GUI round 2: selection, scan loop, column management, dark-mode fix

- Fixed "Scan ranges" button label (no longer grows with the range list).
- Dark-mode KPI cards: derive colours from the live system theme luminance
  instead of is_dark(), which mis-detected some GTK dark themes.
- Removed the checkbox column; the table is multi-select (wxDV_MULTIPLE,
  ctrl/shift-click), with the selection tracked by IP so it survives refreshes.
- Replaced Rescan with Play / Pause / Stop; added an editable auto-rescan
  interval (scan-ranges dialog; ~/.config/alkane-toolkit/auto-rescan-secs.txt)
  with a timer-driven countdown scheduler.
- Status bar shows the last-probed IP during a scan and a countdown to the next
  scan when idle (dropped the "scan complete" text).
- Default sort is IP-ascending with a header chevron; IP is column 0, sortable.
- Choose-columns dialog is a wxRearrangeCtrl (check to show; up/down or drag to
  reorder) exposing every metric, including Pool 1/2/3 URL + worker.
- Column drag-reorder moves the whole column with its data on drop.
- Row separator lines (wxDV_ROW_LINES). GTK3 native has no zebra striping; a
  GTK4-forward zebra-CSS hook and pkg-config gtk cflags are in place.

Scan engine: parse each configured pool's (url, worker); Progress carries the
last-probed IP. Model: Column::Sel removed; Pool1/2/3 columns; default IP sort.

wx-rs bridge: multi-select + selection/context-menu events + get_selections,
alternating-row + zebra-CSS hooks, in-place column title, rearrangeable list,
and popup-menu primitives (for the upcoming right-click config menu). Patches
0001-0003 regenerated and round-trip validated.

Review fixes: scan loop no longer sticks "scanning" if a thread ends without
Done (channel-disconnect handling + Stop force-reset); Play no longer starts a
second scan; stale selections pruned on rescan; column apply order/visibility
applied atomically.

Verified: 22 unit tests, a 14-check headless UI self-test, and interaction
checks (multi-select, column rearrange/drag, play/pause/stop, dark mode).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
This commit is contained in:
2026-09-16 17:27:20 -06:00
co-authored by Claude Opus 4.8
parent d1ab6aa72a
commit bd17a33ea1
11 changed files with 821 additions and 206 deletions
+66 -42
View File
@@ -92,9 +92,11 @@ pub struct MinerRow {
pub expected_chips: Option<u32>,
pub hashboards: Option<u32>,
pub expected_hashboards: Option<u32>,
// pool
// pool: active-pool convenience fields, plus the (url, worker) of each
// configured pool (miners usually allow up to 3 redundant pools).
pub worker: String,
pub pool_url: String,
pub pools: Vec<(String, String)>,
// shares
pub best_share: Option<f64>,
pub session_best_share: Option<f64>,
@@ -130,11 +132,11 @@ impl MinerRow {
}
}
/// Model columns. Sel and Ip are fixed (checkbox + always-on IP column); the
/// rest map 1:1 to a scannable metric and can be shown/hidden/reordered.
/// Model columns. Ip is fixed (always shown first); the rest map 1:1 to a
/// scannable metric and can be shown/hidden/reordered. Row selection replaces
/// the old checkbox column.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Column {
Sel,
Ip,
Hashrate,
Power,
@@ -167,12 +169,17 @@ pub enum Column {
SessionBestShare,
TuningPercent,
PoolUrl,
Pool1Url,
Pool1Worker,
Pool2Url,
Pool2Worker,
Pool3Url,
Pool3Worker,
}
/// Every column, in registry order. Sel + Ip first, then the default-visible
/// set (UI-SPEC order), then all remaining metrics.
pub const ALL_COLUMNS: [Column; 33] = [
Column::Sel,
/// Every column, in registry order. Ip first, then the default-visible set
/// (UI-SPEC order), then all remaining metrics.
pub const ALL_COLUMNS: [Column; 38] = [
Column::Ip,
Column::Hashrate,
Column::Power,
@@ -205,9 +212,15 @@ pub const ALL_COLUMNS: [Column; 33] = [
Column::SessionBestShare,
Column::TuningPercent,
Column::PoolUrl,
Column::Pool1Url,
Column::Pool1Worker,
Column::Pool2Url,
Column::Pool2Worker,
Column::Pool3Url,
Column::Pool3Worker,
];
/// The columns shown by default (UI-SPEC), after Sel + Ip.
/// The columns shown by default (UI-SPEC), after the fixed IP column.
pub const DEFAULT_VISIBLE: [Column; 8] = [
Column::Hashrate,
Column::Power,
@@ -222,7 +235,6 @@ pub const DEFAULT_VISIBLE: [Column; 8] = [
impl Column {
pub fn title(self) -> &'static str {
match self {
Column::Sel => "",
Column::Ip => "IP",
Column::Hashrate => "Hashrate",
Column::Power => "Power",
@@ -255,12 +267,17 @@ impl Column {
Column::SessionBestShare => "Session best",
Column::TuningPercent => "Tuning %",
Column::PoolUrl => "Pool URL",
Column::Pool1Url => "Pool 1 URL",
Column::Pool1Worker => "Pool 1 worker",
Column::Pool2Url => "Pool 2 URL",
Column::Pool2Worker => "Pool 2 worker",
Column::Pool3Url => "Pool 3 URL",
Column::Pool3Worker => "Pool 3 worker",
}
}
pub fn width(self) -> i32 {
match self {
Column::Sel => 28,
Column::Ip => 130,
Column::Hashrate | Column::ExpectedHashrate => 110,
Column::Power => 90,
@@ -282,7 +299,8 @@ impl Column {
Column::Uptime => 100,
Column::OperatingState => 100,
Column::BestShare | Column::SessionBestShare => 110,
Column::PoolUrl => 220,
Column::PoolUrl | Column::Pool1Url | Column::Pool2Url | Column::Pool3Url => 200,
Column::Pool1Worker | Column::Pool2Worker | Column::Pool3Worker => 150,
}
}
@@ -320,7 +338,6 @@ impl Column {
pub fn sort_key(&self, r: &MinerRow) -> SortKey {
let none = f64::NEG_INFINITY;
match self {
Column::Sel => SortKey::Num(if r.selected { 1.0 } else { 0.0 }),
Column::Hashrate => SortKey::Num(r.hashrate_ths),
Column::ExpectedHashrate => SortKey::Num(r.expected_ths),
Column::Power => SortKey::Num(r.power_w),
@@ -360,8 +377,9 @@ impl Column {
}
};
let count = |v: Option<u32>| -> String { v.map(|n| n.to_string()).unwrap_or_default() };
let pool_url = |i: usize| r.pools.get(i).map(|(u, _)| u.clone()).unwrap_or_default();
let pool_worker = |i: usize| r.pools.get(i).map(|(_, w)| w.clone()).unwrap_or_default();
match self {
Column::Sel => String::new(),
Column::Ip => r.ip.clone(),
Column::Hashrate => {
if r.hashrate_ths > 0.0 {
@@ -418,6 +436,12 @@ impl Column {
r.session_best_share.map(|v| format_si(v, "")).unwrap_or_default()
}
Column::TuningPercent => r.tuning_percent.map(|v| format!("{v}%")).unwrap_or_default(),
Column::Pool1Url => pool_url(0),
Column::Pool1Worker => pool_worker(0),
Column::Pool2Url => pool_url(1),
Column::Pool2Worker => pool_worker(1),
Column::Pool3Url => pool_url(2),
Column::Pool3Worker => pool_worker(2),
}
}
}
@@ -429,7 +453,7 @@ pub enum SortKey {
/// Display state: order, visibility, sort, filter.
pub struct ViewState {
/// Model column order as displayed (Sel is always display position 0).
/// Model column order as displayed (Ip is always the first visible column).
pub order: Vec<Column>,
pub visible: HashSet<Column>,
pub sort: Option<(Column, bool)>, // (column, ascending)
@@ -439,36 +463,37 @@ pub struct ViewState {
impl Default for ViewState {
fn default() -> Self {
// Registry order for `order`; only Sel + Ip + DEFAULT_VISIBLE are shown.
// Registry order for `order`; Ip + DEFAULT_VISIBLE are shown. Default
// sort is by IP ascending.
let order: Vec<Column> = ALL_COLUMNS.to_vec();
let mut visible: HashSet<Column> = DEFAULT_VISIBLE.iter().copied().collect();
visible.insert(Column::Sel);
visible.insert(Column::Ip);
ViewState { order, visible, sort: None, filters: HashMap::new() }
ViewState { order, visible, sort: Some((Column::Ip, true)), filters: HashMap::new() }
}
}
impl ViewState {
pub fn display_columns(&self) -> Vec<Column> {
// Ip is always shown first; the rest follow `order` filtered by visibility.
self.order
.iter()
.copied()
.filter(|c| *c == Column::Sel || self.visible.contains(c))
.filter(|c| *c == Column::Ip || self.visible.contains(c))
.collect()
}
pub fn is_fixed(&self, c: Column) -> bool {
c == Column::Sel || c == Column::Ip
c == Column::Ip
}
/// Apply a drag-reorder of the visible columns. `new_visible` is the visible
/// columns in their new display order; it must be a permutation of the
/// currently-visible set with Sel still first. The new order is spliced back
/// currently-visible set with Ip still first. The new order is spliced back
/// into `order`, leaving hidden columns in their existing slots, so a
/// reorder while some column is hidden never drops or duplicates a column.
pub fn apply_visible_reorder(&mut self, new_visible: &[Column]) {
let disp = self.display_columns();
if new_visible.len() != disp.len() || new_visible.first() != Some(&Column::Sel) {
if new_visible.len() != disp.len() || new_visible.first() != Some(&Column::Ip) {
return;
}
let want: HashSet<Column> = disp.iter().copied().collect();
@@ -486,12 +511,9 @@ impl ViewState {
/// Rows that pass every active filter (AND across columns, OR within one).
pub fn passes_filters(&self, r: &MinerRow) -> bool {
self.filters.iter().all(|(col, allowed)| {
if *col == Column::Sel {
return true;
}
allowed.contains(&col.cell(r))
})
self.filters
.iter()
.all(|(col, allowed)| allowed.contains(&col.cell(r)))
}
/// Filtered + sorted rows in display order.
@@ -605,11 +627,14 @@ mod tests {
}
#[test]
fn default_view_is_insertion_order() {
fn default_view_sorts_by_ip_ascending() {
let (rows, _v, idx) = full_view();
let ips: Vec<&str> = idx.iter().map(|&i| rows[i].ip.as_str()).collect();
assert_eq!(ips[0], "10.255.1.112");
let ips: Vec<String> = idx.iter().map(|&i| rows[i].ip.clone()).collect();
assert_eq!(ips.len(), 9);
let mut sorted = ips.clone();
sorted.sort();
assert_eq!(ips, sorted, "default view should be IP-ascending");
assert_eq!(ips[0], "10.255.1.112");
}
#[test]
@@ -641,13 +666,12 @@ mod tests {
fn default_visible_is_the_ui_spec_set() {
let view = ViewState::default();
let disp = view.display_columns();
// Sel, Ip, then the 8 default columns in order.
assert_eq!(disp[0], Column::Sel);
assert_eq!(disp[1], Column::Ip);
assert_eq!(&disp[2..], &DEFAULT_VISIBLE[..]);
// Ip first, then the 8 default columns in order.
assert_eq!(disp[0], Column::Ip);
assert_eq!(&disp[1..], &DEFAULT_VISIBLE[..]);
// hidden-by-default metrics are still selectable (present in order).
assert!(view.order.contains(&Column::Mac));
assert!(view.order.contains(&Column::Uptime));
assert!(view.order.contains(&Column::Pool2Url));
assert!(!view.visible.contains(&Column::Mac));
}
@@ -659,8 +683,7 @@ mod tests {
view.visible.remove(&Column::Power);
let after = view.display_columns();
assert!(!after.contains(&Column::Power));
assert_eq!(after[0], Column::Sel);
assert_eq!(after[1], Column::Ip);
assert_eq!(after[0], Column::Ip);
assert_eq!(after.len(), before.len() - 1);
let hr = after.iter().position(|c| *c == Column::Hashrate).unwrap();
assert_eq!(after[hr + 1], Column::ChipTemp);
@@ -678,8 +701,9 @@ mod tests {
fn reorder_with_hidden_column_keeps_all_columns() {
let mut view = ViewState::default();
view.visible.remove(&Column::Power);
// display now: Ip(0), Hashrate(1), ChipTemp(2), ... - swap Hashrate/ChipTemp
let mut vis = view.display_columns();
vis.swap(2, 3); // swap Hashrate and ChipTemp
vis.swap(1, 2);
view.apply_visible_reorder(&vis);
assert!(view.order.contains(&Column::Power), "hidden column dropped!");
assert_eq!(view.order.len(), ALL_COLUMNS.len());
@@ -689,15 +713,15 @@ mod tests {
let hr = disp.iter().position(|c| *c == Column::Hashrate).unwrap();
let ct = disp.iter().position(|c| *c == Column::ChipTemp).unwrap();
assert!(ct < hr, "reorder not applied");
assert_eq!(view.order[0], Column::Sel);
assert_eq!(view.order[1], Column::Ip);
assert_eq!(view.order[0], Column::Ip);
}
#[test]
fn reorder_rejects_non_permutation() {
let mut view = ViewState::default();
let before = view.order.clone();
view.apply_visible_reorder(&[Column::Ip, Column::Sel, Column::Hashrate]);
// Ip not first -> ignored
view.apply_visible_reorder(&[Column::Hashrate, Column::Ip, Column::Power]);
assert_eq!(view.order, before);
}