Compare commits

...
2 Commits
Author SHA1 Message Date
noahandClaude Opus 4.8 282f0b195c GUI round 12 (#13): editable per-firmware default scan credentials
Adds a per-firmware default-login editor so the operator can set the discovery
credentials each firmware is probed with, rather than a single global pair.

- credentials.rs: a per-firmware store (firmware-credentials.txt, 0600, one
  "name<TAB>user<TAB>pass" line per firmware) keyed by the asic-rs firmware
  registry's Display name -- the same key the factory uses for
  with_firmware_discovery_auth. A firmware_default_creds() table seeds the editor
  with each firmware's shipped default (mirrors the asic-rs backends' default_auth
  constants; asic-rs does not expose them at the entry level).
- configured_factory() precedence is now: a per-firmware override wins; else the
  single global scan credential (unchanged back-compat) applies to every backend;
  else the backend's own default_auth. Nothing saved -> plain MinerFactory::new().
- UI: the "Set scan credentials..." dialog gains a "Per-firmware defaults..."
  button opening an editor that lists every firmware in the compiled-in registry
  (read at runtime, not hard-coded) with editable user/pass fields prefilled from
  the saved override or the shipped default. Save persists only rows that differ
  from the shipped default (so defaults evolve with asic-rs and the file stays
  minimal); Reset to defaults clears all overrides.

Verified under Xvfb: the editor lists all 16 registry firmwares with correct
default logins (AntMiner root/root, WhatsMiner admin/admin, VNish blank/admin,
UMC OS blank/letmein, ...). Round-trip/permissions/precedence covered by a unit
test (folded into the existing HOME-scoped credentials test to avoid a parallel
HOME race); self-test still passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
2026-09-20 00:06:37 -06:00
noahandClaude Opus 4.8 1857a9e1a0 GUI round 12 (#9, #11): SVG icons in table cells (access padlocks + status)
Adds an SVG-backed icon path to the table's segment renderer: the Rust side
registers a raw SVG per shape sentinel (with its viewBox dims), and the renderer
recolours it to the cell's segment colour, rasterises once per (sentinel, colour,
height) and caches the bitmap. The recolour matches the KPI cards' svg_recolored
(replace currentColor + inject a root fill so fill-less SVGs inherit the colour).

- #9: the Access column padlocks now use the operator-supplied Font Awesome
  lock/unlock SVGs (red closed = view-only, green open = writable) instead of the
  hand-drawn vector padlock. The vector padlock remains as a fallback if the SVG
  is somehow unregistered.
- #11: the Status column renders its KPI icon (green rabbit = hashing, amber
  turtle = slow, red cracked wine glass = not hashing, blue otter = paused)
  instead of the status text, matching the dashboard cards. An unrecognised
  status still falls back to coloured text.

The status dots (hashboards, locate light) stay vector so the round-12 #6 fade
can drive them later. Self-test updated (Status is now a shape cell, verified
structurally like the other icon columns) and still passes. Verified under Xvfb:
the Access column shows the FA padlocks and, with the Status column enabled, the
four status icons render in their KPI colours. wx-rs patches 0002/0003
regenerated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
2026-09-19 23:55:37 -06:00
8 changed files with 562 additions and 30 deletions
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--! Font Awesome Pro 7.3.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2026 Fonticons, Inc. --><path fill="currentColor" d="M128 192l128 0 0-64c0-35.3-28.7-64-64-64s-64 28.7-64 64l0 64zm-64 0l0-64C64 57.3 121.3 0 192 0S320 57.3 320 128l0 64c35.3 0 64 28.7 64 64l0 192c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 256c0-35.3 28.7-64 64-64zm256 64l-256 0 0 192 256 0 0-192z"/></svg>

After

Width:  |  Height:  |  Size: 522 B

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 7.3.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2026 Fonticons, Inc. --><path fill="currentColor" d="M320 128c0-35.3 28.7-64 64-64s64 28.7 64 64l0 128 64 0 0-128C512 57.3 454.7 0 384 0S256 57.3 256 128l0 64-192 0c-35.3 0-64 28.7-64 64L0 448c0 35.3 28.7 64 64 64l256 0c35.3 0 64-28.7 64-64l0-192c0-35.3-28.7-64-64-64l0-64zM64 256l256 0 0 192-256 0 0-192z"/></svg>

After

Width:  |  Height:  |  Size: 520 B

+141 -8
View File
@@ -5,6 +5,7 @@
//! is the one place that fans a saved username/password out across the whole
//! firmware registry, so `scan`'s callers never have to think about it.
use std::collections::HashMap;
use std::io::Write;
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
@@ -14,6 +15,10 @@ use asic_rs::core::traits::miner::MinerAuth;
use crate::scan::config_path;
pub const CREDENTIALS_FILE: &str = "scan-credentials.txt";
/// Per-firmware default logins the operator can override (round 12 #13). One
/// `firmware-name<TAB>user<TAB>pass` line per firmware, 0600 like the others.
/// Keyed by the firmware registry's Display name (see `firmware_default_creds`).
pub const FIRMWARE_CREDENTIALS_FILE: &str = "firmware-credentials.txt";
/// SSH login for the control board (used by the PIC probe; distinct from the
/// web/API scan credentials above -- miners' SSH root login is usually not the
/// same account as the web digest-auth login).
@@ -87,16 +92,115 @@ pub fn clear_credentials() -> std::io::Result<()> {
}
}
/// Build a `MinerFactory` with the saved credentials (if any) applied as
/// discovery auth for every firmware backend, so scans, refreshes, config
/// actions, and firmware flashes all authenticate against a non-default
/// login the same way. With no saved credentials this is plain `MinerFactory::new()`
/// and every backend falls back to its own default auth.
/// The stock/default login each firmware ships with, keyed by the firmware
/// registry's Display name (round 12 #13). These seed the per-firmware editor and
/// let it tell an override from an unchanged default; they mirror the
/// `default_auth()` constants in the vendored asic-rs backends (a single
/// best-guess per registry entry, since a stock entry can span several backend
/// versions). asic-rs does not expose these at the entry level, so they are
/// duplicated here; a firmware absent from this table defaults to blank.
pub fn firmware_default_creds() -> &'static [(&'static str, &'static str, &'static str)] {
&[
("AntMiner Stock", "root", "root"),
("WhatsMiner Stock", "admin", "admin"),
("Braiins", "root", "root"),
("VNish", "", "admin"),
("LuxOS", "root", "root"),
("UMC OS", "", "letmein"),
("Marathon", "root", "root"),
("VolcMiner Stock", "root", "ltc@dog"),
("Elphapex Stock", "root", "root"),
("FutureBit Stock", "futurebit", "futurebit123"),
("SealMiner Stock", "seal", "seal"),
("Auradine Stock", "admin", "admin"),
("AvalonMiner Stock", "", ""),
("Nerdaxe Stock", "", ""),
("Proto Stock", "", ""),
("Bitaxe Stock", "", ""),
]
}
/// The shipped default login for a firmware, or `("","")` if unknown.
pub fn firmware_default_for(name: &str) -> (String, String) {
firmware_default_creds()
.iter()
.find(|(n, _, _)| *n == name)
.map(|(_, u, p)| (u.to_string(), p.to_string()))
.unwrap_or_default()
}
/// Load the operator's per-firmware credential overrides, keyed by firmware
/// Display name. Malformed lines are skipped.
pub fn load_firmware_credentials() -> HashMap<String, (String, String)> {
let mut map = HashMap::new();
let Ok(s) = std::fs::read_to_string(config_path(FIRMWARE_CREDENTIALS_FILE)) else {
return map;
};
for line in s.lines() {
let mut parts = line.splitn(3, '\t');
let (Some(name), user) = (parts.next(), parts.next()) else {
continue;
};
if name.is_empty() {
continue;
}
let user = user.unwrap_or("").to_string();
let pass = parts.next().unwrap_or("").to_string();
map.insert(name.to_string(), (user, pass));
}
map
}
/// Save the per-firmware credential overrides (0600), sorted by name for a
/// stable file. An empty map clears the file.
pub fn save_firmware_credentials(map: &HashMap<String, (String, String)>) -> std::io::Result<()> {
if map.is_empty() {
return clear_firmware_credentials();
}
let p = config_path(FIRMWARE_CREDENTIALS_FILE);
if let Some(dir) = p.parent() {
std::fs::create_dir_all(dir)?;
}
let mut f = std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.mode(0o600)
.open(&p)?;
f.set_permissions(std::fs::Permissions::from_mode(0o600))?;
let mut names: Vec<&String> = map.keys().collect();
names.sort();
for name in names {
let (user, pass) = &map[name];
f.write_all(format!("{name}\t{user}\t{pass}\n").as_bytes())?;
}
Ok(())
}
/// Remove the per-firmware overrides file, if any. Not an error if none exists.
pub fn clear_firmware_credentials() -> std::io::Result<()> {
clear_creds_file(FIRMWARE_CREDENTIALS_FILE)
}
/// Build a `MinerFactory` with saved credentials applied as discovery auth.
/// Precedence per firmware backend: a per-firmware override (round 12 #13) wins;
/// otherwise the single global scan credential (if set) applies to every backend;
/// otherwise the backend falls back to its own default auth. With nothing saved
/// this is plain `MinerFactory::new()`.
pub fn configured_factory() -> MinerFactory {
let mut factory = MinerFactory::new();
if let Some((user, pass)) = load_credentials() {
for fw in asic_rs::factory::default_firmware_registry() {
factory = factory.with_firmware_discovery_auth(fw.as_ref(), MinerAuth::new(user.clone(), pass.clone()));
let global = load_credentials();
let per_fw = load_firmware_credentials();
if global.is_none() && per_fw.is_empty() {
return factory;
}
for fw in asic_rs::factory::default_firmware_registry() {
let cred = per_fw
.get(&fw.to_string())
.cloned()
.or_else(|| global.clone());
if let Some((user, pass)) = cred {
factory = factory.with_firmware_discovery_auth(fw.as_ref(), MinerAuth::new(user, pass));
}
}
factory
@@ -149,6 +253,35 @@ mod tests {
assert_eq!(load_credentials(), None, "cleared -> None");
clear_credentials().unwrap(); // idempotent: clearing an already-clear store is not an error
// Per-firmware overrides (round 12 #13). Kept in this same test because
// HOME is process-global: a second #[test] mutating it would race under
// cargo's default parallel runner.
assert!(load_firmware_credentials().is_empty(), "no file -> empty map");
let mut fw = HashMap::new();
fw.insert("WhatsMiner Stock".to_string(), ("super".to_string(), "sup3r".to_string()));
fw.insert("VNish".to_string(), ("".to_string(), "hunter2".to_string()));
save_firmware_credentials(&fw).unwrap();
// 0600, and it round-trips (an empty username survives the tab format).
let fwpath = config_path(FIRMWARE_CREDENTIALS_FILE);
assert_eq!(
std::fs::metadata(&fwpath).unwrap().permissions().mode() & 0o777,
0o600,
"per-firmware creds file must be 0600"
);
let back = load_firmware_credentials();
assert_eq!(back.get("WhatsMiner Stock"), Some(&("super".into(), "sup3r".into())));
assert_eq!(back.get("VNish"), Some(&("".into(), "hunter2".into())));
assert_eq!(back.len(), 2);
// Shipped-default lookup: known firmware resolves, unknown blanks.
assert_eq!(firmware_default_for("AntMiner Stock"), ("root".into(), "root".into()));
assert_eq!(firmware_default_for("nonexistent"), (String::new(), String::new()));
// Overrides + no global still builds a factory.
let _ = configured_factory();
// Saving an empty map clears the file (no stale overrides linger).
save_firmware_credentials(&HashMap::new()).unwrap();
assert!(load_firmware_credentials().is_empty(), "empty save -> cleared");
clear_firmware_credentials().unwrap(); // idempotent
match prev {
Some(v) => std::env::set_var("HOME", v),
None => std::env::remove_var("HOME"),
+205 -6
View File
@@ -72,6 +72,12 @@ const ID_FLASH_CANCEL: i32 = 745;
const ID_CREDS_SAVE: i32 = 746;
const ID_CREDS_CLEAR: i32 = 747;
const ID_CREDS_CANCEL: i32 = 748;
// Per-firmware default-credentials editor (round 12 #13), opened from the scan
// credentials dialog.
const ID_FWCREDS_OPEN: i32 = 749;
const ID_FWCREDS_SAVE: i32 = 750;
const ID_FWCREDS_RESET: i32 = 751;
const ID_FWCREDS_CANCEL: i32 = 752;
// Column-header right-click menu (Excel-style).
const ID_HDR_SORT_ASC: i32 = 760;
const ID_HDR_SORT_DESC: i32 = 761;
@@ -242,6 +248,48 @@ fn encode_flag_cell(plain: &str, color: Option<(u8, u8, u8)>) -> String {
const SHAPE_DOT: &str = "\u{0007}";
const SHAPE_LOCK: &str = "\u{0002}";
const SHAPE_UNLOCK: &str = "\u{0003}";
// Status-column KPI icons (round 12 #11): one sentinel per status, each drawn
// from the same SVG as its dashboard KPI card. Registered with the bridge in
// `register_cell_icons` at startup.
const SHAPE_HASHING: &str = "\u{0004}";
const SHAPE_SLOW: &str = "\u{0005}";
const SHAPE_NOTHASHING: &str = "\u{0006}";
const SHAPE_PAUSED: &str = "\u{0008}";
/// Register every SVG-backed table-cell icon with the bridge (round 12 #9/#11):
/// the access padlocks and the four status KPI icons. Called once at startup;
/// the renderer recolours each per cell. The sentinel code points MUST match the
/// `\u{..}` constants above and the SHAPE_* set in widgets_bridge.cpp.
fn register_cell_icons() {
// (sentinel first char, svg) pairs; the bridge reads the viewBox dims we pass
// to keep each icon's aspect ratio when it rasterises at the cell height.
let icons: [(&str, &str); 6] = [
(SHAPE_LOCK, SVG_LOCK),
(SHAPE_UNLOCK, SVG_UNLOCK),
(SHAPE_HASHING, SVG_RABBIT),
(SHAPE_SLOW, SVG_TURTLE),
(SHAPE_NOTHASHING, SVG_WINE_CRACK),
(SHAPE_PAUSED, SVG_OTTER),
];
for (sentinel, svg) in icons {
let cp = sentinel.chars().next().map(|c| c as u32).unwrap_or(0);
let (vbw, vbh) = svg_viewbox(svg);
wx_rs::register_shape_svg(cp, svg, vbw, vbh);
}
}
/// Parse an SVG's viewBox width/height (round 12 #9/#11), defaulting to a square
/// when absent so the bridge can preserve the icon aspect at any cell height.
fn svg_viewbox(svg: &str) -> (i32, i32) {
svg.split("viewBox=\"")
.nth(1)
.and_then(|s| s.split('"').next())
.and_then(|vb| {
let n: Vec<f64> = vb.split_whitespace().filter_map(|x| x.parse().ok()).collect();
(n.len() == 4 && n[2] > 0.0 && n[3] > 0.0).then(|| (n[2].round() as i32, n[3].round() as i32))
})
.unwrap_or((1, 1))
}
/// Boards column: one status dot per hashboard (round 11 #10). Board 1 is the
/// rightmost dot, so boards render high-position-first (left to right). green =
@@ -285,6 +333,20 @@ fn encode_light_dot(pal: &Palette, flashing: Option<bool>) -> String {
}
}
/// Status column: the status rendered as its KPI icon in the status colour
/// (round 12 #11) -- rabbit=hashing, turtle=slow, cracked wine glass=not
/// hashing, otter=paused. An unrecognised status falls back to coloured text.
fn encode_status_icon(pal: &Palette, status: &str) -> String {
let shape = match status {
"hashing" => SHAPE_HASHING,
"slow" => SHAPE_SLOW,
"not hashing" => SHAPE_NOTHASHING,
"paused" => SHAPE_PAUSED,
_ => return encode_segments(&[(Some(status_kind_color(pal, status)), status.to_string())]),
};
encode_segments(&[(Some(status_kind_color(pal, status)), shape.to_string())])
}
// KPI card icons (round 11 #15). The animal/wine-glass SVGs are Font Awesome Pro
// (operator-supplied); bolt/hive are matching in-repo SVGs. All use
// fill="currentColor", recoloured per card at render time.
@@ -294,6 +356,10 @@ const SVG_WINE_CRACK: &str = include_str!("../assets/icons/wine-glass-crack.svg"
const SVG_OTTER: &str = include_str!("../assets/icons/otter.svg");
const SVG_HIVE: &str = include_str!("../assets/icons/hive.svg");
const SVG_BOLT: &str = include_str!("../assets/icons/bolt.svg");
// Access-column padlocks (round 12 #9): operator-supplied Font Awesome padlocks
// that replace the hand-drawn vector padlocks in the table.
const SVG_LOCK: &str = include_str!("../assets/icons/lock.svg");
const SVG_UNLOCK: &str = include_str!("../assets/icons/unlock.svg");
/// KPI card minimum widths. The count cards (Total/Hashing/...) are narrow; the
/// two wide cards (SHA-256 Hashrate, Est. power) need more room so their
@@ -509,6 +575,10 @@ pub struct App {
creds_dialog: Widget,
creds_user_input: Widget,
creds_pass_input: Widget,
// Per-firmware default-credentials editor (round 12 #13): the dialog plus one
// (firmware name, user field, pass field) per registry firmware.
fwcreds_dialog: Widget,
fwcreds_rows: Vec<(String, Widget, Widget)>,
// Background access (lock-state) probe.
access_probe: Option<scan::AccessProbeHandle>,
// Background SSH PIC probe + its credentials dialog.
@@ -554,6 +624,9 @@ pub struct App {
pub fn build(frame: Widget) -> App {
let pal = palette();
// Register the SVG-backed table-cell icons once (access padlocks + status KPI
// icons, round 12 #9/#11) before any row is rendered.
register_cell_icons();
let panel = Widget::panel(frame);
let root = Widget::box_sizer(true);
@@ -777,6 +850,8 @@ pub fn build(frame: Widget) -> App {
creds_dialog: frame,
creds_user_input: frame,
creds_pass_input: frame,
fwcreds_dialog: frame,
fwcreds_rows: Vec::new(),
access_probe: None,
pic_probe: None,
pending_pic_targets: Vec::new(),
@@ -979,9 +1054,9 @@ impl App {
}
Column::Firmware => encode_flag_cell(&c.cell(r), firmware_color(&r.firmware)),
Column::Status => {
// Status keeps its status colour on its own cell (the
// row is no longer tinted wholesale).
encode_flag_cell(&c.cell(r), Some(status_kind_color(&self.pal, r.status())))
// The status reads as its KPI icon (round 12 #11), drawn
// in the status colour so it matches the dashboard card.
encode_status_icon(&self.pal, r.status())
}
_ => continue,
};
@@ -1751,6 +1826,19 @@ impl App {
pass_input.set_min_size(200, -1);
pass_row.add(pass_input, 1, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 6);
root.add_sizer(pass_row, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
// The single credential above is applied to every firmware that has no
// per-firmware override; the button below edits those per-firmware default
// logins (round 12 #13).
let fwrow = Widget::box_sizer(false);
fwrow.add(
Widget::static_text(dlg, "Or set a login per firmware:"),
0,
sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL,
6,
);
fwrow.add_stretch(1);
fwrow.add(Widget::button(dlg, "Per-firmware defaults...", ID_FWCREDS_OPEN), 0, sf::BORDER_ALL, 6);
root.add_sizer(fwrow, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT | sf::BORDER_TOP, 6);
let btns = Widget::box_sizer(false);
btns.add_stretch(1);
btns.add(Widget::button(dlg, "Save", ID_CREDS_SAVE), 0, sf::BORDER_ALL, 6);
@@ -1758,7 +1846,7 @@ impl App {
btns.add(Widget::button(dlg, "Cancel", ID_CREDS_CANCEL), 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(360, 190);
dlg.set_min_size(460, 220);
dlg.fit(dlg);
self.creds_dialog = dlg;
self.creds_user_input = user_input;
@@ -1766,6 +1854,113 @@ impl App {
dlg
}
/// Build (but do not show) the per-firmware default-credentials editor
/// (round 12 #13): one row per firmware in the asic-rs registry, each with a
/// username and password field prefilled from the saved override or, failing
/// that, the firmware's shipped default. Editing a field away from the default
/// makes it an override; setting it back to the default clears the override.
fn build_firmware_creds_dialog(&mut self) -> Widget {
let frame = Widget::main_frame();
let dlg = Widget::dialog(frame, "Per-firmware default logins");
let root = Widget::box_sizer(true);
root.add(
Widget::static_text(
dlg,
"Default login used when auto-discovering each firmware. Blank fields mean no login.\nValues left at the firmware's shipped default are not saved as overrides.",
),
0,
sf::BORDER_ALL,
8,
);
// Column headers.
let head = Widget::box_sizer(false);
let h_fw = Widget::static_text(dlg, "Firmware");
h_fw.set_min_size(150, -1);
head.add(h_fw, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
let h_user = Widget::static_text(dlg, "Username");
h_user.set_min_size(150, -1);
head.add(h_user, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
head.add(Widget::static_text(dlg, "Password"), 0, sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
root.add_sizer(head, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT | sf::BORDER_TOP, 6);
let saved = credentials::load_firmware_credentials();
let mut rows: Vec<(String, Widget, Widget)> = Vec::new();
for fw in asic_rs::factory::default_firmware_registry() {
let name = fw.to_string();
let (def_user, def_pass) = credentials::firmware_default_for(&name);
let (user, pass) = saved
.get(&name)
.cloned()
.unwrap_or((def_user, def_pass));
let row = Widget::box_sizer(false);
let label = Widget::static_text(dlg, &name);
label.set_min_size(150, -1);
row.add(label, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
let user_ctrl = Widget::text_ctrl(dlg, false);
user_ctrl.set_min_size(150, -1);
user_ctrl.set_value(&user);
row.add(user_ctrl, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
let pass_ctrl = Widget::text_ctrl(dlg, false);
pass_ctrl.set_min_size(150, -1);
pass_ctrl.set_value(&pass);
row.add(pass_ctrl, 1, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
root.add_sizer(row, 0, sf::EXPAND | sf::BORDER_TOP, 4);
rows.push((name, user_ctrl, pass_ctrl));
}
let btns = Widget::box_sizer(false);
btns.add_stretch(1);
btns.add(Widget::button(dlg, "Save", ID_FWCREDS_SAVE), 0, sf::BORDER_ALL, 6);
btns.add(Widget::button(dlg, "Reset to defaults", ID_FWCREDS_RESET), 0, sf::BORDER_ALL, 6);
btns.add(Widget::button(dlg, "Cancel", ID_FWCREDS_CANCEL), 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(520, 200);
dlg.fit(dlg);
self.fwcreds_dialog = dlg;
self.fwcreds_rows = rows;
dlg
}
/// Persist the per-firmware editor: a row that differs from the firmware's
/// shipped default becomes an override; a row equal to the default clears it.
fn apply_firmware_creds_save(&mut self) {
let mut map: std::collections::HashMap<String, (String, String)> = std::collections::HashMap::new();
for (name, user_ctrl, pass_ctrl) in &self.fwcreds_rows {
let user = user_ctrl.get_value();
let pass = pass_ctrl.get_value();
let default = credentials::firmware_default_for(name);
if (user.clone(), pass.clone()) != default {
map.insert(name.clone(), (user, pass));
}
}
match credentials::save_firmware_credentials(&map) {
Ok(()) => {
self.fwcreds_dialog.close(1);
let n = map.len();
wx_rs::set_status_text(&format!(
"per-firmware logins saved ({n} override{})",
if n == 1 { "" } else { "s" }
));
}
Err(e) => wx_rs::set_status_text(&format!("failed to save per-firmware logins: {e}")),
}
}
/// Reset every editor row to the firmware's shipped default and clear the
/// saved overrides.
fn apply_firmware_creds_reset(&mut self) {
for (name, user_ctrl, pass_ctrl) in &self.fwcreds_rows {
let (user, pass) = credentials::firmware_default_for(name);
user_ctrl.set_value(&user);
pass_ctrl.set_value(&pass);
}
match credentials::clear_firmware_credentials() {
Ok(()) => wx_rs::set_status_text("per-firmware logins reset to defaults"),
Err(e) => wx_rs::set_status_text(&format!("failed to clear per-firmware logins: {e}")),
}
}
fn apply_creds_save(&mut self) {
let user = self.creds_user_input.get_value();
let mut pass = self.creds_pass_input.get_value();
@@ -2852,6 +3047,10 @@ impl App {
ID_CREDS_SAVE => self.apply_creds_save(),
ID_CREDS_CLEAR => self.apply_creds_clear(),
ID_CREDS_CANCEL => self.creds_dialog.close(0),
ID_FWCREDS_OPEN => return Some(self.build_firmware_creds_dialog()),
ID_FWCREDS_SAVE => self.apply_firmware_creds_save(),
ID_FWCREDS_RESET => self.apply_firmware_creds_reset(),
ID_FWCREDS_CANCEL => self.fwcreds_dialog.close(0),
ID_KPI_HASHING => self.toggle_kpi_filter("hashing"),
ID_KPI_SLOW => self.toggle_kpi_filter("slow"),
ID_KPI_NOT => self.toggle_kpi_filter("not hashing"),
@@ -2960,12 +3159,12 @@ impl App {
// Icon/dot columns (round 11 #10/#13) render shape sentinels, not
// text, so they don't round-trip to c.cell(r); they're verified
// structurally in the icon-column spot-check below.
if matches!(c, Column::Hashboards | Column::Locked | Column::Light) {
if matches!(c, Column::Hashboards | Column::Locked | Column::Light | Column::Status) {
continue;
}
let want = c.cell(r);
let raw = t.dvlc_get_cell(disp_row, j).unwrap_or_default();
let got = if matches!(c, Column::Hashrate | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Error | Column::Status | Column::Firmware) {
let got = if matches!(c, Column::Hashrate | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Error | Column::Firmware) {
decode_segments_plain(&raw)
} else {
raw
+13 -1
View File
@@ -10,7 +10,7 @@
+pub use widgets::*;
--- a/src/widgets.rs
+++ b/src/widgets.rs
@@ -0,0 +1,794 @@
@@ -0,0 +1,806 @@
+// 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).
@@ -117,6 +117,7 @@
+ pub fn wxbr_choice_set_selection(win: *mut c_void, i: c_int);
+ pub fn wxbr_media_button(parent: *mut c_void, id: c_int, kind: c_int, r: c_int, g: c_int, b: c_int) -> *mut c_void;
+ pub fn wxbr_svg_icon(parent: *mut c_void, svg: *const c_char, w: c_int, h: c_int) -> *mut c_void;
+ pub fn wxbr_register_shape_svg(sentinel: c_int, svg: *const c_char, vbw: c_int, vbh: c_int);
+ pub fn wxbr_bind_sys_colour(win: *mut c_void);
+ pub fn wxbr_destroy(win: *mut c_void);
+ pub fn wxbr_destroy_children(win: *mut c_void);
@@ -213,6 +214,17 @@
+ unsafe { notsafe::wxbr_status_indicator_set(c.as_ptr(), r as c_int, g as c_int, b as c_int) }
+}
+
+/// Register a raw SVG for a table-cell shape sentinel (a control-char code point)
+/// so the segment renderer can draw it recoloured to each cell's segment colour.
+/// `vbw`/`vbh` are the SVG viewBox dimensions, used to keep the icon's aspect
+/// ratio when it is rasterised at the cell height (round 12 #9/#11).
+pub fn register_shape_svg(sentinel: u32, svg: &str, vbw: i32, vbh: i32) {
+ let c = CString::new(svg).unwrap_or_default();
+ unsafe {
+ notsafe::wxbr_register_shape_svg(sentinel as c_int, c.as_ptr(), vbw as c_int, vbh as c_int)
+ }
+}
+
+/// Open a URL in the system default browser. Returns true on success.
+pub fn launch_browser(url: &str) -> bool {
+ let c = CString::new(url).unwrap_or_default();
+95 -8
View File
@@ -1,6 +1,6 @@
--- a/cpp_src/widgets_bridge.cpp
+++ b/cpp_src/widgets_bridge.cpp
@@ -0,0 +1,1460 @@
@@ -0,0 +1,1547 @@
+// 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).
@@ -159,27 +159,95 @@
+const wxUniChar SHAPE_DOT = 0x07; // filled status dot (hashboards, locate light)
+const wxUniChar SHAPE_LOCK = 0x02; // closed padlock (locked / view-only)
+const wxUniChar SHAPE_UNLOCK = 0x03; // open padlock (unlocked / writable)
+// Status-column KPI icons (round 12 #11): each renders the same Font Awesome
+// glyph as its dashboard KPI card, drawn from an SVG registered by the Rust side
+// (see wxbr_register_shape_svg). No vector fallback -- if unregistered the cell
+// is simply blank.
+const wxUniChar SHAPE_HASHING = 0x04; // rabbit (hashing)
+const wxUniChar SHAPE_SLOW = 0x05; // turtle (slow)
+const wxUniChar SHAPE_NOTHASHING = 0x06; // cracked wine glass (not hashing)
+const wxUniChar SHAPE_PAUSED = 0x08; // otter (paused)
+const int SHAPE_ADVANCE = 15; // horizontal space one shape occupies
+
+bool IsShapeSentinel(const wxString& s, wxUniChar& out) {
+ if (s.length() != 1) return false;
+ wxUniChar c = s[0];
+ if (c == SHAPE_DOT || c == SHAPE_LOCK || c == SHAPE_UNLOCK) {
+ if (c == SHAPE_DOT || c == SHAPE_LOCK || c == SHAPE_UNLOCK ||
+ c == SHAPE_HASHING || c == SHAPE_SLOW || c == SHAPE_NOTHASHING ||
+ c == SHAPE_PAUSED) {
+ out = c;
+ return true;
+ }
+ return false;
+}
+
+// Draw one shape sentinel, centred in the SHAPE_ADVANCE-wide slot at x.
+void DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, const wxColour& colour) {
+// Registry of SVG-backed shape icons (round 12 #9 access padlocks, #11 status
+// icons). The Rust side registers a raw SVG (with its viewBox dims for aspect)
+// per sentinel; DrawShape recolours it to the segment colour, rasterises once
+// per (sentinel, colour, height), caches the bitmap, and draws it. The access
+// padlocks (0x02/0x03) fall back to a hand-drawn vector when unregistered.
+struct ShapeSvg {
+ wxString svg;
+ int vbw;
+ int vbh;
+};
+std::map<int, ShapeSvg> g_shape_svgs;
+std::map<uint64_t, wxBitmap> g_shape_bmp_cache;
+
+const ShapeSvg* LookupShapeSvg(wxUniChar shape) {
+ auto it = g_shape_svgs.find((int)shape.GetValue());
+ return it == g_shape_svgs.end() ? nullptr : &it->second;
+}
+
+// Recolour an SVG to `c`, matching the Rust svg_recolored(): replace
+// fill="currentColor" and inject a root fill so shapes that omit a fill inherit
+// the colour too (e.g. the Font Awesome Free otter).
+wxString RecolorShapeSvg(const wxString& svg, const wxColour& c) {
+ wxString hex = wxString::Format("#%02X%02X%02X", (int)c.Red(), (int)c.Green(), (int)c.Blue());
+ wxString s = svg;
+ s.Replace("currentColor", hex);
+ int pos = s.Find("<svg ");
+ if (pos != wxNOT_FOUND) s.insert((size_t)pos + 5, wxString("fill=\"") + hex + "\" ");
+ return s;
+}
+
+const wxBitmap& ShapeBitmap(wxUniChar shape, const ShapeSvg& sv, const wxColour& col,
+ int w, int h) {
+ uint64_t rgb = ((uint64_t)col.Red() << 16) | ((uint64_t)col.Green() << 8) | (uint64_t)col.Blue();
+ uint64_t key = ((uint64_t)(unsigned)shape.GetValue() << 40) | (rgb << 8) | (uint64_t)(h & 0xFF);
+ auto it = g_shape_bmp_cache.find(key);
+ if (it != g_shape_bmp_cache.end()) return it->second;
+ wxString colored = RecolorShapeSvg(sv.svg, col);
+ wxBitmapBundle bundle = wxBitmapBundle::FromSVG(colored.ToUTF8().data(), wxSize(w, h));
+ wxBitmap bmp = bundle.GetBitmap(wxSize(w, h));
+ return g_shape_bmp_cache.emplace(key, bmp).first->second;
+}
+
+// Draw one shape sentinel centred at x; returns the horizontal space it used
+// (SHAPE_ADVANCE for the vector shapes, the icon width for a wider SVG icon).
+int DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, const wxColour& colour) {
+ int cy = cell.y + cell.height / 2;
+ // SVG-backed icon (access padlocks #9, status KPI icons #11): recolour to the
+ // segment colour, rasterise (cached), and draw centred in its slot.
+ if (const ShapeSvg* sv = LookupShapeSvg(shape)) {
+ int h = cell.height - 4;
+ if (h > 15) h = 15;
+ if (h < 8) h = 8;
+ int w = (sv->vbh > 0) ? (int)((double)h * sv->vbw / sv->vbh + 0.5) : h;
+ if (w < 1) w = 1;
+ const wxBitmap& bmp = ShapeBitmap(shape, *sv, colour, w, h);
+ if (bmp.IsOk()) {
+ int slot = (w > SHAPE_ADVANCE) ? w : SHAPE_ADVANCE;
+ dc->DrawBitmap(bmp, x + (slot - w) / 2, cy - h / 2, true);
+ return slot;
+ }
+ }
+ int cx = x + SHAPE_ADVANCE / 2;
+ if (shape == SHAPE_DOT) {
+ dc->SetPen(*wxTRANSPARENT_PEN);
+ dc->SetBrush(wxBrush(colour));
+ dc->DrawCircle(cx, cy, 4);
+ return;
+ return SHAPE_ADVANCE;
+ }
+ // Padlock: a filled body with a staple shackle above. The colour carries the
+ // state (green = unlocked, red = locked); the shackle is drawn ajar when open.
@@ -201,6 +269,7 @@
+ dc->DrawLine(rx, legTop, rx, legTop + sr); // ajar: right leg lifted
+ else
+ dc->DrawLine(rx, legTop, rx, by); // closed: right leg to body
+ return SHAPE_ADVANCE;
+}
+
+} // namespace
@@ -275,8 +344,7 @@
+ // selection highlight (round 11 #10/#13).
+ wxUniChar shape;
+ if (IsShapeSentinel(seg.text, shape)) {
+ DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain);
+ x += SHAPE_ADVANCE;
+ x += DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain);
+ continue;
+ }
+ if (seg.text.IsEmpty()) continue;
@@ -294,7 +362,13 @@
+ for (const ColorSegment& seg : ParseColorSegments(m_value)) {
+ wxUniChar shape;
+ if (IsShapeSentinel(seg.text, shape)) {
+ w += SHAPE_ADVANCE;
+ int adv = SHAPE_ADVANCE;
+ if (const ShapeSvg* sv = LookupShapeSvg(shape)) {
+ int hh = 15;
+ int ww = (sv->vbh > 0) ? (int)((double)hh * sv->vbw / sv->vbh + 0.5) : hh;
+ if (ww > adv) adv = ww;
+ }
+ w += adv;
+ if (h < 12) h = 12;
+ continue;
+ }
@@ -1381,6 +1455,19 @@
+ return (void*)new wxStaticBitmap((wxWindow*)parent, wxID_ANY, bmp);
+}
+
+// Register a raw SVG (with its viewBox width/height for aspect) for a table-cell
+// shape sentinel, so the SegmentRenderer can draw it recoloured to the cell's
+// segment colour (round 12 #9 access padlocks, #11 status KPI icons). Replaces
+// any prior registration for that sentinel and invalidates the bitmap cache.
+void wxbr_register_shape_svg(int sentinel, const char* svg, int vbw, int vbh) {
+ ShapeSvg s;
+ s.svg = wxString::FromUTF8(svg);
+ s.vbw = vbw;
+ s.vbh = vbh;
+ g_shape_svgs[sentinel] = s;
+ g_shape_bmp_cache.clear();
+}
+
+// ---- live theme changes -----------------------------------------------------
+
+// Emit WxEV_SYS_COLOUR when the OS light/dark theme changes so the app can
@@ -156,27 +156,95 @@ std::vector<ColorSegment> ParseColorSegments(const wxString& value) {
const wxUniChar SHAPE_DOT = 0x07; // filled status dot (hashboards, locate light)
const wxUniChar SHAPE_LOCK = 0x02; // closed padlock (locked / view-only)
const wxUniChar SHAPE_UNLOCK = 0x03; // open padlock (unlocked / writable)
// Status-column KPI icons (round 12 #11): each renders the same Font Awesome
// glyph as its dashboard KPI card, drawn from an SVG registered by the Rust side
// (see wxbr_register_shape_svg). No vector fallback -- if unregistered the cell
// is simply blank.
const wxUniChar SHAPE_HASHING = 0x04; // rabbit (hashing)
const wxUniChar SHAPE_SLOW = 0x05; // turtle (slow)
const wxUniChar SHAPE_NOTHASHING = 0x06; // cracked wine glass (not hashing)
const wxUniChar SHAPE_PAUSED = 0x08; // otter (paused)
const int SHAPE_ADVANCE = 15; // horizontal space one shape occupies
bool IsShapeSentinel(const wxString& s, wxUniChar& out) {
if (s.length() != 1) return false;
wxUniChar c = s[0];
if (c == SHAPE_DOT || c == SHAPE_LOCK || c == SHAPE_UNLOCK) {
if (c == SHAPE_DOT || c == SHAPE_LOCK || c == SHAPE_UNLOCK ||
c == SHAPE_HASHING || c == SHAPE_SLOW || c == SHAPE_NOTHASHING ||
c == SHAPE_PAUSED) {
out = c;
return true;
}
return false;
}
// Draw one shape sentinel, centred in the SHAPE_ADVANCE-wide slot at x.
void DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, const wxColour& colour) {
// Registry of SVG-backed shape icons (round 12 #9 access padlocks, #11 status
// icons). The Rust side registers a raw SVG (with its viewBox dims for aspect)
// per sentinel; DrawShape recolours it to the segment colour, rasterises once
// per (sentinel, colour, height), caches the bitmap, and draws it. The access
// padlocks (0x02/0x03) fall back to a hand-drawn vector when unregistered.
struct ShapeSvg {
wxString svg;
int vbw;
int vbh;
};
std::map<int, ShapeSvg> g_shape_svgs;
std::map<uint64_t, wxBitmap> g_shape_bmp_cache;
const ShapeSvg* LookupShapeSvg(wxUniChar shape) {
auto it = g_shape_svgs.find((int)shape.GetValue());
return it == g_shape_svgs.end() ? nullptr : &it->second;
}
// Recolour an SVG to `c`, matching the Rust svg_recolored(): replace
// fill="currentColor" and inject a root fill so shapes that omit a fill inherit
// the colour too (e.g. the Font Awesome Free otter).
wxString RecolorShapeSvg(const wxString& svg, const wxColour& c) {
wxString hex = wxString::Format("#%02X%02X%02X", (int)c.Red(), (int)c.Green(), (int)c.Blue());
wxString s = svg;
s.Replace("currentColor", hex);
int pos = s.Find("<svg ");
if (pos != wxNOT_FOUND) s.insert((size_t)pos + 5, wxString("fill=\"") + hex + "\" ");
return s;
}
const wxBitmap& ShapeBitmap(wxUniChar shape, const ShapeSvg& sv, const wxColour& col,
int w, int h) {
uint64_t rgb = ((uint64_t)col.Red() << 16) | ((uint64_t)col.Green() << 8) | (uint64_t)col.Blue();
uint64_t key = ((uint64_t)(unsigned)shape.GetValue() << 40) | (rgb << 8) | (uint64_t)(h & 0xFF);
auto it = g_shape_bmp_cache.find(key);
if (it != g_shape_bmp_cache.end()) return it->second;
wxString colored = RecolorShapeSvg(sv.svg, col);
wxBitmapBundle bundle = wxBitmapBundle::FromSVG(colored.ToUTF8().data(), wxSize(w, h));
wxBitmap bmp = bundle.GetBitmap(wxSize(w, h));
return g_shape_bmp_cache.emplace(key, bmp).first->second;
}
// Draw one shape sentinel centred at x; returns the horizontal space it used
// (SHAPE_ADVANCE for the vector shapes, the icon width for a wider SVG icon).
int DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, const wxColour& colour) {
int cy = cell.y + cell.height / 2;
// SVG-backed icon (access padlocks #9, status KPI icons #11): recolour to the
// segment colour, rasterise (cached), and draw centred in its slot.
if (const ShapeSvg* sv = LookupShapeSvg(shape)) {
int h = cell.height - 4;
if (h > 15) h = 15;
if (h < 8) h = 8;
int w = (sv->vbh > 0) ? (int)((double)h * sv->vbw / sv->vbh + 0.5) : h;
if (w < 1) w = 1;
const wxBitmap& bmp = ShapeBitmap(shape, *sv, colour, w, h);
if (bmp.IsOk()) {
int slot = (w > SHAPE_ADVANCE) ? w : SHAPE_ADVANCE;
dc->DrawBitmap(bmp, x + (slot - w) / 2, cy - h / 2, true);
return slot;
}
}
int cx = x + SHAPE_ADVANCE / 2;
if (shape == SHAPE_DOT) {
dc->SetPen(*wxTRANSPARENT_PEN);
dc->SetBrush(wxBrush(colour));
dc->DrawCircle(cx, cy, 4);
return;
return SHAPE_ADVANCE;
}
// Padlock: a filled body with a staple shackle above. The colour carries the
// state (green = unlocked, red = locked); the shackle is drawn ajar when open.
@@ -198,6 +266,7 @@ void DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, const w
dc->DrawLine(rx, legTop, rx, legTop + sr); // ajar: right leg lifted
else
dc->DrawLine(rx, legTop, rx, by); // closed: right leg to body
return SHAPE_ADVANCE;
}
} // namespace
@@ -272,8 +341,7 @@ class SegmentRenderer : public wxDataViewCustomRenderer {
// selection highlight (round 11 #10/#13).
wxUniChar shape;
if (IsShapeSentinel(seg.text, shape)) {
DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain);
x += SHAPE_ADVANCE;
x += DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain);
continue;
}
if (seg.text.IsEmpty()) continue;
@@ -291,7 +359,13 @@ class SegmentRenderer : public wxDataViewCustomRenderer {
for (const ColorSegment& seg : ParseColorSegments(m_value)) {
wxUniChar shape;
if (IsShapeSentinel(seg.text, shape)) {
w += SHAPE_ADVANCE;
int adv = SHAPE_ADVANCE;
if (const ShapeSvg* sv = LookupShapeSvg(shape)) {
int hh = 15;
int ww = (sv->vbh > 0) ? (int)((double)hh * sv->vbw / sv->vbh + 0.5) : hh;
if (ww > adv) adv = ww;
}
w += adv;
if (h < 12) h = 12;
continue;
}
@@ -1378,6 +1452,19 @@ void* wxbr_svg_icon(void* parent, const char* svg, int w, int h) {
return (void*)new wxStaticBitmap((wxWindow*)parent, wxID_ANY, bmp);
}
// Register a raw SVG (with its viewBox width/height for aspect) for a table-cell
// shape sentinel, so the SegmentRenderer can draw it recoloured to the cell's
// segment colour (round 12 #9 access padlocks, #11 status KPI icons). Replaces
// any prior registration for that sentinel and invalidates the bitmap cache.
void wxbr_register_shape_svg(int sentinel, const char* svg, int vbw, int vbh) {
ShapeSvg s;
s.svg = wxString::FromUTF8(svg);
s.vbw = vbw;
s.vbh = vbh;
g_shape_svgs[sentinel] = s;
g_shape_bmp_cache.clear();
}
// ---- live theme changes -----------------------------------------------------
// Emit WxEV_SYS_COLOUR when the OS light/dark theme changes so the app can
+12
View File
@@ -104,6 +104,7 @@ mod notsafe {
pub fn wxbr_choice_set_selection(win: *mut c_void, i: c_int);
pub fn wxbr_media_button(parent: *mut c_void, id: c_int, kind: c_int, r: c_int, g: c_int, b: c_int) -> *mut c_void;
pub fn wxbr_svg_icon(parent: *mut c_void, svg: *const c_char, w: c_int, h: c_int) -> *mut c_void;
pub fn wxbr_register_shape_svg(sentinel: c_int, svg: *const c_char, vbw: c_int, vbh: c_int);
pub fn wxbr_bind_sys_colour(win: *mut c_void);
pub fn wxbr_destroy(win: *mut c_void);
pub fn wxbr_destroy_children(win: *mut c_void);
@@ -200,6 +201,17 @@ pub fn status_indicator_set(text: &str, r: u8, g: u8, b: u8) {
unsafe { notsafe::wxbr_status_indicator_set(c.as_ptr(), r as c_int, g as c_int, b as c_int) }
}
/// Register a raw SVG for a table-cell shape sentinel (a control-char code point)
/// so the segment renderer can draw it recoloured to each cell's segment colour.
/// `vbw`/`vbh` are the SVG viewBox dimensions, used to keep the icon's aspect
/// ratio when it is rasterised at the cell height (round 12 #9/#11).
pub fn register_shape_svg(sentinel: u32, svg: &str, vbw: i32, vbh: i32) {
let c = CString::new(svg).unwrap_or_default();
unsafe {
notsafe::wxbr_register_shape_svg(sentinel as c_int, c.as_ptr(), vbw as c_int, vbh as c_int)
}
}
/// Open a URL in the system default browser. Returns true on success.
pub fn launch_browser(url: &str) -> bool {
let c = CString::new(url).unwrap_or_default();