mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-01-14 13:54:19 +01:00
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>
This commit is contained in:
19
src/app.rs
19
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()) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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(),
|
||||
)))
|
||||
|
||||
@@ -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))
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user