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