split notedeck into crates

This splits notedeck into crates, separating the browser chrome and
individual apps:

* notedeck: binary file, browser chrome
* notedeck_columns: our columns app
* enostr: same as before

We still need to do more work to cleanly separate the chrome apis
from the app apis. Soon I will create notedeck-notebook to see what
makes sense to be shared between the apps.

Some obvious ones that come to mind:

1. ImageCache

We will likely want to move this to the notedeck crate, as most apps
will want some kind of image cache. In web browsers, web pages do not
need to worry about this, so we will likely have to do something similar

2. Ndb

Since NdbRef is threadsafe and Ndb is an Arc<NdbRef>, it can be safely
copied to each app. This will simplify things. In the future we might
want to create an abstraction over this? Maybe each app shouldn't have
access to the same database... we assume the data in DBs are all public
anyways, but if we have unwrapped giftwraps that could be a problem.

3. RelayPool / Subscription Manager

The browser should probably maintain these. Then apps can use ken's
high level subscription manager api and not have to worry about
connection pool details

4. Accounts

Accounts and key management should be handled by the chrome. Apps should
only have a simple signer interface.

That's all for now, just something to think about!

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-12-11 02:53:05 -08:00
parent 10cbdf15f0
commit 74c5f0c748
156 changed files with 194 additions and 252 deletions

View File

@@ -0,0 +1,71 @@
[package]
name = "notedeck"
version = "0.2.0"
authors = ["William Casarin <jb55@jb55.com>", "kernelkind <kernelkind@gmail.com>"]
edition = "2021"
default-run = "notedeck"
#rust-version = "1.60"
license = "GPLv3"
description = "A nostr browser"
[dependencies]
notedeck_columns = { workspace = true }
tracing-subscriber = { workspace = true }
tracing-appender = { workspace = true }
tokio = { workspace = true }
eframe = { workspace = true }
[[bin]]
name = "notedeck"
path = "src/notedeck.rs"
[[bin]]
name = "ui_preview"
path = "src/preview.rs"
[features]
default = []
profiling = ["notedeck_columns/puffin"]
[target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.11.1"
android-activity = { version = "0.4", features = [ "native-activity" ] }
winit = { version = "0.30.5", features = [ "android-native-activity" ] }
#winit = { git="https://github.com/rust-windowing/winit.git", rev = "2a58b785fed2a3746f7c7eebce95bce67ddfd27c", features = ["android-native-activity"] }
[package.metadata.bundle]
identifier = "com.damus.notedeck"
icon = ["assets/app_icon.icns"]
[package.metadata.android]
package = "com.damus.app"
apk_name = "damus"
#assets = "assets"
[[package.metadata.android.uses_feature]]
name = "android.hardware.vulkan.level"
required = true
version = 1
[[package.metadata.android.uses_permission]]
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"
[[package.metadata.android.uses_permission]]
name = "android.permission.INTERNET"
[package.metadata.android.application]
label = "Damus"
[package.metadata.generate-rpm]
assets = [
{ source = "target/release/notedeck", dest = "/usr/bin/notedeck", mode = "755" },
]

View File

@@ -0,0 +1,105 @@
#![warn(clippy::all, rust_2018_idioms)]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use notedeck_columns::{
app_creation::generate_native_options,
storage::{DataPath, DataPathType},
Damus,
};
use std::{path::PathBuf, str::FromStr};
use tracing_subscriber::EnvFilter;
// Entry point for wasm
//#[cfg(target_arch = "wasm32")]
//use wasm_bindgen::prelude::*;
fn setup_logging(path: &DataPath) {
#[allow(unused_variables)] // need guard to live for lifetime of program
let (maybe_non_blocking, maybe_guard) = {
let log_path = path.path(DataPathType::Log);
// Setup logging to file
use tracing_appender::{
non_blocking,
rolling::{RollingFileAppender, Rotation},
};
let file_appender = RollingFileAppender::new(
Rotation::DAILY,
log_path,
format!("notedeck-{}.log", env!("CARGO_PKG_VERSION")),
);
let (non_blocking, _guard) = non_blocking(file_appender);
(Some(non_blocking), Some(_guard))
};
// Log to stdout (if you run with `RUST_LOG=debug`).
if let Some(non_blocking_writer) = maybe_non_blocking {
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt};
let console_layer = fmt::layer().with_target(true).with_writer(std::io::stdout);
// Create the file layer (writes to the file)
let file_layer = fmt::layer()
.with_ansi(false)
.with_writer(non_blocking_writer);
let env_filter =
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
// Set up the subscriber to combine both layers
tracing_subscriber::registry()
.with(console_layer)
.with(file_layer)
.with(env_filter)
.init();
} else {
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.init();
}
}
// Desktop
#[cfg(not(target_arch = "wasm32"))]
#[tokio::main]
async fn main() {
let base_path = DataPath::default_base().unwrap_or(PathBuf::from_str(".").unwrap());
let path = DataPath::new(&base_path);
setup_logging(&path);
let _res = eframe::run_native(
"Damus Notedeck",
generate_native_options(path),
Box::new(|cc| {
Ok(Box::new(Damus::new(
&cc.egui_ctx,
base_path,
std::env::args().collect(),
)))
}),
);
}
#[cfg(target_arch = "wasm32")]
pub fn main() {
// Make sure panics are logged using `console.error`.
console_error_panic_hook::set_once();
// Redirect tracing to console.log and friends:
tracing_wasm::set_as_global_default();
wasm_bindgen_futures::spawn_local(async {
let web_options = eframe::WebOptions::default();
eframe::start_web(
"the_canvas_id", // hardcode it
web_options,
Box::new(|cc| Box::new(Damus::new(cc, "."))),
)
.await
.expect("failed to start eframe");
});
}

View File

@@ -0,0 +1,114 @@
use notedeck_columns::ui::configure_deck::ConfigureDeckView;
use notedeck_columns::ui::edit_deck::EditDeckView;
use notedeck_columns::ui::{
account_login_view::AccountLoginView, accounts::AccountsView, add_column::AddColumnView,
DesktopSidePanel, PostView, Preview, PreviewApp, PreviewConfig, ProfilePic, ProfilePreview,
RelayView,
};
use notedeck_columns::{
app_creation::{generate_mobile_emulator_native_options, generate_native_options, setup_cc},
storage::DataPath,
};
use std::env;
struct PreviewRunner {
force_mobile: bool,
light_mode: bool,
}
impl PreviewRunner {
fn new(force_mobile: bool, light_mode: bool) -> Self {
PreviewRunner {
force_mobile,
light_mode,
}
}
async fn run<P>(self, preview: P)
where
P: Into<PreviewApp> + 'static,
{
tracing_subscriber::fmt::init();
let native_options = if self.force_mobile {
generate_mobile_emulator_native_options()
} else {
// TODO: tmp preview pathbuf?
generate_native_options(DataPath::new("previews"))
};
let is_mobile = self.force_mobile;
let light_mode = self.light_mode;
let _ = eframe::run_native(
"UI Preview Runner",
native_options,
Box::new(move |cc| {
let app = Into::<PreviewApp>::into(preview);
setup_cc(&cc.egui_ctx, is_mobile, light_mode);
Ok(Box::new(app))
}),
);
}
}
macro_rules! previews {
// Accept a runner and name variable, followed by one or more identifiers for the views
($runner:expr, $name:expr, $is_mobile:expr, $($view:ident),* $(,)?) => {
match $name.as_ref() {
$(
stringify!($view) => {
$runner.run($view::preview(PreviewConfig { is_mobile: $is_mobile })).await;
}
)*
_ => println!("Component not found."),
}
};
}
#[tokio::main]
async fn main() {
let mut name: Option<String> = None;
let mut is_mobile: Option<bool> = None;
let mut light_mode: bool = false;
for arg in env::args() {
if arg == "--mobile" {
is_mobile = Some(true);
} else if arg == "--light" {
light_mode = true;
} else {
name = Some(arg);
}
}
let name = if let Some(name) = name {
name
} else {
println!("Please specify a component to test");
return;
};
println!(
"light mode previews: {}",
if light_mode { "enabled" } else { "disabled" }
);
let is_mobile = is_mobile.unwrap_or(notedeck_columns::ui::is_compiled_as_mobile());
let runner = PreviewRunner::new(is_mobile, light_mode);
previews!(
runner,
name,
is_mobile,
RelayView,
AccountLoginView,
ProfilePreview,
ProfilePic,
AccountsView,
DesktopSidePanel,
PostView,
AddColumnView,
ConfigureDeckView,
EditDeckView,
);
}