From 588dd4f84745874d3b738498a05413f5d2a0ac66 Mon Sep 17 00:00:00 2001 From: Ixniy Evonniy Date: Wed, 1 Jul 2026 11:57:42 +0300 Subject: [PATCH] feat: add restart button --- main.jai | 26 ++++++++++++++++++++++++++ win32.jai | 1 + 2 files changed, 27 insertions(+) diff --git a/main.jai b/main.jai index 67b813e..4641307 100644 --- a/main.jai +++ b/main.jai @@ -1148,6 +1148,7 @@ show_context_menu :: (app: *App_State) { AppendMenuW(hMenu, MF_SEPARATOR, 0, null); + AppendMenuW(hMenu, MF_STRING, CMD_RESTART, utf8_to_wide("Restart")); toggle_str := ifx app.singbox_running then "Stop Sing-box" else "Start Sing-box"; AppendMenuW(hMenu, MF_STRING, CMD_START_STOP, utf8_to_wide(toggle_str)); AppendMenuW(hMenu, MF_STRING, CMD_UPDATE_NOW, utf8_to_wide("Update Config Now")); @@ -1229,6 +1230,31 @@ show_context_menu :: (app: *App_State) { cmd := TrackPopupMenu(hMenu, track_flags, cursor_pos.x, cursor_pos.y, 0, app.hwnd, null); if cmd == { + case CMD_RESTART; { + log_print("Restart requested, forcing config refresh to select new server.\n"); + if app.singbox_running { + stop_singbox(app); + } + + // Force re-download of config (remote may assign different server) then (re)start sing-box. + app.is_updating = true; + app.animation_frame = 0; + SetTimer(app.hwnd, TIMER_ANIMATION, 150, null); + update_tray(app); + + _, success, err_msg := perform_update(app.is_test_mode); + + app.is_updating = false; + KillTimer(app.hwnd, TIMER_ANIMATION); + update_tray(app); + + if success { + start_singbox(app); + } else { + msg := tprint("Failed to refresh configuration for restart.\nError: %", err_msg); + MessageBoxW(app.hwnd, utf8_to_wide(msg), utf8_to_wide("Sing-box Tray"), MB_ICONERROR); + } + } case CMD_START_STOP; { if app.singbox_running { stop_singbox(app); diff --git a/win32.jai b/win32.jai index b1bef6e..b4db5c7 100644 --- a/win32.jai +++ b/win32.jai @@ -166,6 +166,7 @@ CMD_UPDATE_3D :: 1016; CMD_UPDATE_WEEKLY :: 1017; CMD_CONFIG_DIR :: 1018; CMD_UPDATE_CORE :: 1019; +CMD_RESTART :: 1020; // Boolean constants