notedeck

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

commit 3925012ad9a187bf9eaa2f2dc5af156100ca1821
parent c3779510eccc5d0156b24a4c9278409be36cc83c
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 10 Feb 2024 13:57:46 -0800

android: pass in internal data path for db

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
MCargo.toml | 8++++++--
Msrc/app.rs | 41++++++++++++++++++-----------------------
Msrc/bin/notedeck.rs | 4++--
Msrc/lib.rs | 3++-
4 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -29,8 +29,8 @@ serde_json = "1.0.89" env_logger = "0.10.0" shatter = "0.1.1" puffin_egui = { version = "0.25.0", optional = true } -puffin = { version = "0.16.0", optional = true } -nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "496a70b3e28dc65be8b9aa6ece37eb5255224ea9" } +puffin = { version = "0.19.0", optional = true } +nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "e513b6ed516a9adf757c1f7ac26cd3d544c391b2" } [features] default = [] @@ -77,6 +77,10 @@ version = 1 name = "android.permission.WRITE_EXTERNAL_STORAGE" max_sdk_version = 18 +[[package.metadata.android.uses_permission]] +name = "android.permission.READ_EXTERNAL_STORAGE" +max_sdk_version = 18 + [package.metadata.android.signing.release] path = "damus.keystore" keystore_password = "damuskeystore" diff --git a/src/app.rs b/src/app.rs @@ -19,6 +19,7 @@ use poll_promise::Promise; use std::cmp::Ordering; use std::collections::{HashMap, HashSet}; use std::hash::{Hash, Hasher}; +use std::path::{Path, PathBuf}; use std::time::Duration; use tracing::{debug, error, info, warn}; @@ -99,25 +100,6 @@ pub struct Damus { frame_history: crate::frame_history::FrameHistory, } -impl Default for Damus { - fn default() -> Self { - let mut config = Config::new(); - config.set_ingester_threads(2); - Self { - state: DamusState::Initializing, - contacts: Contacts::new(), - pool: RelayPool::new(), - home_sub: None, - img_cache: HashMap::new(), - n_panels: 1, - timelines: vec![Timeline::new()], - ndb: Ndb::new(".", &config).expect("ndb"), - compose: "".to_string(), - frame_history: FrameHistory::default(), - } - } -} - pub fn is_mobile(ctx: &egui::Context) -> bool { //true let screen_size = ctx.screen_rect().size(); @@ -351,7 +333,7 @@ fn render_damus(damus: &mut Damus, ctx: &Context) { impl Damus { /// Called once before the first frame. - pub fn new(cc: &eframe::CreationContext<'_>) -> Self { + pub fn new<P: AsRef<Path>>(cc: &eframe::CreationContext<'_>, data_path: P) -> Self { // This is also where you can customized the look at feel of egui using // `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`. @@ -363,9 +345,22 @@ impl Damus { // cc.egui_ctx - .set_pixels_per_point(cc.egui_ctx.pixels_per_point() + 0.4); + .set_pixels_per_point(cc.egui_ctx.pixels_per_point() + 0.2); - Default::default() + let mut config = Config::new(); + config.set_ingester_threads(2); + Self { + state: DamusState::Initializing, + contacts: Contacts::new(), + pool: RelayPool::new(), + home_sub: None, + img_cache: HashMap::new(), + n_panels: 1, + timelines: vec![Timeline::new()], + ndb: Ndb::new(data_path.as_ref().to_str().expect("db path ok"), &config).expect("ndb"), + compose: "".to_string(), + frame_history: FrameHistory::default(), + } } } @@ -577,7 +572,7 @@ fn top_panel(ctx: &egui::Context) -> egui::TopBottomPanel { // mobile needs padding, at least on android if is_mobile(ctx) { let mut top_margin = Margin::default(); - top_margin.top = 50.0; + top_margin.top = 20.0; let frame = Frame { inner_margin: top_margin, diff --git a/src/bin/notedeck.rs b/src/bin/notedeck.rs @@ -18,7 +18,7 @@ async fn main() { let _res = eframe::run_native( "Damus NoteDeck", native_options, - Box::new(|cc| Box::new(Damus::new(cc))), + Box::new(|cc| Box::new(Damus::new(cc, "."))), ); } @@ -35,7 +35,7 @@ pub fn main() { eframe::start_web( "the_canvas_id", // hardcode it web_options, - Box::new(|cc| Box::new(Damus::new(cc))), + Box::new(|cc| Box::new(Damus::new(cc, "."))), ) .await .expect("failed to start eframe"); diff --git a/src/lib.rs b/src/lib.rs @@ -34,6 +34,7 @@ pub async fn android_main(app: AndroidApp) { std::env::set_var("RUST_BACKTRACE", "full"); android_logger::init_once(android_logger::Config::default().with_min_level(log::Level::Info)); + let path = app.internal_data_path().expect("data path"); let mut options = eframe::NativeOptions::default(); options.renderer = eframe::Renderer::Wgpu; options.event_loop_builder = Some(Box::new(move |builder| { @@ -43,6 +44,6 @@ pub async fn android_main(app: AndroidApp) { let res_ = eframe::run_native( "Damus NoteDeck", options, - Box::new(|cc| Box::new(Damus::new(cc))), + Box::new(|cc| Box::new(Damus::new(cc, path))), ); }