dave: prepare for android

This commit is contained in:
William Casarin
2025-03-26 09:20:46 -07:00
parent cb7a3adacf
commit 4469918fd2
8 changed files with 70 additions and 211 deletions

View File

@@ -3,8 +3,9 @@
use egui_winit::winit::platform::android::activity::AndroidApp;
use notedeck_columns::Damus;
use notedeck_dave::Dave;
use crate::setup::setup_chrome;
use crate::{setup::setup_chrome, chrome::Chrome};
use notedeck::Notedeck;
use serde_json::Value;
use std::fs;
@@ -13,7 +14,7 @@ use std::path::PathBuf;
#[no_mangle]
#[tokio::main]
pub async fn android_main(app: AndroidApp) {
use tracing_logcat::{LogcatMakeWriter, LogcatTag};
//use tracing_logcat::{LogcatMakeWriter, LogcatTag};
use tracing_subscriber::{prelude::*, EnvFilter};
std::env::set_var("RUST_BACKTRACE", "full");
@@ -24,8 +25,8 @@ pub async fn android_main(app: AndroidApp) {
// "enostr=debug,notedeck_columns=debug,notedeck_chrome=debug",
//);
let writer =
LogcatMakeWriter::new(LogcatTag::Target).expect("Failed to initialize logcat writer");
//let writer =
//LogcatMakeWriter::new(LogcatTag::Target).expect("Failed to initialize logcat writer");
let fmt_layer = tracing_subscriber::fmt::layer()
.with_level(false)
@@ -62,12 +63,15 @@ pub async fn android_main(app: AndroidApp) {
let mut notedeck = Notedeck::new(ctx, path, &app_args);
setup_chrome(ctx, &notedeck.args(), notedeck.theme());
let damus = Damus::new(&mut notedeck.app_context(), &app_args);
let context = &mut notedeck.app_context();
let dave = Dave::new(cc.wgpu_render_state.as_ref());
let columns = Damus::new(context, &app_args);
let mut chrome = Chrome::new();
// ensure we recognized all the arguments
let completely_unrecognized: Vec<String> = notedeck
.unrecognized_args()
.intersection(damus.unrecognized_args())
.intersection(columns.unrecognized_args())
.cloned()
.collect();
assert!(
@@ -76,7 +80,13 @@ pub async fn android_main(app: AndroidApp) {
completely_unrecognized
);
notedeck.set_app(damus);
chrome.add_app(columns);
chrome.add_app(dave);
// test dav
chrome.set_active(1);
notedeck.set_app(chrome);
Ok(Box::new(notedeck))
}),

View File

@@ -0,0 +1,37 @@
// Entry point for wasm
//#[cfg(target_arch = "wasm32")]
//use wasm_bindgen::prelude::*;
pub struct Chrome {
active: i32,
apps: Vec<Box<dyn notedeck::App>>,
}
impl Chrome {
pub fn new() -> Self {
Chrome {
active: 0,
apps: vec![],
}
}
pub fn add_app(&mut self, app: impl notedeck::App + 'static) {
self.apps.push(Box::new(app));
}
pub fn set_active(&mut self, app: i32) {
self.active = app;
}
}
impl notedeck::App for Chrome {
fn update(&mut self, ctx: &mut notedeck::AppContext, ui: &mut egui::Ui) {
let active = self.active;
self.apps[active as usize].update(ctx, ui);
//for i in 0..self.apps.len() {
// self.apps[i].update(ctx, ui);
//}
}
}

View File

@@ -4,3 +4,7 @@ pub mod theme;
#[cfg(target_os = "android")]
mod android;
mod chrome;
pub use chrome::Chrome;

View File

@@ -1,49 +1,16 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
//#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
// hide console window on Windows in release
use notedeck_chrome::setup::{generate_native_options, setup_chrome};
use notedeck::{DataPath, DataPathType, Notedeck};
use notedeck_chrome::{
setup::{generate_native_options, setup_chrome},
Chrome,
};
use notedeck_columns::Damus;
use notedeck_dave::Dave;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::EnvFilter;
// Entry point for wasm
//#[cfg(target_arch = "wasm32")]
//use wasm_bindgen::prelude::*;
struct Chrome {
active: i32,
apps: Vec<Box<dyn notedeck::App>>,
}
impl Chrome {
pub fn new() -> Self {
Chrome {
active: 0,
apps: vec![],
}
}
pub fn add_app(&mut self, app: impl notedeck::App + 'static) {
self.apps.push(Box::new(app));
}
pub fn set_active(&mut self, app: i32) {
self.active = app;
}
}
impl notedeck::App for Chrome {
fn update(&mut self, ctx: &mut notedeck::AppContext, ui: &mut egui::Ui) {
let active = self.active;
self.apps[active as usize].update(ctx, ui);
//for i in 0..self.apps.len() {
// self.apps[i].update(ctx, ui);
//}
}
}
fn setup_logging(path: &DataPath) -> Option<WorkerGuard> {
#[allow(unused_variables)] // need guard to live for lifetime of program
let (maybe_non_blocking, maybe_guard) = {