main.rs (2287B)
1 //! patina-updater: Sector F Linux's updater (ADR-0016). Shows what the system is running, checks a 2 //! registry for a newer build of it, stages the update, and switches the system to another 3 //! registry. Built on egui and Patina. 4 5 mod app; 6 mod backend; 7 mod system; 8 9 use std::sync::Arc; 10 11 use backend::{Backend, Mock}; 12 13 const USAGE: &str = "usage: patina-updater 14 15 For trying the screens without root or a registry, on a fake system and a fake update: 16 PATINA_UPDATER_MOCK=1 (=fail makes the update fail part way) 17 PATINA_UPDATER_DEMO=... available, working, done, failed, switch, unreachable 18 PATINA_UPDATER_SCREENSHOT=file.png saves the window to a file and quits 19 PATINA_SKIN=name another skin"; 20 21 fn main() -> eframe::Result { 22 match std::env::args().nth(1).as_deref() { 23 None => {} 24 Some("-h" | "--help") => { 25 println!("{USAGE}"); 26 return Ok(()); 27 } 28 Some("-V" | "--version") => { 29 println!("patina-updater {}", env!("CARGO_PKG_VERSION")); 30 return Ok(()); 31 } 32 Some(_) => { 33 eprintln!("{USAGE}"); 34 std::process::exit(2); 35 } 36 } 37 38 let backend: Arc<dyn Backend> = match std::env::var("PATINA_UPDATER_MOCK").as_deref() { 39 Ok("fail") => Arc::new(Mock { fail: true }), 40 Ok(_) => Arc::new(Mock { fail: false }), 41 Err(_) => Arc::new(system::System), 42 }; 43 44 let options = eframe::NativeOptions { 45 viewport: patina::frame::viewport( 46 egui::ViewportBuilder::default() 47 .with_title("Software Update") 48 .with_app_id("com.sectorflabs.Updater") 49 .with_inner_size([720.0, 640.0]) 50 .with_min_inner_size([520.0, 420.0]), 51 true, 52 ), 53 ..Default::default() 54 }; 55 eframe::run_native( 56 "patina-updater", 57 options, 58 Box::new(move |cc| { 59 let mut app = app::App::new(cc, backend); 60 if let Ok(what) = std::env::var("PATINA_UPDATER_DEMO") { 61 app.demo(&what); 62 } 63 if let Ok(path) = std::env::var("PATINA_UPDATER_SCREENSHOT") { 64 app.screenshot_to(path.into()); 65 } 66 Ok(Box::new(app)) 67 }), 68 ) 69 }