notedeck

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

lib.rs (4074B)


      1 mod app;
      2 //mod camera;
      3 mod error;
      4 //mod note;
      5 //mod block;
      6 mod abbrev;
      7 pub mod accounts;
      8 mod actionbar;
      9 pub mod app_creation;
     10 mod app_size_handler;
     11 mod app_style;
     12 mod args;
     13 mod colors;
     14 mod column;
     15 mod deck_state;
     16 mod decks;
     17 mod draft;
     18 mod filter;
     19 mod fonts;
     20 mod frame_history;
     21 mod images;
     22 mod imgcache;
     23 mod key_parsing;
     24 pub mod login_manager;
     25 mod multi_subscriber;
     26 mod muted;
     27 mod nav;
     28 mod note;
     29 mod notecache;
     30 mod notes_holder;
     31 mod post;
     32 mod profile;
     33 pub mod relay_pool_manager;
     34 mod result;
     35 mod route;
     36 mod subscriptions;
     37 mod support;
     38 mod test_data;
     39 mod thread;
     40 mod time;
     41 mod timecache;
     42 mod timeline;
     43 pub mod ui;
     44 mod unknowns;
     45 mod user_account;
     46 mod view_state;
     47 
     48 #[cfg(test)]
     49 #[macro_use]
     50 mod test_utils;
     51 
     52 pub mod storage;
     53 
     54 pub use app::Damus;
     55 pub use error::Error;
     56 pub use profile::DisplayName;
     57 
     58 #[cfg(target_os = "android")]
     59 use winit::platform::android::EventLoopBuilderExtAndroid;
     60 
     61 pub type Result<T> = std::result::Result<T, error::Error>;
     62 
     63 //#[cfg(target_os = "android")]
     64 //use egui_android::run_android;
     65 
     66 #[cfg(target_os = "android")]
     67 use winit::platform::android::activity::AndroidApp;
     68 
     69 #[cfg(target_os = "android")]
     70 #[no_mangle]
     71 #[tokio::main]
     72 pub async fn android_main(app: AndroidApp) {
     73     std::env::set_var("RUST_BACKTRACE", "full");
     74     android_logger::init_once(android_logger::Config::default().with_min_level(log::Level::Info));
     75 
     76     let path = app.internal_data_path().expect("data path");
     77     let mut options = eframe::NativeOptions::default();
     78     options.renderer = eframe::Renderer::Wgpu;
     79     // Clone `app` to use it both in the closure and later in the function
     80     let app_clone_for_event_loop = app.clone();
     81     options.event_loop_builder = Some(Box::new(move |builder| {
     82         builder.with_android_app(app_clone_for_event_loop);
     83     }));
     84 
     85     let app_args = get_app_args(app);
     86 
     87     let _res = eframe::run_native(
     88         "Damus Notedeck",
     89         options,
     90         Box::new(move |cc| Ok(Box::new(Damus::new(&cc.egui_ctx, path, app_args)))),
     91     );
     92 }
     93 
     94 #[cfg(target_os = "android")]
     95 use serde_json::Value;
     96 #[cfg(target_os = "android")]
     97 use std::fs;
     98 #[cfg(target_os = "android")]
     99 use std::path::PathBuf;
    100 
    101 /*
    102 Read args from a config file:
    103 - allows use of more interesting args w/o risk of checking them in by mistake
    104 - allows use of different args w/o rebuilding the app
    105 - uses compiled in defaults if config file missing or broken
    106 
    107 Example android-config.json:
    108 ```
    109 {
    110   "args": [
    111     "--npub",
    112     "npub1h50pnxqw9jg7dhr906fvy4mze2yzawf895jhnc3p7qmljdugm6gsrurqev",
    113     "-c",
    114     "contacts",
    115     "-c",
    116     "notifications"
    117   ]
    118 }
    119 ```
    120 
    121 Install/update android-config.json with:
    122 ```
    123 adb push android-config.json /sdcard/Android/data/com.damus.app/files/android-config.json
    124 ```
    125 
    126 Using internal storage would be better but it seems hard to get the config file onto
    127 the device ...
    128 */
    129 
    130 #[cfg(target_os = "android")]
    131 fn get_app_args(app: AndroidApp) -> Vec<String> {
    132     let external_data_path: PathBuf = app
    133         .external_data_path()
    134         .expect("external data path")
    135         .to_path_buf();
    136     let config_file = external_data_path.join("android-config.json");
    137 
    138     let default_args = vec![
    139         "--pub",
    140         "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245",
    141         "-c",
    142         "contacts",
    143         "-c",
    144         "notifications",
    145         "-c",
    146         "notifications:3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681",
    147     ]
    148     .into_iter()
    149     .map(|s| s.to_string())
    150     .collect();
    151 
    152     if config_file.exists() {
    153         if let Ok(config_contents) = fs::read_to_string(config_file) {
    154             if let Ok(json) = serde_json::from_str::<Value>(&config_contents) {
    155                 if let Some(args_array) = json.get("args").and_then(|v| v.as_array()) {
    156                     let config_args = args_array
    157                         .iter()
    158                         .filter_map(|v| v.as_str().map(String::from))
    159                         .collect();
    160 
    161                     return config_args;
    162                 }
    163             }
    164         }
    165     }
    166 
    167     default_args // Return the default args if config is missing or invalid
    168 }