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