Skip to content

Commit

Permalink
android: pass in internal data path for db
Browse files Browse the repository at this point in the history
Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
jb55 committed Feb 10, 2024
1 parent c377951 commit 3925012
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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"
Expand Down
41 changes: 18 additions & 23 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Check failure on line 22 in src/app.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused import: `PathBuf`
use std::time::Duration;
use tracing::{debug, error, info, warn};

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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`.

Expand All @@ -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(),
}
}
}

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/bin/notedeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "."))),
);
}

Expand All @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand All @@ -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))),
);
}

0 comments on commit 3925012

Please sign in to comment.