From 2f20e8253ea63be370e1c04a43e549f9a4df192f Mon Sep 17 00:00:00 2001 From: William Casarin Date: Wed, 13 Nov 2024 10:12:58 -0800 Subject: [PATCH] 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 --- src/app.rs | 19 +++++++++---------- src/app_creation.rs | 3 +-- src/bin/notedeck.rs | 2 +- src/ui_preview/main.rs | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/app.rs b/src/app.rs index b77d560..55c8e2e 100644 --- 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>( - cc: &eframe::CreationContext<'_>, - data_path: P, - args: Vec, - ) -> Self { + pub fn new>(ctx: &egui::Context, data_path: P, args: Vec) -> 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 index 55924f0..02fb332 100644 --- 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 index 4b226a9..6df1834 100644 --- 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 index 186d3dd..8be13a0 100644 --- 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::::into(preview); - setup_cc(cc, is_mobile, light_mode); + setup_cc(&cc.egui_ctx, is_mobile, light_mode); Ok(Box::new(app)) }), );