feat: add restart button
This commit is contained in:
parent
1cc4c4c3d5
commit
588dd4f847
26
main.jai
26
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user