diff --git a/cache.db b/cache.db index 7167119..8e64342 100644 Binary files a/cache.db and b/cache.db differ diff --git a/main.jai b/main.jai index ab0efa3..ab57408 100644 --- a/main.jai +++ b/main.jai @@ -25,6 +25,9 @@ App_State :: struct { updater_data: Updater_Thread_Data; use_system_proxy: bool = true; port: int = 10801; + + icon_running: HICON; + icon_stopped: HICON; } // Custom log print sending logs to OutputDebugStringW @@ -131,10 +134,10 @@ update_tray :: (app: *App_State) { nid.uFlags = NIF_ICON | NIF_TIP; if app.singbox_running { - nid.hIcon = LoadIconW(null, IDI_SHIELD); + nid.hIcon = app.icon_running; set_tray_tip(*nid, "Sing-box: Running"); } else { - nid.hIcon = LoadIconW(null, IDI_APPLICATION); + nid.hIcon = app.icon_stopped; set_tray_tip(*nid, "Sing-box: Stopped"); } @@ -473,6 +476,17 @@ app_wnd_proc :: (hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESUL } } +load_stock_icon :: (siid: s32) -> HICON { + sii: SHSTOCKICONINFO; + sii.cbSize = size_of(SHSTOCKICONINFO); + hr := SHGetStockIconInfo(siid, SHGSI_ICON | SHGSI_SMALLICON, *sii); + if hr == 0 { // S_OK + return sii.hIcon; + } + // Fallback to default application icon + return LoadIconW(null, IDI_APPLICATION); +} + main :: () { hInstance := GetModuleHandleW(null); class_name := utf8_to_wide("SingboxTrayControllerClass"); @@ -488,6 +502,8 @@ main :: () { defer UnregisterClassW(class_name, hInstance); app_state: App_State; + app_state.icon_running = load_stock_icon(SIID_WORLD); + app_state.icon_stopped = load_stock_icon(SIID_ERROR); hwnd := CreateWindowExW( 0, @@ -534,7 +550,7 @@ main :: () { nid.uID = 1; nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; nid.uCallbackMessage = WM_TRAY_CALLBACK; - nid.hIcon = LoadIconW(null, IDI_APPLICATION); + nid.hIcon = app_state.icon_stopped; set_tray_tip(*nid, "Sing-box: Stopped"); if !Shell_NotifyIconW(NIM_ADD, *nid) { @@ -574,4 +590,7 @@ main :: () { } stop_singbox(*app_state); + + if app_state.icon_running DestroyIcon(app_state.icon_running); + if app_state.icon_stopped DestroyIcon(app_state.icon_stopped); } diff --git a/win32.jai b/win32.jai index 4c62375..9d88e67 100644 --- a/win32.jai +++ b/win32.jai @@ -199,6 +199,28 @@ HttpQueryInfoW :: ( lpdwIndex: *DWORD ) -> BOOL #foreign wininet; +SHSTOCKICONINFO :: struct { + cbSize: DWORD; + hIcon: HICON; + iSysImageIndex: s32; + iIcon: s32; + szPath: [260] u16; +} + +SIID_WORLD :: 13; +SIID_ERROR :: 80; + +SHGSI_ICON :: 0x00000100; +SHGSI_SMALLICON :: 0x00000001; + +SHGetStockIconInfo :: ( + siid: s32, + uFlags: u32, + psii: *SHSTOCKICONINFO +) -> s32 #foreign shell32; + +DestroyIcon :: (hIcon: HICON) -> BOOL #foreign user32; + wcslen :: (str: *u16) -> int { len := 0; while str[len] != 0 {