commit 2f20e8253ea63be370e1c04a43e549f9a4df192f
parent fab1257f6eb0681ee492c82d135f83be61f99f40
Author: William Casarin <jb55@jb55.com>
Date: Wed, 13 Nov 2024 10:12:58 -0800
app: simplify Damus::new constructor
Just take an egui::Context instead of an eframe::CreationContext.
This should make it easier to test the app via egui::Context::default();
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
4 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/src/app.rs b/src/app.rs
@@ -647,16 +647,12 @@ fn determine_key_storage_type() -> KeyStorageType {
impl Damus {
/// Called once before the first frame.
- pub fn new<P: AsRef<Path>>(
- cc: &eframe::CreationContext<'_>,
- data_path: P,
- args: Vec<String>,
- ) -> Self {
+ pub fn new<P: AsRef<Path>>(ctx: &egui::Context, data_path: P, args: Vec<String>) -> Self {
// arg parsing
let parsed_args = Args::parse(&args);
let is_mobile = parsed_args.is_mobile.unwrap_or(ui::is_compiled_as_mobile());
- setup_cc(cc, is_mobile, parsed_args.light);
+ setup_cc(ctx, is_mobile, parsed_args.light);
let data_path = parsed_args
.datapath
@@ -700,13 +696,16 @@ impl Damus {
// setup relays if we have them
let pool = if parsed_args.relays.is_empty() {
let mut pool = RelayPool::new();
- relay_setup(&mut pool, &cc.egui_ctx);
+ relay_setup(&mut pool, ctx);
pool
} else {
- let ctx = cc.egui_ctx.clone();
- let wakeup = move || {
- ctx.request_repaint();
+ let wakeup = {
+ let ctx = ctx.clone();
+ move || {
+ ctx.request_repaint();
+ }
};
+
let mut pool = RelayPool::new();
for relay in parsed_args.relays {
if let Err(e) = pool.add_url(relay.clone(), wakeup.clone()) {
diff --git a/src/app_creation.rs b/src/app_creation.rs
@@ -51,8 +51,7 @@ pub fn generate_mobile_emulator_native_options() -> eframe::NativeOptions {
})
}
-pub fn setup_cc(cc: &eframe::CreationContext<'_>, is_mobile: bool, light: bool) {
- let ctx = &cc.egui_ctx;
+pub fn setup_cc(ctx: &egui::Context, is_mobile: bool, light: bool) {
setup_fonts(ctx);
//ctx.set_pixels_per_point(ctx.pixels_per_point() + UI_SCALE_FACTOR);
diff --git a/src/bin/notedeck.rs b/src/bin/notedeck.rs
@@ -77,7 +77,7 @@ async fn main() {
generate_native_options(path),
Box::new(|cc| {
Ok(Box::new(Damus::new(
- cc,
+ &cc.egui_ctx,
base_path,
std::env::args().collect(),
)))
diff --git a/src/ui_preview/main.rs b/src/ui_preview/main.rs
@@ -43,7 +43,7 @@ impl PreviewRunner {
native_options,
Box::new(move |cc| {
let app = Into::<PreviewApp>::into(preview);
- setup_cc(cc, is_mobile, light_mode);
+ setup_cc(&cc.egui_ctx, is_mobile, light_mode);
Ok(Box::new(app))
}),
);