verify / verify (pull_request) Skipped
source / check (pull_request) Successful in 7m17s
The fleet scan (asic-rs) recognises miners by their cgminer socket or vendor web UI. A board running Alkane OS exposes neither, so it never appeared and could not be right-clicked; the periodic refresh also marked it offline. - alkane_detect: probe addresses asic-rs does not identify over HTTP: GET /api/identity (alkane-os 0.1.2+: os, version, board, MAC, hostname), falling back to /api/summary's "alkane-os" STATUS for older images. Used by the scan and the refresh. Rows show Firmware "Alkane" with the version, MAC, hostname and control board (XIL (C49) for zynq-7010). - Context menu: "Install alkane OS..." only for a supported board (control board alkane-os has an image for; a stock Antminer on XIL (C49), or by model S17/S17 Pro/T17 when the stock miner software is down and reports no board) that is not running Alkane; "Update alkane OS..." for a supported board already running it (same dialog, updated in place); "Uninstall alkane OS" only for boards running Alkane. Mixed selections get neither install nor update. - Docs updated. Verified live on the bench S17: running Alkane -> found as Alkane 0.1.2, XIL (C49), update + uninstall offered; restored to stock -> found as Antminer S17 Stock, install offered. Unit tests for the probe parsing and the menu rules; an ignored live scan test (ALKANE_TEST_SCAN_RANGE). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B1W6qKwKxq3oUPDKWicM6i
157 lines
5.7 KiB
Rust
157 lines
5.7 KiB
Rust
//! alkane-toolkit: primary view (docs/UI-SPEC.md).
|
|
//! Pure-Rust wxWidgets app on the vendored, patched wx-rs.
|
|
|
|
// A GUI application on Windows: no console window opens behind it. The
|
|
// headless modes below re-attach to the console they were started from.
|
|
#![cfg_attr(windows, windows_subsystem = "windows")]
|
|
|
|
mod access_probe;
|
|
mod alkane_detect;
|
|
mod askpass;
|
|
mod bug_report;
|
|
mod credentials;
|
|
mod export;
|
|
mod fixtures;
|
|
mod i18n;
|
|
mod log_scan;
|
|
mod logs;
|
|
mod model;
|
|
mod naming;
|
|
mod pool_prefs;
|
|
mod presets;
|
|
mod restore;
|
|
mod scan;
|
|
mod stock_ops;
|
|
mod ui;
|
|
|
|
fn main() {
|
|
// ssh runs this executable as its askpass helper for password logins
|
|
// (askpass.rs); answer and exit before anything else starts.
|
|
if let Some(code) = askpass::serve_if_askpass() {
|
|
std::process::exit(code);
|
|
}
|
|
if headless_mode() {
|
|
attach_parent_console();
|
|
}
|
|
|
|
// Headless workflow self-test: render the bench-fleet fixtures through the
|
|
// real widgets and check the table + KPIs against the expected hardware
|
|
// output. Run under a virtual display (see scripts/ui-selftest.sh).
|
|
if std::env::var_os("ALKANE_SELFTEST").is_some() {
|
|
std::process::exit(run_selftest());
|
|
}
|
|
|
|
// Headless access-probe check: `ALKANE_ACCESS_PROBE="<ip> <make>"` prints the
|
|
// lock state the real access probe computes (no GUI, no wx), so the WhatsMiner
|
|
// :4028 token check and the Antminer digest check can be verified directly.
|
|
if let Some(spec) = std::env::var_os("ALKANE_ACCESS_PROBE") {
|
|
let spec = spec.to_string_lossy();
|
|
let mut it = spec.split_whitespace();
|
|
let ip = it.next().unwrap_or("");
|
|
let make = it.next().unwrap_or("");
|
|
let (user, pass) = credentials::load_credentials().unwrap_or_default();
|
|
match access_probe::probe_access(ip, make, &user, &pass) {
|
|
Ok(Some(true)) => println!("ACCESS {ip} {make}: LOCKED"),
|
|
Ok(Some(false)) => println!("ACCESS {ip} {make}: UNLOCKED"),
|
|
Ok(None) => println!("ACCESS {ip} {make}: INDETERMINATE"),
|
|
Err(e) => println!("ACCESS {ip} {make}: ERROR {e}"),
|
|
}
|
|
std::process::exit(0);
|
|
}
|
|
|
|
// Headless log-scan check: `ALKANE_LOG_SCAN="<ip> <brand>"` fetches the miner's
|
|
// log through asic-rs's per-backend read_logs() (round 19 #11-16), so the log
|
|
// paths can be verified without the GUI. WhatsMiner falls back to fault codes.
|
|
if let Some(spec) = std::env::var_os("ALKANE_LOG_SCAN") {
|
|
let spec = spec.to_string_lossy();
|
|
let mut it = spec.split_whitespace();
|
|
let ip = it.next().unwrap_or("");
|
|
let brand = it.next().unwrap_or("");
|
|
match log_scan::scan_log(ip, brand, scan::load_scan_timeout()) {
|
|
Ok(s) => println!("LOGSCAN {ip} ({brand}): {} log bytes", s.text.len()),
|
|
Err(e) => println!("LOGSCAN {ip} ({brand}): ERROR {e}"),
|
|
}
|
|
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). This also picks the
|
|
// light/dark appearance (system, or ALKANE_APPEARANCE=light|dark) before the
|
|
// frame exists, which wxMSW requires.
|
|
wx_rs::init_app("alkane-toolkit", 1280, 800);
|
|
|
|
// Build the UI-SPEC primary view into the frame.
|
|
let frame = wx_rs::Widget::main_frame();
|
|
let app = ui::build(frame);
|
|
ui::install(app);
|
|
|
|
// All widget events funnel through one dispatcher.
|
|
wx_rs::set_event_handler(ui::dispatch);
|
|
|
|
// Enter the wx event loop; the scan thread streams rows via channel and
|
|
// a 1 s timer drains it on the main thread.
|
|
wx_rs::run_app();
|
|
}
|
|
|
|
fn run_selftest() -> i32 {
|
|
// Force offline: never touch the network during the self-test.
|
|
std::env::set_var(scan::FAKE_SCAN_ENV, "1");
|
|
wx_rs::init_app("alkane-toolkit", 1280, 800);
|
|
let frame = wx_rs::Widget::main_frame();
|
|
let mut app = ui::build(frame);
|
|
let ok = app.run_fixture_selftest();
|
|
// ALKANE_SNAPSHOT=path (macOS): also write a PNG of the window as the app
|
|
// draws it, to check rendering without screen-recording permission.
|
|
if let Some(path) = std::env::var_os("ALKANE_SNAPSHOT") {
|
|
let path = path.to_string_lossy();
|
|
let wrote = wx_rs::snapshot_png(&frame, &path);
|
|
println!(
|
|
"SNAPSHOT {} {}",
|
|
if wrote { "wrote" } else { "unavailable" },
|
|
path
|
|
);
|
|
}
|
|
println!("SELFTEST {}", if ok { "PASS" } else { "FAIL" });
|
|
if ok {
|
|
0
|
|
} else {
|
|
1
|
|
}
|
|
}
|
|
|
|
/// True when the process runs one of the headless check modes instead of the GUI.
|
|
fn headless_mode() -> bool {
|
|
["ALKANE_SELFTEST", "ALKANE_ACCESS_PROBE", "ALKANE_LOG_SCAN"]
|
|
.iter()
|
|
.any(|v| std::env::var_os(v).is_some())
|
|
}
|
|
|
|
/// A Windows GUI-subsystem process has no console, so output from the headless
|
|
/// modes would vanish when they are run from a terminal. Attach to the parent's
|
|
/// console in that case. Redirected output (pipes, files, CI) already has valid
|
|
/// standard handles and is left alone.
|
|
#[cfg(windows)]
|
|
fn attach_parent_console() {
|
|
type Handle = *mut core::ffi::c_void;
|
|
const STD_OUTPUT_HANDLE: u32 = -11i32 as u32;
|
|
const ATTACH_PARENT_PROCESS: u32 = u32::MAX;
|
|
#[link(name = "kernel32")]
|
|
extern "system" {
|
|
fn GetStdHandle(which: u32) -> Handle;
|
|
fn AttachConsole(process_id: u32) -> i32;
|
|
}
|
|
// SAFETY: plain Win32 calls with constant arguments; failure (no parent
|
|
// console, already attached) is harmless and leaves the process unchanged.
|
|
unsafe {
|
|
let out = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
if out.is_null() || out as isize == -1 {
|
|
AttachConsole(ATTACH_PARENT_PROCESS);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(not(windows))]
|
|
fn attach_parent_console() {}
|