From ac1e5e1b4ec2f07a14f5e171fb067c63a857a5f8 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Tue, 6 Aug 2024 10:14:32 -0700 Subject: [PATCH] Split app key from viewport title to stop spraying app.ron files everywhere. Egui uses the app key to determine the storage location for persisted configuration files. This does not work well when the app key is something like "~/Downloads/prof_0.gz - Legion Prof" (the case when profiling files you've just downloaded), which results in the app.ron files being persisted to some random subdirectory of ~/Downloads instead of "~/Library/Application Support/Legion Prof" or something similar (depending on the OS). So split the app key off from the viewport title so that the former can be short and predictable and not mess with the persistent config location so badly. --- src/app.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/app.rs b/src/app.rs index eca9c64..fea764e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2770,9 +2770,7 @@ impl UiExtra for egui::Ui { } #[cfg(not(target_arch = "wasm32"))] -pub fn start(data_sources: Vec>) { - env_logger::try_init().unwrap_or(()); // Log to stderr (if you run with `RUST_LOG=debug`). - +fn get_locator(data_sources: &[Box]) -> String { let all_locators = data_sources .iter() .flat_map(|x| x.fetch_description().source_locator) @@ -2780,17 +2778,32 @@ pub fn start(data_sources: Vec>) { let unique_locators = all_locators.into_iter().unique().collect_vec(); - let locator = match &unique_locators[..] { + match &unique_locators[..] { [] => "No data source".to_string(), [x] => x.to_string(), [x, ..] => format!("{} and {} other sources", x, unique_locators.len() - 1), - }; + } +} - let app_name = format!("{locator} - Legion Prof"); +#[cfg(not(target_arch = "wasm32"))] +pub fn start(data_sources: Vec>) { + env_logger::try_init().unwrap_or(()); // Log to stderr (if you run with `RUST_LOG=debug`). - let native_options = eframe::NativeOptions::default(); + // IMPORTANT: This will be used as the directory name for the storage + // location for the persisted app.ron configuration. eframe is not good + // about sanitizing these directory names, so it is VERY IMPORTANT that + // this be a short, predictable name without weird characters in it. + let app_name = "Legion Prof"; + + // This is what will be displayed as the window's actual title. + let locator = format!("{} - {}", get_locator(&data_sources), app_name); + + let native_options = eframe::NativeOptions { + viewport: egui::ViewportBuilder::default().with_title(locator), + ..Default::default() + }; eframe::run_native( - &app_name, + app_name, native_options, Box::new(|cc| Box::new(ProfApp::new(cc, data_sources))), )