Introducing Damus Notedeck: a nostr browser
This splits notedeck into: - notedeck - notedeck_chrome - notedeck_columns The `notedeck` crate is the library that `notedeck_chrome` and `notedeck_columns`, use. It contains common functionality related to notedeck apps such as the NoteCache, ImageCache, etc. The `notedeck_chrome` crate is the binary and ui chrome. It is responsible for managing themes, user accounts, signing, data paths, nostrdb, image caches etc. It will eventually have its own ui which has yet to be determined. For now it just manages the browser data, which is passed to apps via a new struct called `AppContext`. `notedeck_columns` is our columns app, with less responsibility now that more things are handled by `notedeck_chrome` There is still much work left to do before this is a proper browser: - process isolation - sandboxing - etc This is the beginning of a new era! We're just getting started. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
110
crates/notedeck_chrome/src/preview.rs
Normal file
110
crates/notedeck_chrome/src/preview.rs
Normal file
@@ -0,0 +1,110 @@
|
||||
use notedeck::DataPath;
|
||||
use notedeck_chrome::setup::{
|
||||
generate_mobile_emulator_native_options, generate_native_options, setup_cc,
|
||||
};
|
||||
use notedeck_columns::ui::configure_deck::ConfigureDeckView;
|
||||
use notedeck_columns::ui::edit_deck::EditDeckView;
|
||||
use notedeck_columns::ui::{
|
||||
account_login_view::AccountLoginView, PostView, Preview, PreviewApp, PreviewConfig, ProfilePic,
|
||||
ProfilePreview, RelayView,
|
||||
};
|
||||
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::ui::is_compiled_as_mobile());
|
||||
let runner = PreviewRunner::new(is_mobile, light_mode);
|
||||
|
||||
previews!(
|
||||
runner,
|
||||
name,
|
||||
is_mobile,
|
||||
RelayView,
|
||||
AccountLoginView,
|
||||
ProfilePreview,
|
||||
ProfilePic,
|
||||
PostView,
|
||||
ConfigureDeckView,
|
||||
EditDeckView,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user