GUI round 15 (part 2, #13): Settings menu, localization, Logs page

Add a Settings menu (the old Credentials toolbar button is now "Settings")
containing Credentials, a Language sub-menu, and a Logs page.

Localization (#13): a small i18n layer -- visible strings are wrapped in
t("English") and looked up per language, falling back to English. Built-in
translations for Mandarin, Russian, French, Spanish and Portuguese cover the
toolbar buttons, KPI captions and table column headers; changing the language
re-labels them live (columns via a table rebuild) and localizes dialogs as
they open. The choice persists under the config dir and loads at startup.
(Dialog-internal strings and status text are not yet fully translated -- the
framework is in place to extend them.)

Logs page (#13): an in-app activity log (scans, operations applied, export,
language change) shown in Settings > Logs with Refresh / Clear.

New wx-rs bridge: menu sub-menus (menu_append_submenu). Bridge patches
0002/0003 regenerated. Unit tests + headless selftest pass; the Chinese UI
was verified rendering end to end.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv3oncM4LxTS5tb61Ako6
This commit is contained in:
2026-09-21 14:54:10 -06:00
co-authored by Claude Opus 4.8
parent 0d19e958f0
commit bafbd519bb
8 changed files with 364 additions and 17 deletions
+125 -15
View File
@@ -20,6 +20,13 @@ pub const ID_SCAN_CREDS: i32 = 107;
pub const ID_PRESETS: i32 = 108;
// Export all scan data to CSV (round 15 #14).
pub const ID_EXPORT: i32 = 109;
// Settings menu (round 15 #13): the toolbar button + its menu items.
pub const ID_SETTINGS: i32 = 110;
const ID_LANG_BASE: i32 = 790; // one id per language (790 + index)
const ID_LOGS_OPEN: i32 = 796; // open the Logs page
const ID_LOGS_REFRESH: i32 = 797;
const ID_LOGS_CLEAR: i32 = 798;
const ID_LOGS_CLOSE: i32 = 799;
// Presets dialog.
const ID_PRESET_LOAD: i32 = 770;
const ID_PRESET_SAVE: i32 = 771;
@@ -626,6 +633,9 @@ pub struct App {
// so both can be repainted when the system light/dark theme changes.
pal: Palette,
kpi_cards: Vec<(Widget, Widget, Widget, ColorKind)>,
// Localizable widgets (toolbar buttons + KPI captions) with their English key,
// re-labelled when the language changes (round 15 #13).
l10n_labels: Vec<(Widget, &'static str)>,
/// The main content panel and the KPI card row sizer, plus whether the two
/// wide KPI cards (Hashrate, Est. power) are currently collapsed because the
/// window is too narrow to fit all seven cards (round 11 #2).
@@ -688,6 +698,9 @@ pub struct App {
access_probe: Option<scan::AccessProbeHandle>,
// The API log viewer dialog (round 12 #12).
logview_dialog: Widget,
// Settings > Logs page (round 15 #13).
logs_dialog: Widget,
logs_text: Widget,
// Restore-to-stock (round 12 #8a): background job + its typed-confirm dialog.
restore: Option<restore::RestoreHandle>,
restore_dialog: Widget,
@@ -768,7 +781,7 @@ pub fn build(frame: Widget) -> App {
value.set_fg(vc.0, vc.1, vc.2);
}
value.set_bg(pal.card_bg.0, pal.card_bg.1, pal.card_bg.2);
let lbl = Widget::static_text(card, label);
let lbl = Widget::static_text(card, &crate::i18n::t(label));
lbl.set_font_size(9);
lbl.set_fg(pal.label.0, pal.label.1, pal.label.2);
lbl.set_bg(pal.card_bg.0, pal.card_bg.1, pal.card_bg.2);
@@ -860,7 +873,7 @@ pub fn build(frame: Widget) -> App {
// / Set scan credentials pushed to the right. wrap_sizer so it reflows at
// narrow widths instead of clipping.
let ctl = Widget::wrap_sizer(false);
let ranges_btn = Widget::button(panel, "Scan ranges", ID_RANGES);
let ranges_btn = Widget::button(panel, &crate::i18n::t("Scan ranges"), ID_RANGES);
ctl.add(ranges_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
ctl.add_spacer(8);
// Play / pause / stop as coloured media icons (green / amber / red). Vivid
@@ -872,17 +885,33 @@ pub fn build(frame: Widget) -> App {
let stop_btn = Widget::media_button(panel, ID_STOP, 2, (226, 72, 60));
ctl.add(stop_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 2);
ctl.add_stretch(1);
let presets_btn = Widget::button(panel, "Presets", ID_PRESETS);
ctl.add(presets_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
let filter_btn = Widget::button(panel, "Filter", ID_FILTER);
ctl.add(filter_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
let columns_btn = Widget::button(panel, "Columns", ID_COLUMNS);
ctl.add(columns_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
let export_btn = Widget::button(panel, "Export", ID_EXPORT);
ctl.add(export_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
let creds_btn = Widget::button(panel, "Credentials", ID_SCAN_CREDS);
ctl.add(creds_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
// Toolbar buttons; labels are localized and tracked for live re-labelling
// when the language changes (round 15 #13).
let mut l10n_labels: Vec<(Widget, &'static str)> = Vec::new();
l10n_labels.push((ranges_btn, "Scan ranges"));
let mut tbtn = |label: &'static str, id: i32| -> Widget {
let b = Widget::button(panel, &crate::i18n::t(label), id);
ctl.add(b, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
l10n_labels.push((b, label));
b
};
let presets_btn = tbtn("Presets", ID_PRESETS);
let filter_btn = tbtn("Filter", ID_FILTER);
let columns_btn = tbtn("Columns", ID_COLUMNS);
let export_btn = tbtn("Export", ID_EXPORT);
// The old Credentials button is now a Settings menu (round 15 #13).
let creds_btn = tbtn("Settings", ID_SETTINGS);
root.add_sizer(ctl, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT, 4);
// Track the KPI captions for live re-localization (index 5, the hashrate
// caption, is dynamic per-algorithm so it is refreshed by refresh_kpis).
let kpi_keys = ["Total", "Hashing", "Slow", "Not hashing", "Paused", "", "Est. power"];
for (i, key) in kpi_keys.iter().enumerate() {
if !key.is_empty() {
if let Some(card) = kpi_cards.get(i) {
l10n_labels.push((card.2, key));
}
}
}
// Scan-progress bar across the top of the table (hidden when idle).
let progress = Widget::gauge(panel, 1);
@@ -943,6 +972,7 @@ pub fn build(frame: Widget) -> App {
selected_ips: HashSet::new(),
pal,
kpi_cards,
l10n_labels,
panel,
kpi_row,
kpi_collapsed: false,
@@ -971,6 +1001,8 @@ pub fn build(frame: Widget) -> App {
fwcreds_rows: Vec::new(),
access_probe: None,
logview_dialog: frame,
logs_dialog: frame,
logs_text: frame,
restore: None,
restore_dialog: frame,
pending_restore: Vec::new(),
@@ -1089,7 +1121,7 @@ impl App {
// numeric sort, so we mark the header text instead.
for c in self.table_columns() {
let fixed = self.view.is_fixed(c);
let mut title = c.title().to_string();
let mut title = crate::i18n::t(c.title());
match self.view.sort {
Some((sc, true)) if sc == c => title.push_str(" ^"),
Some((sc, false)) if sc == c => title.push_str(" v"),
@@ -1671,6 +1703,7 @@ impl App {
}
self.pools_dialog.close(1);
self.action_targets = ips.clone();
crate::logs::log(format!("configure pools on {} miner(s)", ips.len()));
self.set_op_status(&ips, "setting pools…");
self.action = Some(scan::start_pools_action(targets));
}
@@ -1690,6 +1723,7 @@ impl App {
}
// Progress shows in each miner's Health cell (round 15 #8), not the scan
// line; the bottom-right indicator still surfaces failures at the end.
crate::logs::log(format!("apply {} to {} miner(s)", action.label(), ips.len()));
self.action_targets = ips.clone();
self.set_op_status(&ips, &action.progress_label());
self.action = Some(scan::start_config_action(ips, action));
@@ -1829,6 +1863,7 @@ impl App {
let (ssh_user, ssh_pass) = credentials::load_ssh_credentials().unwrap_or_default();
let ips: Vec<String> = targets.iter().map(|t| t.ip.clone()).collect();
self.restore_dialog.close(1);
crate::logs::log(format!("restore {} miner(s) to stock", ips.len()));
self.set_op_status(&ips, "restoring…");
self.restore = Some(restore::start_restore(targets, vnish_pass, ssh_user, ssh_pass));
}
@@ -1966,7 +2001,15 @@ impl App {
self.choose_pool_dropdown(id);
return None;
}
// Settings menu Language items (round 15 #13).
if (ID_LANG_BASE..ID_LANG_BASE + 6).contains(&id) {
self.set_language((id - ID_LANG_BASE) as usize);
return None;
}
match id {
// Settings menu items (round 15 #13).
ID_SCAN_CREDS => return Some(self.build_firmware_creds_dialog()),
ID_LOGS_OPEN => return Some(self.build_logs_dialog()),
ID_HDR_SORT_ASC | ID_HDR_SORT_DESC | ID_HDR_SORT_REL_ASC | ID_HDR_SORT_REL_DESC
| ID_HDR_HIDE | ID_HDR_AUTOSIZE | ID_HDR_COLUMNS => return self.on_header_menu(id),
ID_CTX_OPEN => {
@@ -2539,6 +2582,7 @@ impl App {
self.progress.gauge_set_value(self.scan_total.max(1) as i32);
self.progress.show(false);
self.table_parent.layout();
crate::logs::log(format!("scan complete: {} miner(s) found", self.rows.len()));
// Arm the next automatic scan (if the loop is running).
self.countdown = if self.playing { self.auto_secs } else { 0 };
}
@@ -2780,7 +2824,7 @@ impl App {
fn update_headers(&self) {
let Some(t) = self.table else { return };
for (i, c) in self.table_columns().iter().enumerate() {
let mut title = c.title().to_string();
let mut title = crate::i18n::t(c.title());
match self.view.sort {
Some((sc, true)) if sc == *c => title.push_str(" ^"),
Some((sc, false)) if sc == *c => title.push_str(" v"),
@@ -3046,11 +3090,70 @@ impl App {
};
let csv = crate::export::rows_to_csv(&self.rows);
match std::fs::write(&path, csv) {
Ok(()) => wx_rs::set_status_text(&format!("exported {} miner(s) to {path}", self.rows.len())),
Ok(()) => {
crate::logs::log(format!("exported {} miner(s) to {path}", self.rows.len()));
wx_rs::set_status_text(&format!("exported {} miner(s) to {path}", self.rows.len()))
}
Err(e) => self.set_error_indicator(&format!("export failed: {e}")),
}
}
/// Build + queue the Settings popup menu (round 15 #13): Credentials, a
/// Language submenu, and the Logs page.
fn open_settings_menu(&mut self) {
let menu = Widget::menu_new();
menu.menu_append(ID_SCAN_CREDS, &crate::i18n::t("Credentials"));
menu.menu_append_separator();
let lang_menu = Widget::menu_new();
let cur = crate::i18n::current();
for (i, l) in crate::i18n::Lang::all().iter().enumerate() {
// A bullet marks the active language.
let mark = if *l == cur { "\u{2022} " } else { " " };
lang_menu.menu_append(ID_LANG_BASE + i as i32, &format!("{mark}{}", l.label()));
}
menu.menu_append_submenu(&crate::i18n::t("Language"), lang_menu);
menu.menu_append_separator();
menu.menu_append(ID_LOGS_OPEN, &crate::i18n::t("Logs"));
self.pending_popup = Some((Widget::main_frame(), menu));
}
/// Apply a language change (round 15 #13): re-label the tracked toolbar/KPI
/// widgets and re-title the columns; dialogs pick up the language when opened.
fn set_language(&mut self, idx: usize) {
let Some(l) = crate::i18n::Lang::all().get(idx).copied() else { return };
crate::i18n::set(l);
crate::logs::log(format!("language set to {}", l.label()));
for (w, key) in &self.l10n_labels {
w.set_label(&crate::i18n::t(key));
}
self.rebuild_table();
self.refresh_kpis();
}
/// Build (but do not show) the Logs page (round 15 #13): the in-app activity
/// log with Refresh / Clear / Close.
fn build_logs_dialog(&mut self) -> Widget {
let frame = Widget::main_frame();
let dlg = Widget::dialog(frame, &crate::i18n::t("Logs"));
let root = Widget::box_sizer(true);
let text = Widget::text_ctrl(dlg, true);
text.set_value(&crate::logs::dump());
text.set_min_size(620, 360);
root.add(text, 1, sf::EXPAND | sf::BORDER_ALL, 6);
let btns = Widget::box_sizer(false);
btns.add(Widget::button(dlg, "Refresh", ID_LOGS_REFRESH), 0, sf::BORDER_ALL, 6);
btns.add(Widget::button(dlg, "Clear", ID_LOGS_CLEAR), 0, sf::BORDER_ALL, 6);
btns.add_stretch(1);
btns.add(Widget::button(dlg, "Close", ID_LOGS_CLOSE), 0, sf::BORDER_ALL, 6);
root.add_sizer(btns, 0, sf::EXPAND | sf::BORDER_ALL, 6);
root.set_sizer_on(dlg);
dlg.set_min_size(660, 420);
dlg.fit(dlg);
self.logs_dialog = dlg;
self.logs_text = text;
dlg
}
fn build_columns_dialog(&mut self) -> Widget {
let frame = Widget::main_frame();
let dlg = Widget::dialog(frame, "Choose columns");
@@ -3498,6 +3601,13 @@ impl App {
ID_RANGES_APPLY => self.apply_ranges(),
ID_RANGES_CANCEL => self.ranges_dialog.close(0),
ID_EXPORT => self.apply_export(),
ID_SETTINGS => self.open_settings_menu(),
ID_LOGS_REFRESH => self.logs_text.set_value(&crate::logs::dump()),
ID_LOGS_CLEAR => {
crate::logs::clear();
self.logs_text.set_value("");
}
ID_LOGS_CLOSE => self.logs_dialog.close(1),
ID_COLUMNS => return Some(self.build_columns_dialog()),
ID_COLUMNS_OK => self.apply_columns(),
ID_COLUMNS_CANCEL => self.columns_dialog.close(0),