fix: move Auto-update into Configure menu
This commit is contained in:
parent
d745efbf87
commit
1d349d6692
58
main.jai
58
main.jai
@ -374,15 +374,41 @@ start_singbox :: (app: *App_State) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !has_config || !has_outbounds {
|
if !has_config || !has_outbounds {
|
||||||
|
if !url_present {
|
||||||
|
// Prompt configuration dialog
|
||||||
|
changed := show_config_url_dialog(app.hwnd, app.is_test_mode);
|
||||||
|
if changed {
|
||||||
|
// reload config to verify and fetch URL
|
||||||
|
config_data, read_ok := read_entire_file(config_filename);
|
||||||
|
if read_ok {
|
||||||
|
url := get_json_string_field(config_data, "\"_url\"");
|
||||||
|
if url {
|
||||||
|
url_present = true;
|
||||||
|
}
|
||||||
|
free(config_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if url_present {
|
if url_present {
|
||||||
|
// Trigger animation for downloading config
|
||||||
|
app.is_updating = true;
|
||||||
|
app.animation_frame = 0;
|
||||||
|
SetTimer(app.hwnd, TIMER_ANIMATION, 150, null);
|
||||||
|
update_tray(app);
|
||||||
|
|
||||||
changed, success, err_msg := perform_update(app.is_test_mode);
|
changed, success, err_msg := perform_update(app.is_test_mode);
|
||||||
|
|
||||||
|
app.is_updating = false;
|
||||||
|
KillTimer(app.hwnd, TIMER_ANIMATION);
|
||||||
|
update_tray(app);
|
||||||
|
|
||||||
if !success {
|
if !success {
|
||||||
msg := tprint("Could not download configuration.\nError: %", err_msg);
|
msg := tprint("Could not download configuration.\nError: %", err_msg);
|
||||||
MessageBoxW(app.hwnd, utf8_to_wide(msg), utf8_to_wide("Sing-box Tray"), MB_ICONERROR);
|
MessageBoxW(app.hwnd, utf8_to_wide(msg), utf8_to_wide("Sing-box Tray"), MB_ICONERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MessageBoxW(app.hwnd, utf8_to_wide("No configuration found. Please configure the Config URL first."), utf8_to_wide("Sing-box Tray"), MB_ICONWARNING);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -596,11 +622,17 @@ show_context_menu :: (app: *App_State) {
|
|||||||
|
|
||||||
toggle_str := ifx app.singbox_running then "Stop Sing-box" else "Start Sing-box";
|
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_START_STOP, utf8_to_wide(toggle_str));
|
||||||
|
|
||||||
AppendMenuW(hMenu, MF_STRING, CMD_SET_URL, utf8_to_wide("Configure URL..."));
|
|
||||||
AppendMenuW(hMenu, MF_STRING, CMD_SET_PORT, utf8_to_wide("Configure Port..."));
|
|
||||||
AppendMenuW(hMenu, MF_STRING, CMD_UPDATE_NOW, utf8_to_wide("Update Config Now"));
|
AppendMenuW(hMenu, MF_STRING, CMD_UPDATE_NOW, utf8_to_wide("Update Config Now"));
|
||||||
|
|
||||||
|
hConfigureMenu := CreatePopupMenu();
|
||||||
|
AppendMenuW(hConfigureMenu, MF_STRING, CMD_SET_URL, utf8_to_wide("Configure URL..."));
|
||||||
|
AppendMenuW(hConfigureMenu, MF_STRING, CMD_SET_PORT, utf8_to_wide("Configure Port..."));
|
||||||
|
autostart_flags := MF_STRING;
|
||||||
|
if is_autostart_enabled() {
|
||||||
|
autostart_flags |= MF_CHECKED;
|
||||||
|
}
|
||||||
|
AppendMenuW(hConfigureMenu, autostart_flags, CMD_TOGGLE_AUTOSTART, utf8_to_wide("Start on Windows boot"));
|
||||||
|
|
||||||
hUpdateMenu := CreatePopupMenu();
|
hUpdateMenu := CreatePopupMenu();
|
||||||
current_interval := app.updater_data.update_interval_seconds;
|
current_interval := app.updater_data.update_interval_seconds;
|
||||||
AppendMenuW(hUpdateMenu, MF_STRING | (ifx current_interval == 0 then MF_CHECKED else 0), CMD_UPDATE_NEVER, utf8_to_wide("Never"));
|
AppendMenuW(hUpdateMenu, MF_STRING | (ifx current_interval == 0 then MF_CHECKED else 0), CMD_UPDATE_NEVER, utf8_to_wide("Never"));
|
||||||
@ -611,7 +643,9 @@ show_context_menu :: (app: *App_State) {
|
|||||||
AppendMenuW(hUpdateMenu, MF_STRING | (ifx current_interval == 86400 then MF_CHECKED else 0), CMD_UPDATE_DAILY, utf8_to_wide("Daily"));
|
AppendMenuW(hUpdateMenu, MF_STRING | (ifx current_interval == 86400 then MF_CHECKED else 0), CMD_UPDATE_DAILY, utf8_to_wide("Daily"));
|
||||||
AppendMenuW(hUpdateMenu, MF_STRING | (ifx current_interval == 259200 then MF_CHECKED else 0), CMD_UPDATE_3D, utf8_to_wide("3 days"));
|
AppendMenuW(hUpdateMenu, MF_STRING | (ifx current_interval == 259200 then MF_CHECKED else 0), CMD_UPDATE_3D, utf8_to_wide("3 days"));
|
||||||
AppendMenuW(hUpdateMenu, MF_STRING | (ifx current_interval == 604800 then MF_CHECKED else 0), CMD_UPDATE_WEEKLY, utf8_to_wide("weekly"));
|
AppendMenuW(hUpdateMenu, MF_STRING | (ifx current_interval == 604800 then MF_CHECKED else 0), CMD_UPDATE_WEEKLY, utf8_to_wide("weekly"));
|
||||||
AppendMenuW(hMenu, MF_POPUP, cast(s64) hUpdateMenu, utf8_to_wide("Config Auto-Update"));
|
AppendMenuW(hConfigureMenu, MF_POPUP, cast(s64) hUpdateMenu, utf8_to_wide("Auto-update"));
|
||||||
|
|
||||||
|
AppendMenuW(hMenu, MF_POPUP, cast(s64) hConfigureMenu, utf8_to_wide("Configure"));
|
||||||
|
|
||||||
AppendMenuW(hMenu, MF_SEPARATOR, 0, null);
|
AppendMenuW(hMenu, MF_SEPARATOR, 0, null);
|
||||||
|
|
||||||
@ -627,14 +661,6 @@ show_context_menu :: (app: *App_State) {
|
|||||||
|
|
||||||
AppendMenuW(hMenu, MF_SEPARATOR, 0, null);
|
AppendMenuW(hMenu, MF_SEPARATOR, 0, null);
|
||||||
|
|
||||||
autostart_flags := MF_STRING;
|
|
||||||
if is_autostart_enabled() {
|
|
||||||
autostart_flags |= MF_CHECKED;
|
|
||||||
}
|
|
||||||
AppendMenuW(hMenu, autostart_flags, CMD_TOGGLE_AUTOSTART, utf8_to_wide("Start on Windows boot"));
|
|
||||||
|
|
||||||
AppendMenuW(hMenu, MF_SEPARATOR, 0, null);
|
|
||||||
|
|
||||||
AppendMenuW(hMenu, MF_STRING, CMD_EXIT, utf8_to_wide("Exit"));
|
AppendMenuW(hMenu, MF_STRING, CMD_EXIT, utf8_to_wide("Exit"));
|
||||||
|
|
||||||
cursor_pos: POINT;
|
cursor_pos: POINT;
|
||||||
@ -1094,9 +1120,9 @@ main :: () {
|
|||||||
}
|
}
|
||||||
defer Shell_NotifyIconW(NIM_DELETE, *nid);
|
defer Shell_NotifyIconW(NIM_DELETE, *nid);
|
||||||
|
|
||||||
if file_exists(config_filename) {
|
// Try to run / start sing-box. On first start (or if config/outbounds are missing),
|
||||||
start_singbox(*app_state);
|
// this will prompt the configuration dialog instead of silently failing or erroring.
|
||||||
}
|
start_singbox(*app_state);
|
||||||
|
|
||||||
SetTimer(hwnd, TIMER_PROCESS_CHECK, 1000, null);
|
SetTimer(hwnd, TIMER_PROCESS_CHECK, 1000, null);
|
||||||
defer KillTimer(hwnd, TIMER_PROCESS_CHECK);
|
defer KillTimer(hwnd, TIMER_PROCESS_CHECK);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user