chrome: remove duplication in app setup

Also move debug warning to chrome so that headless
notedeck apps don't hit that.
This commit is contained in:
William Casarin
2025-07-31 17:07:25 -07:00
parent 09eeb57bd9
commit dac786e60f
12 changed files with 449 additions and 467 deletions

View File

@@ -1,75 +1,6 @@
use crate::{fonts, theme};
use eframe::NativeOptions;
use egui::{FontId, ThemePreference};
use notedeck::{AppSizeHandler, DataPath, NotedeckOptions, NotedeckTextStyle};
use notedeck::{AppSizeHandler, DataPath};
use notedeck_ui::app_images;
use tracing::info;
pub fn setup_chrome(
ctx: &egui::Context,
args: &notedeck::Args,
theme: ThemePreference,
note_body_font_size: f32,
zoom_factor: f32,
) {
let is_mobile =
args.options.contains(NotedeckOptions::Mobile) || notedeck::ui::is_compiled_as_mobile();
let is_oled = notedeck::ui::is_oled();
// Some people have been running notedeck in debug, let's catch that!
if !args.options.contains(NotedeckOptions::Tests)
&& cfg!(debug_assertions)
&& !args.options.contains(NotedeckOptions::Debug)
{
println!("--- WELCOME TO DAMUS NOTEDECK! ---");
println!(
"It looks like are running notedeck in debug mode, unless you are a developer, this is not likely what you want."
);
println!("If you are a developer, run `cargo run -- --debug` to skip this message.");
println!("For everyone else, try again with `cargo run --release`. Enjoy!");
println!("---------------------------------");
panic!();
}
ctx.options_mut(|o| {
info!("Loaded theme {:?} from disk", theme);
o.theme_preference = theme;
});
ctx.set_visuals_of(egui::Theme::Dark, theme::dark_mode(is_oled));
ctx.set_visuals_of(egui::Theme::Light, theme::light_mode());
setup_cc(ctx, is_mobile);
ctx.set_zoom_factor(zoom_factor);
let mut style = (*ctx.style()).clone();
style.text_styles.insert(
NotedeckTextStyle::NoteBody.text_style(),
FontId::proportional(note_body_font_size),
);
ctx.set_style(style);
}
pub fn setup_cc(ctx: &egui::Context, is_mobile: bool) {
fonts::setup_fonts(ctx);
if notedeck::ui::is_compiled_as_mobile() {
ctx.set_pixels_per_point(ctx.pixels_per_point() + 0.2);
}
//ctx.set_pixels_per_point(1.0);
//
//
//ctx.tessellation_options_mut(|to| to.feathering = false);
egui_extras::install_image_loaders(ctx);
ctx.options_mut(|o| {
o.input_options.max_click_duration = 0.4;
});
ctx.all_styles_mut(|style| theme::add_custom_style(is_mobile, style));
}
pub fn generate_native_options(paths: DataPath) -> NativeOptions {
let window_builder = Box::new(move |builder: egui::ViewportBuilder| {