diff --git a/installer/PowerToysSetupVNext/Core.wxs b/installer/PowerToysSetupVNext/Core.wxs index a9cf083512..aaf9bb5550 100644 --- a/installer/PowerToysSetupVNext/Core.wxs +++ b/installer/PowerToysSetupVNext/Core.wxs @@ -61,6 +61,16 @@ + + + + + + + + + + @@ -112,6 +122,7 @@ + @@ -120,6 +131,7 @@ + diff --git a/src/runner/general_settings.cpp b/src/runner/general_settings.cpp index 5024e39753..4deb36ec17 100644 --- a/src/runner/general_settings.cpp +++ b/src/runner/general_settings.cpp @@ -367,11 +367,21 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save) if (json::has(general_configs, L"show_theme_adaptive_tray_icon", json::JsonValueType::Boolean)) { bool new_theme_adaptive = general_configs.GetNamedBoolean(L"show_theme_adaptive_tray_icon"); + Logger::info(L"apply_general_settings: show_theme_adaptive_tray_icon current={}, new={}", + show_theme_adaptive_tray_icon, new_theme_adaptive); if (show_theme_adaptive_tray_icon != new_theme_adaptive) { show_theme_adaptive_tray_icon = new_theme_adaptive; set_tray_icon_theme_adaptive(show_theme_adaptive_tray_icon); } + else + { + Logger::info(L"apply_general_settings: show_theme_adaptive_tray_icon unchanged, skipping update"); + } + } + else + { + Logger::warn(L"apply_general_settings: show_theme_adaptive_tray_icon not found in config"); } if (json::has(general_configs, L"ignored_conflict_properties", json::JsonValueType::Object)) diff --git a/src/runner/tray_icon.cpp b/src/runner/tray_icon.cpp index 9cff0c36ff..633c2c1b42 100644 --- a/src/runner/tray_icon.cpp +++ b/src/runner/tray_icon.cpp @@ -273,12 +273,19 @@ static HICON get_icon(Theme theme) { std::wstring icon_path = get_module_folderpath(); icon_path += theme == Theme::Dark ? L"\\svgs\\PowerToysWhite.ico" : L"\\svgs\\PowerToysDark.ico"; - return static_cast(LoadImage(NULL, + Logger::trace(L"get_icon: Loading icon from path: {}", icon_path); + + HICON icon = static_cast(LoadImage(NULL, icon_path.c_str(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE | LR_SHARED)); + if (!icon) + { + Logger::warn(L"get_icon: Failed to load icon from {}, error: {}", icon_path, GetLastError()); + } + return icon; } @@ -374,13 +381,45 @@ void set_tray_icon_visible(bool shouldIconBeVisible) void set_tray_icon_theme_adaptive(bool theme_adaptive) { - theme_adaptive_enabled = theme_adaptive; + Logger::info(L"set_tray_icon_theme_adaptive: Called with theme_adaptive={}, current theme_adaptive_enabled={}", + theme_adaptive, theme_adaptive_enabled); + auto h_instance = reinterpret_cast(&__ImageBase); - HICON const icon = theme_adaptive ? get_icon(theme_listener.AppTheme) : LoadIcon(h_instance, MAKEINTRESOURCE(APPICON)); + HICON icon = nullptr; + + if (theme_adaptive) + { + icon = get_icon(theme_listener.AppTheme); + if (!icon) + { + Logger::warn(L"set_tray_icon_theme_adaptive: Failed to load theme adaptive icon, falling back to default"); + } + } + + // If not requesting adaptive icon, or if adaptive icon failed to load, use default icon + if (!icon) + { + icon = LoadIcon(h_instance, MAKEINTRESOURCE(APPICON)); + if (theme_adaptive && icon) + { + // We requested adaptive but had to fall back, so update the flag + theme_adaptive = false; + Logger::info(L"set_tray_icon_theme_adaptive: Using default icon as fallback"); + } + } + + theme_adaptive_enabled = theme_adaptive; + if (icon) { tray_icon_data.hIcon = icon; - Shell_NotifyIcon(NIM_MODIFY, &tray_icon_data); + BOOL result = Shell_NotifyIcon(NIM_MODIFY, &tray_icon_data); + Logger::info(L"set_tray_icon_theme_adaptive: Icon updated, theme_adaptive_enabled={}, Shell_NotifyIcon result={}", + theme_adaptive_enabled, result); + } + else + { + Logger::error(L"set_tray_icon_theme_adaptive: Failed to load any icon"); } }