notedeck

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

preview.rs (2812B)


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