Skip to content

Commit

Permalink
Split app key from viewport title to stop spraying app.ron files ever…
Browse files Browse the repository at this point in the history
…ywhere.

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.
  • Loading branch information
elliottslaughter committed Aug 6, 2024
1 parent 05245b0 commit ac1e5e1
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2770,27 +2770,40 @@ impl UiExtra for egui::Ui {
}

#[cfg(not(target_arch = "wasm32"))]
pub fn start(data_sources: Vec<Box<dyn DeferredDataSource>>) {
env_logger::try_init().unwrap_or(()); // Log to stderr (if you run with `RUST_LOG=debug`).

fn get_locator(data_sources: &[Box<dyn DeferredDataSource>]) -> String {
let all_locators = data_sources
.iter()
.flat_map(|x| x.fetch_description().source_locator)
.collect::<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<Box<dyn DeferredDataSource>>) {
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))),
)
Expand Down

0 comments on commit ac1e5e1

Please sign in to comment.