Skip to content

Commit 1a5699c

Browse files
committed
fix(tray-animations): fixed the issue where the logo would be reset after hibernation is started
1 parent 52ee984 commit 1a5699c

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

include/tray/tray_animation_core.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ void TrayAnimation_SetMinIntervalMs(UINT ms);
100100
*/
101101
void TrayAnimation_RecomputeTimerDelay(void);
102102

103+
/**
104+
* @brief Clear current animation name to force reload on next apply
105+
*/
106+
void TrayAnimation_ClearCurrentName(void);
107+
103108
/**
104109
* @brief Update percent icon if in CPU/Memory mode
105110
*

src/tray/tray_animation_core.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,19 @@ void TrayAnimation_RecomputeTimerDelay(void) {
884884
/* No-op: delay computed dynamically now */
885885
}
886886

887+
/**
888+
* @brief Clear current animation name to force reload
889+
*/
890+
void TrayAnimation_ClearCurrentName(void) {
891+
if (g_criticalSectionInitialized) {
892+
EnterCriticalSection(&g_animCriticalSection);
893+
}
894+
g_animationName[0] = '\0';
895+
if (g_criticalSectionInitialized) {
896+
LeaveCriticalSection(&g_animCriticalSection);
897+
}
898+
}
899+
887900
/**
888901
* @brief Update percent icon if needed
889902
*/

src/window_procedure/window_procedure.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,42 @@ extern BOOL PREVIOUS_TOPMOST_STATE;
3838

3939
#define OPACITY_FULL 255
4040

41+
/* ============================================================================
42+
* Power Management Handler
43+
* ============================================================================ */
44+
45+
static LRESULT HandlePowerBroadcast(HWND hwnd, WPARAM wp, LPARAM lp) {
46+
(void)lp;
47+
static volatile LONG s_handling = 0;
48+
49+
/* Handle system resume from sleep/hibernate */
50+
if (wp == PBT_APMRESUMEAUTOMATIC || wp == PBT_APMRESUMESUSPEND) {
51+
/* Prevent re-entry if called multiple times in quick succession */
52+
if (InterlockedCompareExchange(&s_handling, 1, 0) != 0) {
53+
return TRUE;
54+
}
55+
56+
LOG_INFO("System resumed from sleep/hibernate, reinitializing tray icon animation");
57+
58+
/* Step 1: Clear animation name to force reload
59+
* This bypasses the "same name" check in ApplyAnimationPathValueNoPersist */
60+
extern void TrayAnimation_ClearCurrentName(void);
61+
TrayAnimation_ClearCurrentName();
62+
63+
/* Step 2: Reload animation from config */
64+
extern LRESULT HandleAppAnimPathChanged(HWND);
65+
HandleAppAnimPathChanged(hwnd);
66+
67+
/* Step 3: Recreate tray icon with newly loaded animation */
68+
extern void RecreateTaskbarIcon(HWND, HINSTANCE);
69+
RecreateTaskbarIcon(hwnd, GetModuleHandle(NULL));
70+
71+
InterlockedExchange(&s_handling, 0);
72+
}
73+
74+
return TRUE;
75+
}
76+
4177
/* ============================================================================
4278
* Application Message Dispatch Table
4379
* ============================================================================ */
@@ -117,6 +153,7 @@ static const MessageDispatchEntry MESSAGE_DISPATCH_TABLE[] = {
117153
{WM_KEYDOWN, HandleKeyDown, "Key down"},
118154
{WM_HOTKEY, HandleHotkey, "Global hotkey"},
119155
{WM_COPYDATA, HandleCopyData, "Inter-process communication"},
156+
{WM_POWERBROADCAST, HandlePowerBroadcast, "Power management events"},
120157
{WM_APP_QUICK_COUNTDOWN_INDEX, HandleQuickCountdownIndex, "Quick countdown by index"},
121158
{WM_APP_SHOW_CLI_HELP, HandleShowCliHelp, "Show CLI help"},
122159
{WM_USER + 100, HandleTrayUpdateIcon, "Tray icon update"},

0 commit comments

Comments
 (0)