mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-01-17 23:34: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 {
|
impl Damus {
|
||||||
/// Called once before the first frame.
|
/// Called once before the first frame.
|
||||||
pub fn new<P: AsRef<Path>>(
|
pub fn new<P: AsRef<Path>>(ctx: &egui::Context, data_path: P, args: Vec<String>) -> Self {
|
||||||
cc: &eframe::CreationContext<'_>,
|
|
||||||
data_path: P,
|
|
||||||
args: Vec<String>,
|
|
||||||
) -> Self {
|
|
||||||
// arg parsing
|
// arg parsing
|
||||||
let parsed_args = Args::parse(&args);
|
let parsed_args = Args::parse(&args);
|
||||||
let is_mobile = parsed_args.is_mobile.unwrap_or(ui::is_compiled_as_mobile());
|
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
|
let data_path = parsed_args
|
||||||
.datapath
|
.datapath
|
||||||
@@ -700,13 +696,16 @@ impl Damus {
|
|||||||
// setup relays if we have them
|
// setup relays if we have them
|
||||||
let pool = if parsed_args.relays.is_empty() {
|
let pool = if parsed_args.relays.is_empty() {
|
||||||
let mut pool = RelayPool::new();
|
let mut pool = RelayPool::new();
|
||||||
relay_setup(&mut pool, &cc.egui_ctx);
|
relay_setup(&mut pool, ctx);
|
||||||
pool
|
pool
|
||||||
} else {
|
} else {
|
||||||
let ctx = cc.egui_ctx.clone();
|
let wakeup = {
|
||||||
let wakeup = move || {
|
let ctx = ctx.clone();
|
||||||
ctx.request_repaint();
|
move || {
|
||||||
|
ctx.request_repaint();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut pool = RelayPool::new();
|
let mut pool = RelayPool::new();
|
||||||
for relay in parsed_args.relays {
|
for relay in parsed_args.relays {
|
||||||
if let Err(e) = pool.add_url(relay.clone(), wakeup.clone()) {
|
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) {
|
pub fn setup_cc(ctx: &egui::Context, is_mobile: bool, light: bool) {
|
||||||
let ctx = &cc.egui_ctx;
|
|
||||||
setup_fonts(ctx);
|
setup_fonts(ctx);
|
||||||
|
|
||||||
//ctx.set_pixels_per_point(ctx.pixels_per_point() + UI_SCALE_FACTOR);
|
//ctx.set_pixels_per_point(ctx.pixels_per_point() + UI_SCALE_FACTOR);
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ async fn main() {
|
|||||||
generate_native_options(path),
|
generate_native_options(path),
|
||||||
Box::new(|cc| {
|
Box::new(|cc| {
|
||||||
Ok(Box::new(Damus::new(
|
Ok(Box::new(Damus::new(
|
||||||
cc,
|
&cc.egui_ctx,
|
||||||
base_path,
|
base_path,
|
||||||
std::env::args().collect(),
|
std::env::args().collect(),
|
||||||
)))
|
)))
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ impl PreviewRunner {
|
|||||||
native_options,
|
native_options,
|
||||||
Box::new(move |cc| {
|
Box::new(move |cc| {
|
||||||
let app = Into::<PreviewApp>::into(preview);
|
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))
|
Ok(Box::new(app))
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user