main.rs (2933B)
1 use notedeck::ui::{ 2 account_login_view::AccountLoginView, account_management::AccountsView, 3 add_column::AddColumnView, DesktopSidePanel, PostView, Preview, PreviewApp, PreviewConfig, 4 ProfilePic, ProfilePreview, RelayView, 5 }; 6 use notedeck::{ 7 app_creation::{generate_mobile_emulator_native_options, generate_native_options, setup_cc}, 8 storage::DataPath, 9 }; 10 use std::env; 11 12 struct PreviewRunner { 13 force_mobile: bool, 14 light_mode: bool, 15 } 16 17 impl PreviewRunner { 18 fn new(force_mobile: bool, light_mode: bool) -> Self { 19 PreviewRunner { 20 force_mobile, 21 light_mode, 22 } 23 } 24 25 async fn run<P>(self, preview: P) 26 where 27 P: Into<PreviewApp> + 'static, 28 { 29 tracing_subscriber::fmt::init(); 30 31 let native_options = if self.force_mobile { 32 generate_mobile_emulator_native_options() 33 } else { 34 // TODO: tmp preview pathbuf? 35 generate_native_options(DataPath::new("previews")) 36 }; 37 38 let is_mobile = self.force_mobile; 39 let light_mode = self.light_mode; 40 41 let _ = eframe::run_native( 42 "UI Preview Runner", 43 native_options, 44 Box::new(move |cc| { 45 let app = Into::<PreviewApp>::into(preview); 46 setup_cc(&cc.egui_ctx, is_mobile, light_mode); 47 Ok(Box::new(app)) 48 }), 49 ); 50 } 51 } 52 53 macro_rules! previews { 54 // Accept a runner and name variable, followed by one or more identifiers for the views 55 ($runner:expr, $name:expr, $is_mobile:expr, $($view:ident),* $(,)?) => { 56 match $name.as_ref() { 57 $( 58 stringify!($view) => { 59 $runner.run($view::preview(PreviewConfig { is_mobile: $is_mobile })).await; 60 } 61 )* 62 _ => println!("Component not found."), 63 } 64 }; 65 } 66 67 #[tokio::main] 68 async fn main() { 69 let mut name: Option<String> = None; 70 let mut is_mobile: Option<bool> = None; 71 let mut light_mode: bool = false; 72 73 for arg in env::args() { 74 if arg == "--mobile" { 75 is_mobile = Some(true); 76 } else if arg == "--light" { 77 light_mode = true; 78 } else { 79 name = Some(arg); 80 } 81 } 82 83 let name = if let Some(name) = name { 84 name 85 } else { 86 println!("Please specify a component to test"); 87 return; 88 }; 89 90 println!( 91 "light mode previews: {}", 92 if light_mode { "enabled" } else { "disabled" } 93 ); 94 let is_mobile = is_mobile.unwrap_or(notedeck::ui::is_compiled_as_mobile()); 95 let runner = PreviewRunner::new(is_mobile, light_mode); 96 97 previews!( 98 runner, 99 name, 100 is_mobile, 101 RelayView, 102 AccountLoginView, 103 ProfilePreview, 104 ProfilePic, 105 AccountsView, 106 DesktopSidePanel, 107 PostView, 108 AddColumnView, 109 ); 110 }