//! 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=" "` 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=" "` 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() {}