feat: add restart button

This commit is contained in:
Ixniy Evonniy 2026-07-01 11:57:42 +03:00
parent 1cc4c4c3d5
commit 588dd4f847
2 changed files with 27 additions and 0 deletions

View File

@ -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);

View File

@ -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