From 5c5958115aecd47d5e95539a907aab2cdb00ea76 Mon Sep 17 00:00:00 2001 From: VallierDev <24893073+VallierDev@users.noreply.github.com> Date: Sat, 17 Oct 2026 17:08:46 +0800 Subject: [PATCH] viewer: keep the open device page usable across list refreshes The device list refresh (startup and every 30 s) reset the selected device to none while its page stayed open, so every button on that page silently did nothing. Re-select the same device by id after a refresh. The replace-session confirmation now uses Chinese button labels like the other dialogs instead of locale-dependent OK/Cancel. Co-Authored-By: Claude Opus 5.5 --- c_engine/viewer_window.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/c_engine/viewer_window.c b/c_engine/viewer_window.c index 6f583ca..0e30c26 100644 --- a/c_engine/viewer_window.c +++ b/c_engine/viewer_window.c @@ -658,6 +658,9 @@ int uu_viewer_ui_start(void) { /// Lines of "id\tname\tplatform\tonline\tcurrent". void uu_viewer_ui_set_devices(const char *tsv) { pthread_mutex_lock(&d_lock); + /* A refresh (every 30 s) must keep the open device page usable: re-select by id, not reset. */ + char keep[sizeof devices[0].id] = ""; + if (selected >= 0 && selected < device_count) snprintf(keep, sizeof keep, "%s", devices[selected].id); device_count = 0; char *copy = strdup(tsv ? tsv : ""), *save = NULL; for (char *line = strtok_r(copy, "\n", &save); line && device_count < 64; line = strtok_r(NULL, "\n", &save)) { @@ -670,6 +673,7 @@ void uu_viewer_ui_set_devices(const char *tsv) { } free(copy); selected = -1; + for (int i = 0; keep[0] && i < device_count; i++) if (!strcmp(devices[i].id, keep)) { selected = i; break; } pthread_mutex_unlock(&d_lock); if (init_state == 1) g_idle_add(apply_devices, NULL); } @@ -699,7 +703,8 @@ static int replace_result; static gboolean confirm_replace(gpointer d) { (void)d; GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, "打开后将断开当前与该设备的连接,继续吗?"); + GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "打开后将断开当前与该设备的连接,继续吗?"); + gtk_dialog_add_buttons(GTK_DIALOG(dialog), "取消", GTK_RESPONSE_CANCEL, "继续", GTK_RESPONSE_OK, NULL); int accepted = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK; gtk_widget_destroy(dialog); pthread_mutex_lock(&init_lock); replace_result = accepted; pthread_cond_signal(&init_cond); pthread_mutex_unlock(&init_lock);