refactor: extract IconLoader utility to eliminate icon loading duplication#172
Draft
Copilot wants to merge 2 commits into
Draft
refactor: extract IconLoader utility to eliminate icon loading duplication#172Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
…ation Co-authored-by: sunzhuoshi <592211+sunzhuoshi@users.noreply.github.com> Agent-Logs-Url: https://github.com/sunzhuoshi/agent-supervisor/sessions/b8501276-ad05-40a6-815d-f5bdf72cd5b1
Copilot
AI
changed the title
[WIP] Refactor duplicated icon loading logic with fallback
refactor: extract IconLoader utility to eliminate icon loading duplication
Mar 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Icon loading logic (path construction,
File.Existscheck, error handling, fallback) was duplicated across three files, withTaskbarBadgeManageradditionally using a hardcoded"res"string instead ofConstants.IconResourcePath.Changes
New
src/IconLoader.cs— static utility centralizing all icon loading:TryLoadDefault(fileName)→Icon?— loads at default size (preserves multi-resolution ICO behavior)TryLoad(fileName, size)→Icon?— loads at specific pixel size, returnsnullon miss/failureLoadWithFallback(fileName, size, fallbackFactory)— thin wrapper overTryLoadwith non-null guaranteeCreateIconFromBitmap(bitmap)—GetHicon()+Clone()+DestroyIcon()to avoid GDI handle leakMainWindow.cs— replaced manual try/catch withIconLoader.TryLoadDefaultSystemTrayManager.cs—CreateCustomIconusesLoadWithFallback; fallback bitmap-to-icon conversion goes throughCreateIconFromBitmapto properly release the HICON handleTaskbarBadgeManager.cs—DrawBaseIconusesTryLoad; eliminates hardcoded"res"path; fallback draws gradient directly to avoidGetHicon()roundtripOriginal prompt
This section details on the original issue you should resolve
<issue_title>Duplicate Code: Icon Loading with Fallback Pattern in MainWindow, SystemTrayManager, TaskbarBadgeManager</issue_title>
<issue_description>Analysis of commit 0888461
Assignee:
@copilotSummary
The icon loading logic (path construction →
File.Existscheck → load icon → fallback on failure) is duplicated across three files with near-identical structure, each independently handling theapp_icon.icofile loading and error/fallback scenarios.Duplication Details
Pattern: Icon File Loading with Fallback
Severity: High
Occurrences: 3 instances across 3 files
Locations:
src/MainWindow.cs(lines 33–44)src/SystemTrayManager.cs(lines 212–255)src/TaskbarBadgeManager.cs(lines 168–188)Code Sample (representative from each file):
Impact Analysis
"res") inTaskbarBadgeManager.csinstead of usingConstants.IconResourcePath, creating inconsistency risk.Refactoring Recommendations
Extract
IconLoaderutility classsrc/IconLoader.cspublic static Icon LoadWithFallback(string fileName, int size, Func(Icon) fallbackFactory)Path.Combine(BaseDirectory, Constants.IconResourcePath, fileName)), existence check, and error loggingTaskbarBadgeManagerFix hardcoded path in
TaskbarBadgeManager.cs"res"withConstants.IconResourcePathimmediately (independent of refactor)Implementation Checklist
"res"path inTaskbarBadgeManager.csto useConstants.IconResourcePathsrc/IconLoader.csutility class withLoadWithFallbackmethodMainWindow.csto useIconLoaderSystemTrayManager.csto useIconLoaderTaskbarBadgeManager.csto useIconLoaderAnalysis Metadata
Comments on the Issue (you are @copilot in this section)
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.