Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bafbd519bb |
@@ -0,0 +1,162 @@
|
||||
//! Lightweight UI localization (round 15 #13).
|
||||
//!
|
||||
//! Visible strings are wrapped in `t("English text")`; the English text is the
|
||||
//! lookup key. `t` returns the translation for the current language, falling back
|
||||
//! to the English key when a string has no translation yet. The language is a
|
||||
//! process-global, persisted under the config dir; changing it re-titles the
|
||||
//! table columns and toolbar/KPI labels live and localizes dialogs as they open.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::{AtomicU8, Ordering};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Lang {
|
||||
En,
|
||||
Zh,
|
||||
Ru,
|
||||
Fr,
|
||||
Es,
|
||||
Pt,
|
||||
}
|
||||
|
||||
impl Lang {
|
||||
pub fn all() -> [Lang; 6] {
|
||||
[Lang::En, Lang::Zh, Lang::Ru, Lang::Fr, Lang::Es, Lang::Pt]
|
||||
}
|
||||
/// The language's own name, for the selector menu.
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
Lang::En => "English",
|
||||
Lang::Zh => "\u{4e2d}\u{6587}", // 中文
|
||||
Lang::Ru => "\u{0420}\u{0443}\u{0441}\u{0441}\u{043a}\u{0438}\u{0439}", // Русский
|
||||
Lang::Fr => "Fran\u{e7}ais",
|
||||
Lang::Es => "Espa\u{f1}ol",
|
||||
Lang::Pt => "Portugu\u{ea}s",
|
||||
}
|
||||
}
|
||||
fn code(self) -> &'static str {
|
||||
match self {
|
||||
Lang::En => "en",
|
||||
Lang::Zh => "zh",
|
||||
Lang::Ru => "ru",
|
||||
Lang::Fr => "fr",
|
||||
Lang::Es => "es",
|
||||
Lang::Pt => "pt",
|
||||
}
|
||||
}
|
||||
fn from_code(s: &str) -> Lang {
|
||||
match s.trim() {
|
||||
"zh" => Lang::Zh,
|
||||
"ru" => Lang::Ru,
|
||||
"fr" => Lang::Fr,
|
||||
"es" => Lang::Es,
|
||||
"pt" => Lang::Pt,
|
||||
_ => Lang::En,
|
||||
}
|
||||
}
|
||||
fn index(self) -> usize {
|
||||
match self {
|
||||
Lang::En => 0,
|
||||
Lang::Zh => 1,
|
||||
Lang::Ru => 2,
|
||||
Lang::Fr => 3,
|
||||
Lang::Es => 4,
|
||||
Lang::Pt => 5,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static CURRENT: AtomicU8 = AtomicU8::new(0);
|
||||
|
||||
const LANG_FILE: &str = "language.txt";
|
||||
|
||||
fn config_path() -> PathBuf {
|
||||
let home = std::env::var("HOME").unwrap_or_else(|_| ".".into());
|
||||
PathBuf::from(home).join(".config/alkane-toolkit").join(LANG_FILE)
|
||||
}
|
||||
|
||||
/// Load the saved language into the global (call once at startup).
|
||||
pub fn init() {
|
||||
let l = std::fs::read_to_string(config_path())
|
||||
.ok()
|
||||
.map(|s| Lang::from_code(&s))
|
||||
.unwrap_or(Lang::En);
|
||||
CURRENT.store(lang_to_u8(l), Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub fn current() -> Lang {
|
||||
u8_to_lang(CURRENT.load(Ordering::Relaxed))
|
||||
}
|
||||
|
||||
/// Set + persist the language.
|
||||
pub fn set(l: Lang) {
|
||||
CURRENT.store(lang_to_u8(l), Ordering::Relaxed);
|
||||
let p = config_path();
|
||||
if let Some(dir) = p.parent() {
|
||||
let _ = std::fs::create_dir_all(dir);
|
||||
}
|
||||
let _ = std::fs::write(p, l.code());
|
||||
}
|
||||
|
||||
fn lang_to_u8(l: Lang) -> u8 {
|
||||
l.index() as u8
|
||||
}
|
||||
fn u8_to_lang(v: u8) -> Lang {
|
||||
Lang::all().get(v as usize).copied().unwrap_or(Lang::En)
|
||||
}
|
||||
|
||||
/// Translate `key` (an English string) to the current language, or return `key`
|
||||
/// when there is no translation.
|
||||
pub fn t(key: &str) -> String {
|
||||
let lang = current();
|
||||
if lang == Lang::En {
|
||||
return key.to_string();
|
||||
}
|
||||
for (en, tr) in TABLE {
|
||||
if *en == key {
|
||||
let s = tr[lang.index()];
|
||||
if !s.is_empty() {
|
||||
return s.to_string();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
key.to_string()
|
||||
}
|
||||
|
||||
// Translation table: (English, [en, zh, ru, fr, es, pt]). The en slot mirrors the
|
||||
// key (unused by `t`, kept for readability). An empty slot falls back to English.
|
||||
#[rustfmt::skip]
|
||||
const TABLE: &[(&str, [&str; 6])] = &[
|
||||
// Toolbar + settings
|
||||
("Scan ranges", ["Scan ranges", "\u{626b}\u{63cf}\u{8303}\u{56f4}", "\u{0414}\u{0438}\u{0430}\u{043f}\u{0430}\u{0437}\u{043e}\u{043d}\u{044b}", "Plages", "Rangos", "Faixas"]),
|
||||
("Presets", ["Presets", "\u{9884}\u{8bbe}", "\u{041f}\u{0440}\u{0435}\u{0441}\u{0435}\u{0442}\u{044b}", "Pr\u{e9}r\u{e9}glages", "Ajustes", "Predefini\u{e7}\u{f5}es"]),
|
||||
("Filter", ["Filter", "\u{7b5b}\u{9009}", "\u{0424}\u{0438}\u{043b}\u{044c}\u{0442}\u{0440}", "Filtre", "Filtro", "Filtro"]),
|
||||
("Columns", ["Columns", "\u{5217}", "\u{0421}\u{0442}\u{043e}\u{043b}\u{0431}\u{0446}\u{044b}", "Colonnes", "Columnas", "Colunas"]),
|
||||
("Export", ["Export", "\u{5bfc}\u{51fa}", "\u{042d}\u{043a}\u{0441}\u{043f}\u{043e}\u{0440}\u{0442}", "Exporter", "Exportar", "Exportar"]),
|
||||
("Settings", ["Settings", "\u{8bbe}\u{7f6e}", "\u{041d}\u{0430}\u{0441}\u{0442}\u{0440}\u{043e}\u{0439}\u{043a}\u{0438}", "Param\u{e8}tres", "Ajustes", "Configura\u{e7}\u{f5}es"]),
|
||||
("Credentials", ["Credentials", "\u{51ed}\u{636e}", "\u{0423}\u{0447}\u{0451}\u{0442}\u{043d}\u{044b}\u{0435} \u{0434}\u{0430}\u{043d}\u{043d}\u{044b}\u{0435}", "Identifiants", "Credenciales", "Credenciais"]),
|
||||
("Language", ["Language", "\u{8bed}\u{8a00}", "\u{042f}\u{0437}\u{044b}\u{043a}", "Langue", "Idioma", "Idioma"]),
|
||||
("Logs", ["Logs", "\u{65e5}\u{5fd7}", "\u{0416}\u{0443}\u{0440}\u{043d}\u{0430}\u{043b}", "Journaux", "Registros", "Registos"]),
|
||||
// KPI captions
|
||||
("Total", ["Total", "\u{603b}\u{6570}", "\u{0412}\u{0441}\u{0435}\u{0433}\u{043e}", "Total", "Total", "Total"]),
|
||||
("Hashing", ["Hashing", "\u{6b63}\u{5728}\u{6316}\u{77ff}", "\u{0425}\u{0435}\u{0448}\u{0438}\u{0440}\u{043e}\u{0432}\u{0430}\u{043d}\u{0438}\u{0435}", "Minage", "Minando", "Minerando"]),
|
||||
("Slow", ["Slow", "\u{7f13}\u{6162}", "\u{041c}\u{0435}\u{0434}\u{043b}\u{0435}\u{043d}\u{043d}\u{043e}", "Lent", "Lento", "Lento"]),
|
||||
("Not hashing", ["Not hashing", "\u{672a}\u{6316}\u{77ff}", "\u{041d}\u{0435} \u{0445}\u{0435}\u{0448}\u{0438}\u{0440}\u{0443}\u{0435}\u{0442}", "Inactif", "Inactivo", "Inativo"]),
|
||||
("Paused", ["Paused", "\u{5df2}\u{6682}\u{505c}", "\u{041f}\u{0430}\u{0443}\u{0437}\u{0430}", "En pause", "Pausado", "Pausado"]),
|
||||
("Est. power", ["Est. power", "\u{4f30}\u{8ba1}\u{529f}\u{7387}", "\u{041e}\u{0446}. \u{043c}\u{043e}\u{0449}\u{043d}.", "Puiss. est.", "Pot. est.", "Pot. est."]),
|
||||
// Column headers (the default-visible set + common ones)
|
||||
("Model", ["Model", "\u{578b}\u{53f7}", "\u{041c}\u{043e}\u{0434}\u{0435}\u{043b}\u{044c}", "Mod\u{e8}le", "Modelo", "Modelo"]),
|
||||
("Health", ["Health", "\u{72b6}\u{6001}", "\u{0421}\u{043e}\u{0441}\u{0442}\u{043e}\u{044f}\u{043d}\u{0438}\u{0435}", "\u{c9}tat", "Estado", "Sa\u{fa}de"]),
|
||||
("Hashrate", ["Hashrate", "\u{7b97}\u{529b}", "\u{0425}\u{0435}\u{0448}\u{0440}\u{0435}\u{0439}\u{0442}", "Hashrate", "Hashrate", "Hashrate"]),
|
||||
("Power", ["Power", "\u{529f}\u{7387}", "\u{041c}\u{043e}\u{0449}\u{043d}\u{043e}\u{0441}\u{0442}\u{044c}", "Puissance", "Potencia", "Pot\u{ea}ncia"]),
|
||||
("Chip temp", ["Chip temp", "\u{82af}\u{7247}\u{6e29}\u{5ea6}", "\u{0422}\u{0435}\u{043c}\u{043f}. \u{0447}\u{0438}\u{043f}\u{0430}", "Temp. puce", "Temp. chip", "Temp. chip"]),
|
||||
("Firmware", ["Firmware", "\u{56fa}\u{4ef6}", "\u{041f}\u{0440}\u{043e}\u{0448}\u{0438}\u{0432}\u{043a}\u{0430}", "Firmware", "Firmware", "Firmware"]),
|
||||
("CPU", ["CPU", "CPU", "\u{041f}\u{0440}\u{043e}\u{0446}.", "Processeur", "CPU", "CPU"]),
|
||||
("Access", ["Access", "\u{8bbf}\u{95ee}", "\u{0414}\u{043e}\u{0441}\u{0442}\u{0443}\u{043f}", "Acc\u{e8}s", "Acceso", "Acesso"]),
|
||||
("Light", ["Light", "\u{6307}\u{793a}\u{706f}", "\u{041f}\u{043e}\u{0434}\u{0441}\u{0432}\u{0435}\u{0442}\u{043a}\u{0430}", "Voyant", "Luz", "Luz"]),
|
||||
("Fan (RPM)", ["Fan (RPM)", "\u{98ce}\u{6247} (RPM)", "\u{0412}\u{0435}\u{043d}\u{0442}. (\u{043e}\u{0431}/\u{043c}\u{0438}\u{043d})", "Ventilo (TR/M)", "Ventilador (RPM)", "Ventoinha (RPM)"]),
|
||||
("Control Board", ["Control Board", "\u{63a7}\u{5236}\u{677f}", "\u{041f}\u{043b}\u{0430}\u{0442}\u{0430} \u{0443}\u{043f}\u{0440}.", "Carte de contr\u{f4}le", "Placa control", "Placa controlo"]),
|
||||
("Uptime", ["Uptime", "\u{8fd0}\u{884c}\u{65f6}\u{95f4}", "\u{0412}\u{0440}\u{0435}\u{043c}\u{044f} \u{0440}\u{0430}\u{0431}.", "Dur\u{e9}e", "Tiempo activo", "Tempo ativo"]),
|
||||
("Serial", ["Serial", "\u{5e8f}\u{5217}\u{53f7}", "\u{0421}\u{0435}\u{0440}\u{0438}\u{0439}\u{043d}\u{044b}\u{0439}", "N\u{b0} de s\u{e9}rie", "N\u{b0} de serie", "N\u{b0} de s\u{e9}rie"]),
|
||||
];
|
||||
@@ -0,0 +1,42 @@
|
||||
//! In-app activity log (round 15 #13). A small, process-global ring buffer of
|
||||
//! timestamped messages -- scans starting/finishing, operations applied, errors --
|
||||
//! shown in the Settings > Logs page. Thread-safe so background workers can append.
|
||||
|
||||
use std::sync::Mutex;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
const MAX_ENTRIES: usize = 2000;
|
||||
|
||||
static LOG: Mutex<Vec<String>> = Mutex::new(Vec::new());
|
||||
|
||||
/// Local wall-clock HH:MM:SS for a log line. Uses the system clock offset from
|
||||
/// UTC via the TZ-less epoch; good enough for an activity log timestamp.
|
||||
fn stamp() -> String {
|
||||
let secs = SystemTime::now().duration_since(UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0);
|
||||
let t = secs % 86_400;
|
||||
format!("{:02}:{:02}:{:02}", t / 3600, (t % 3600) / 60, t % 60)
|
||||
}
|
||||
|
||||
/// Append a message to the activity log (timestamped).
|
||||
pub fn log(msg: impl Into<String>) {
|
||||
let line = format!("{} {}", stamp(), msg.into());
|
||||
if let Ok(mut v) = LOG.lock() {
|
||||
v.push(line);
|
||||
let len = v.len();
|
||||
if len > MAX_ENTRIES {
|
||||
v.drain(0..len - MAX_ENTRIES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The whole log as one string, newest last (for the Logs page text box).
|
||||
pub fn dump() -> String {
|
||||
LOG.lock().map(|v| v.join("\n")).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Clear the log.
|
||||
pub fn clear() {
|
||||
if let Ok(mut v) = LOG.lock() {
|
||||
v.clear();
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ mod access_probe;
|
||||
mod credentials;
|
||||
mod export;
|
||||
mod fixtures;
|
||||
mod i18n;
|
||||
mod logs;
|
||||
mod log_scan;
|
||||
mod model;
|
||||
mod naming;
|
||||
@@ -67,6 +69,9 @@ fn main() {
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
// Load the saved UI language before any strings are built (round 15 #13).
|
||||
i18n::init();
|
||||
|
||||
// Bootstrap the wx app + main frame (upstream bridge).
|
||||
wx_rs::init_app("alkane-toolkit", 1280, 800);
|
||||
// Follow the system light/dark appearance.
|
||||
|
||||
+125
-15
@@ -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),
|
||||
|
||||
+9
-1
@@ -10,7 +10,7 @@
|
||||
+pub use widgets::*;
|
||||
--- a/src/widgets.rs
|
||||
+++ b/src/widgets.rs
|
||||
@@ -0,0 +1,903 @@
|
||||
@@ -0,0 +1,911 @@
|
||||
+// widgets.rs — alkane-toolkit extension: Rust bindings for the widget bridge
|
||||
+// in cpp_src/widgets_bridge.cpp. Handles are opaque pointers owned by the
|
||||
+// wxWidgets object tree (parents own children; nothing to free in Rust).
|
||||
@@ -102,6 +102,7 @@
|
||||
+ pub fn wxbr_menu_new() -> *mut c_void;
|
||||
+ pub fn wxbr_menu_append(menu: *mut c_void, id: c_int, label: *const c_char);
|
||||
+ pub fn wxbr_menu_append_separator(menu: *mut c_void);
|
||||
+ pub fn wxbr_menu_append_submenu(menu: *mut c_void, label: *const c_char, submenu: *mut c_void);
|
||||
+ pub fn wxbr_popup_menu(win: *mut c_void, menu: *mut c_void);
|
||||
+ pub fn wxbr_timer(id: c_int, ms: c_int) -> *mut c_void;
|
||||
+ pub fn wxbr_gauge(parent: *mut c_void, range: c_int) -> *mut c_void;
|
||||
@@ -791,6 +792,13 @@
|
||||
+ unsafe { notsafe::wxbr_menu_append_separator(self.0) }
|
||||
+ }
|
||||
+
|
||||
+ /// Append `submenu` under this menu with `label` (round 15 #13). This menu
|
||||
+ /// takes ownership of the submenu.
|
||||
+ pub fn menu_append_submenu(&self, label: &str, submenu: Widget) {
|
||||
+ let c = CString::new(label).unwrap_or_default();
|
||||
+ unsafe { notsafe::wxbr_menu_append_submenu(self.0, c.as_ptr(), submenu.0) }
|
||||
+ }
|
||||
+
|
||||
+ /// Show `menu` as a popup on this window; blocks until dismissed.
|
||||
+ pub fn popup_menu(&self, menu: Widget) {
|
||||
+ unsafe { notsafe::wxbr_popup_menu(self.0, menu.0) }
|
||||
|
||||
+7
-1
@@ -1,6 +1,6 @@
|
||||
--- a/cpp_src/widgets_bridge.cpp
|
||||
+++ b/cpp_src/widgets_bridge.cpp
|
||||
@@ -0,0 +1,2047 @@
|
||||
@@ -0,0 +1,2053 @@
|
||||
+// widgets_bridge.cpp — alkane-toolkit extension to wx-rs
|
||||
+// Adds the widget/event surface the toolkit UI needs on top of the upstream
|
||||
+// render-callback bridge (which is kept untouched).
|
||||
@@ -1728,6 +1728,12 @@
|
||||
+ ((wxMenu*)menu)->Append(id, wxString::FromUTF8(label));
|
||||
+}
|
||||
+
|
||||
+// Append `submenu` under `menu` as a labelled sub-menu (round 15 #13); `menu`
|
||||
+// takes ownership of `submenu`.
|
||||
+void wxbr_menu_append_submenu(void* menu, const char* label, void* submenu) {
|
||||
+ ((wxMenu*)menu)->AppendSubMenu((wxMenu*)submenu, wxString::FromUTF8(label));
|
||||
+}
|
||||
+
|
||||
+void wxbr_menu_append_separator(void* menu) {
|
||||
+ ((wxMenu*)menu)->AppendSeparator();
|
||||
+}
|
||||
|
||||
@@ -1725,6 +1725,12 @@ void wxbr_menu_append(void* menu, int id, const char* label) {
|
||||
((wxMenu*)menu)->Append(id, wxString::FromUTF8(label));
|
||||
}
|
||||
|
||||
// Append `submenu` under `menu` as a labelled sub-menu (round 15 #13); `menu`
|
||||
// takes ownership of `submenu`.
|
||||
void wxbr_menu_append_submenu(void* menu, const char* label, void* submenu) {
|
||||
((wxMenu*)menu)->AppendSubMenu((wxMenu*)submenu, wxString::FromUTF8(label));
|
||||
}
|
||||
|
||||
void wxbr_menu_append_separator(void* menu) {
|
||||
((wxMenu*)menu)->AppendSeparator();
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ mod notsafe {
|
||||
pub fn wxbr_menu_new() -> *mut c_void;
|
||||
pub fn wxbr_menu_append(menu: *mut c_void, id: c_int, label: *const c_char);
|
||||
pub fn wxbr_menu_append_separator(menu: *mut c_void);
|
||||
pub fn wxbr_menu_append_submenu(menu: *mut c_void, label: *const c_char, submenu: *mut c_void);
|
||||
pub fn wxbr_popup_menu(win: *mut c_void, menu: *mut c_void);
|
||||
pub fn wxbr_timer(id: c_int, ms: c_int) -> *mut c_void;
|
||||
pub fn wxbr_gauge(parent: *mut c_void, range: c_int) -> *mut c_void;
|
||||
@@ -778,6 +779,13 @@ impl Widget {
|
||||
unsafe { notsafe::wxbr_menu_append_separator(self.0) }
|
||||
}
|
||||
|
||||
/// Append `submenu` under this menu with `label` (round 15 #13). This menu
|
||||
/// takes ownership of the submenu.
|
||||
pub fn menu_append_submenu(&self, label: &str, submenu: Widget) {
|
||||
let c = CString::new(label).unwrap_or_default();
|
||||
unsafe { notsafe::wxbr_menu_append_submenu(self.0, c.as_ptr(), submenu.0) }
|
||||
}
|
||||
|
||||
/// Show `menu` as a popup on this window; blocks until dismissed.
|
||||
pub fn popup_menu(&self, menu: Widget) {
|
||||
unsafe { notsafe::wxbr_popup_menu(self.0, menu.0) }
|
||||
|
||||
Reference in New Issue
Block a user