notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

main.rs (3068B)


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