android: pass in internal data path for db
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -29,8 +29,8 @@ serde_json = "1.0.89"
|
|||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
shatter = "0.1.1"
|
shatter = "0.1.1"
|
||||||
puffin_egui = { version = "0.25.0", optional = true }
|
puffin_egui = { version = "0.25.0", optional = true }
|
||||||
puffin = { version = "0.16.0", optional = true }
|
puffin = { version = "0.19.0", optional = true }
|
||||||
nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "496a70b3e28dc65be8b9aa6ece37eb5255224ea9" }
|
nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "e513b6ed516a9adf757c1f7ac26cd3d544c391b2" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
@@ -77,6 +77,10 @@ version = 1
|
|||||||
name = "android.permission.WRITE_EXTERNAL_STORAGE"
|
name = "android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
max_sdk_version = 18
|
max_sdk_version = 18
|
||||||
|
|
||||||
|
[[package.metadata.android.uses_permission]]
|
||||||
|
name = "android.permission.READ_EXTERNAL_STORAGE"
|
||||||
|
max_sdk_version = 18
|
||||||
|
|
||||||
[package.metadata.android.signing.release]
|
[package.metadata.android.signing.release]
|
||||||
path = "damus.keystore"
|
path = "damus.keystore"
|
||||||
keystore_password = "damuskeystore"
|
keystore_password = "damuskeystore"
|
||||||
|
|||||||
41
src/app.rs
41
src/app.rs
@@ -19,6 +19,7 @@ use poll_promise::Promise;
|
|||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tracing::{debug, error, info, warn};
|
use tracing::{debug, error, info, warn};
|
||||||
|
|
||||||
@@ -99,25 +100,6 @@ pub struct Damus {
|
|||||||
frame_history: crate::frame_history::FrameHistory,
|
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 {
|
pub fn is_mobile(ctx: &egui::Context) -> bool {
|
||||||
//true
|
//true
|
||||||
let screen_size = ctx.screen_rect().size();
|
let screen_size = ctx.screen_rect().size();
|
||||||
@@ -351,7 +333,7 @@ fn render_damus(damus: &mut Damus, ctx: &Context) {
|
|||||||
|
|
||||||
impl Damus {
|
impl Damus {
|
||||||
/// Called once before the first frame.
|
/// 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
|
// 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`.
|
// `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`.
|
||||||
|
|
||||||
@@ -363,9 +345,22 @@ impl Damus {
|
|||||||
//
|
//
|
||||||
|
|
||||||
cc.egui_ctx
|
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
|
// mobile needs padding, at least on android
|
||||||
if is_mobile(ctx) {
|
if is_mobile(ctx) {
|
||||||
let mut top_margin = Margin::default();
|
let mut top_margin = Margin::default();
|
||||||
top_margin.top = 50.0;
|
top_margin.top = 20.0;
|
||||||
|
|
||||||
let frame = Frame {
|
let frame = Frame {
|
||||||
inner_margin: top_margin,
|
inner_margin: top_margin,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ async fn main() {
|
|||||||
let _res = eframe::run_native(
|
let _res = eframe::run_native(
|
||||||
"Damus NoteDeck",
|
"Damus NoteDeck",
|
||||||
native_options,
|
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(
|
eframe::start_web(
|
||||||
"the_canvas_id", // hardcode it
|
"the_canvas_id", // hardcode it
|
||||||
web_options,
|
web_options,
|
||||||
Box::new(|cc| Box::new(Damus::new(cc))),
|
Box::new(|cc| Box::new(Damus::new(cc, "."))),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("failed to start eframe");
|
.expect("failed to start eframe");
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ pub async fn android_main(app: AndroidApp) {
|
|||||||
std::env::set_var("RUST_BACKTRACE", "full");
|
std::env::set_var("RUST_BACKTRACE", "full");
|
||||||
android_logger::init_once(android_logger::Config::default().with_min_level(log::Level::Info));
|
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();
|
let mut options = eframe::NativeOptions::default();
|
||||||
options.renderer = eframe::Renderer::Wgpu;
|
options.renderer = eframe::Renderer::Wgpu;
|
||||||
options.event_loop_builder = Some(Box::new(move |builder| {
|
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(
|
let res_ = eframe::run_native(
|
||||||
"Damus NoteDeck",
|
"Damus NoteDeck",
|
||||||
options,
|
options,
|
||||||
Box::new(|cc| Box::new(Damus::new(cc))),
|
Box::new(|cc| Box::new(Damus::new(cc, path))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user