Files
effectcraft/crates/ui-egui/src/panels/settings.rs
T

621 lines
29 KiB
Rust
Raw Normal View History

2026-10-02 09:14:45 -04:00
//! The Settings dialog (After Effects' Preferences): the page list on the left, the page on the
//! right, OK / Cancel / Previous / Next. Pages are built from the engine's schema
//! (`effectcraft_engine::prefs::pages`), so the dialog, `prefs.pages` and the docs agree. Edits
//! apply live; Cancel restores the settings from when the dialog opened, OK saves them.
//!
//! Automation ids: `settings.page.<id>`, `settings.<key>` (e.g. `settings.general.undoLevels`),
//! `settings.labels.<n>.name` / `.color`, `settings.button.<label>`, `settings.ok`,
//! `settings.cancel`, `settings.previous`, `settings.next`.
use effectcraft_engine::prefs::{Item, Kind, Page, pages};
use effectcraft_engine::segment::Task;
2026-10-02 09:14:45 -04:00
use egui::{Color32, RichText, vec2};
use serde_json::{Value, json};
use crate::theme::Tokens;
use crate::{Dialog, EffectcraftApp};
/// Open the dialog on a page, remembering the settings for Cancel.
pub fn open(app: &mut EffectcraftApp, page: &str) {
if app.dialog != Some(Dialog::Settings) {
app.dialog_state.prefs_snapshot = Some(app.session.prefs.clone());
}
app.dialog_state.settings_page = page.to_string();
app.dialog = Some(Dialog::Settings);
}
enum Act {
Set(String, Value),
Run(String, Value),
PickFolder(String),
PickProject(String),
/// Install from File (a downloaded weights file) for a task's models.
PickModel(Task),
2026-10-02 09:14:45 -04:00
}
fn hex(c: [u8; 3]) -> String {
format!("#{:02x}{:02x}{:02x}", c[0], c[1], c[2])
}
fn reg(app: &mut EffectcraftApp, id: &str, r: &egui::Response, label: &str) {
app.auto.add(id, r.rect, label);
}
/// One page's rows.
fn page_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, page: &Page, cur: &Value, t: &Tokens, acts: &mut Vec<Act>) {
let get = |key: &str| cur.pointer(&format!("/{}", key.replace('.', "/"))).cloned().unwrap_or(Value::Null);
let label_w = 250.0;
for item in &page.items {
match *item {
Item::Section(title) => {
ui.add_space(6.0);
ui.label(RichText::new(title).font(Tokens::semibold(12.5)).color(t.tab_text_active));
ui.separator();
}
Item::Note(text) => {
ui.label(RichText::new(text).color(t.text_dim));
}
Item::Button { label, command, params } => {
let r = ui.button(label);
reg(app, &format!("settings.button.{}", label.trim_end_matches('.')), &r, label);
if r.clicked() {
acts.push(Act::Run(command.into(), serde_json::from_str(params).unwrap_or(json!({}))));
}
}
Item::Labels => labels_ui(app, ui, cur, acts),
Item::BrowserStorage => browser_storage_ui(app, ui, t, acts),
Item::Models(task) => models_ui(app, ui, t, acts, task),
2026-10-02 09:14:45 -04:00
Item::AudioDevices { key } => {
let devices: Vec<String> = app.hooks.audio_devices.as_ref().map(|f| f()).unwrap_or_default();
let sel = get(key).as_str().unwrap_or("").to_string();
ui.horizontal(|ui| {
ui.add_sized(vec2(label_w, 18.0), egui::Label::new("Default Output:"));
let shown = if sel.is_empty() { "System Default".to_string() } else { sel.clone() };
let r = egui::ComboBox::from_id_salt(("settings", key)).selected_text(shown).width(260.0).show_ui(ui, |ui| {
if ui.selectable_label(sel.is_empty(), "System Default").clicked() {
acts.push(Act::Set(key.into(), json!("")));
}
for d in &devices {
if ui.selectable_label(*d == sel, d).clicked() {
acts.push(Act::Set(key.into(), json!(d)));
}
}
});
reg(app, &format!("settings.{key}"), &r.response, "Default Output");
});
if devices.is_empty() {
ui.label(RichText::new("No device list from this host; the system default output is used.").color(t.text_dim));
}
}
Item::Setting { key, label, kind, live } => {
let v = get(key);
let id = format!("settings.{key}");
let tip = (!live).then_some("Stored, but not used by EffectCraft yet");
let mut resp: Option<egui::Response> = None;
match kind {
Kind::Bool => {
let mut b = v.as_bool().unwrap_or(false);
let r = ui.checkbox(&mut b, label);
if r.changed() {
acts.push(Act::Set(key.into(), json!(b)));
}
resp = Some(r);
}
_ => {
ui.horizontal(|ui| {
ui.add_sized(vec2(label_w, 18.0), egui::Label::new(format!("{label}:")).truncate());
let r = match kind {
Kind::Int(lo, hi, unit) => {
let mut x = v.as_i64().unwrap_or(0);
let r = ui.add(egui::DragValue::new(&mut x).range(lo..=hi).speed(0.25));
if !unit.is_empty() {
ui.label(RichText::new(unit).color(t.text_dim));
}
if r.changed() {
acts.push(Act::Set(key.into(), json!(x)));
}
r
}
Kind::Float(lo, hi, unit) => {
let mut x = v.as_f64().unwrap_or(0.0);
let r = ui.add(egui::DragValue::new(&mut x).range(lo..=hi).speed(0.1).max_decimals(3));
if !unit.is_empty() {
ui.label(RichText::new(unit).color(t.text_dim));
}
if r.changed() {
acts.push(Act::Set(key.into(), json!(x)));
}
r
}
Kind::Slider(lo, hi) => {
let mut x = v.as_f64().unwrap_or(0.0);
ui.label(RichText::new("Darker").color(t.text_dim));
let r = ui.add(egui::Slider::new(&mut x, lo..=hi).show_value(false));
ui.label(RichText::new("Lighter").color(t.text_dim));
if ui.small_button("Default").clicked() {
acts.push(Act::Set(key.into(), json!(0.0)));
}
if r.changed() {
acts.push(Act::Set(key.into(), json!(x)));
}
r
}
Kind::Choice(opts) => {
// (A number with choices, UI Scale, shows as its text.)
let curv = v.as_str().map_or_else(|| v.to_string(), str::to_string);
2026-10-02 09:14:45 -04:00
let shown = opts.iter().find(|o| o.1 == curv).map(|o| o.0).unwrap_or(curv.as_str()).to_string();
egui::ComboBox::from_id_salt(("settings", key))
.selected_text(shown)
.width(220.0)
.show_ui(ui, |ui| {
for (l, val) in opts {
if ui.selectable_label(*val == curv, *l).clicked() {
acts.push(Act::Set(key.into(), json!(val)));
}
}
})
.response
}
Kind::Text | Kind::Path => {
let mut s = v.as_str().unwrap_or("").to_string();
let r = ui.add(egui::TextEdit::singleline(&mut s).desired_width(if kind == Kind::Path { 230.0 } else { 260.0 }));
if r.changed() {
acts.push(Act::Set(key.into(), json!(s)));
}
if kind == Kind::Path {
let b = ui.button("Choose...");
reg(app, &format!("{id}.choose"), &b, "Choose...");
if b.clicked() {
acts.push(if key.ends_with("Path") { Act::PickProject(key.into()) } else { Act::PickFolder(key.into()) });
}
}
r
}
Kind::Color => {
let c = crate::panels::viewer::hex_rgb(v.as_str().unwrap_or("")).unwrap_or([128, 128, 128]);
let mut rgb = c;
let r = ui.color_edit_button_srgb(&mut rgb);
ui.label(RichText::new(hex(rgb)).monospace().color(t.text_dim));
if rgb != c {
acts.push(Act::Set(key.into(), json!(hex(rgb))));
}
r
}
// Checkboxes are drawn above; nothing to edit here.
Kind::Bool => ui.label(""),
2026-10-02 09:14:45 -04:00
};
resp = Some(r);
});
}
}
if let Some(r) = resp {
let r = match tip {
Some(tip) => r.on_hover_text(tip),
None => r,
};
reg(app, &id, &r, label);
}
}
}
}
}
/// Bytes as "12.3 MB".
pub fn human_bytes(b: u64) -> String {
let units = ["bytes", "KB", "MB", "GB", "TB"];
let mut v = b as f64;
let mut u = 0;
while v >= 1000.0 && u + 1 < units.len() {
v /= 1000.0;
u += 1;
}
if u == 0 { format!("{b} bytes") } else { format!("{v:.1} {}", units[u]) }
}
/// Settings ▸ Roto Brush and Settings ▸ Face Tracking: a task's models (`roto.models`,
/// `face.models`): choose one; download, install from a file or remove the trained ones; who made
/// them, their licence, size and source.
fn models_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, t: &Tokens, acts: &mut Vec<Act>, task: Task) {
let (prefix, user) = match task {
Task::Mask => ("roto", "Roto Brush"),
Task::Face => ("face", "Face tracking"),
};
let Ok(info) = app.session.execute(&format!("{prefix}.models"), json!({})) else { return };
let web = cfg!(target_arch = "wasm32");
let busy = info["busy"].as_str().map(str::to_string);
for m in info["models"].as_array().into_iter().flatten() {
let id = m["id"].as_str().unwrap_or_default().to_string();
let name = m["name"].as_str().unwrap_or_default();
let classic = id == effectcraft_engine::segment::CLASSICAL;
let (installed, selected, active) =
(m["installed"].as_bool().unwrap_or(false), m["selected"].as_bool().unwrap_or(false), m["active"].as_bool().unwrap_or(false));
ui.add_space(6.0);
egui::Frame::new().fill(t.field_bg).corner_radius(6.0).inner_margin(egui::Margin::same(10)).show(ui, |ui| {
ui.set_width(ui.available_width());
ui.horizontal(|ui| {
let r = ui.radio(selected, RichText::new(name).font(Tokens::semibold(12.5)));
reg(app, &format!("settings.{prefix}.model.{id}"), &r, name);
if r.clicked() && !selected {
acts.push(Act::Run(format!("{prefix}.model.select"), json!({"id": id})));
}
let state = match (active, installed, selected) {
(true, _, _) => "In use".to_string(),
_ if classic => "Built in".to_string(),
(false, true, true) if busy.is_some() => "Loading…".to_string(),
(false, true, _) => "Installed".to_string(),
(false, false, true) => format!("Not installed: {user} uses the classic engine"),
_ => "Not installed".to_string(),
};
ui.label(RichText::new(state).color(if active { t.accent } else { t.text_dim }));
});
ui.label(RichText::new(m["description"].as_str().unwrap_or_default()).color(t.text_dim));
if let Some(by) = m["authors"].as_str() {
ui.label(RichText::new(format!("By {by}")).color(t.text_dim));
}
ui.horizontal_wrapped(|ui| {
ui.label(RichText::new(format!("Licence: {}", m["licence"].as_str().unwrap_or_default())).color(t.text_dim));
if let Some(size) = m["size"].as_u64() {
ui.label(RichText::new(format!("· {}", human_bytes(size))).color(t.text_dim));
}
for (label, key) in [("Project page", "homepage"), ("Licence", "licenceUrl")] {
if let Some(url) = m[key].as_str() {
let r = ui.link(label);
if r.clicked() {
ui.ctx().open_url(egui::OpenUrl::new_tab(url));
}
}
}
});
if classic {
return;
}
ui.horizontal(|ui| {
if !installed && !web {
let r = ui.add_enabled(busy.is_none(), egui::Button::new("Download"));
reg(app, &format!("settings.{prefix}.download.{id}"), &r, "Download");
if r.clicked() {
acts.push(Act::Run(format!("{prefix}.model.download"), json!({"id": id})));
}
}
if !web {
let r = ui.add_enabled(busy.is_none(), egui::Button::new("Install from File…"));
reg(app, &format!("settings.{prefix}.install.{id}"), &r, "Install from File");
if r.clicked() {
acts.push(Act::PickModel(task));
}
}
if installed {
let r = ui.add_enabled(busy.is_none(), egui::Button::new("Remove"));
reg(app, &format!("settings.{prefix}.remove.{id}"), &r, "Remove");
if r.clicked() {
acts.push(Act::Run(format!("{prefix}.model.remove"), json!({"id": id})));
}
}
});
});
}
if let Some(b) = &busy {
ui.horizontal(|ui| {
ui.spinner();
ui.label(b);
});
ui.ctx().request_repaint_after(std::time::Duration::from_millis(250));
}
if let Some(e) = info["error"].as_str() {
ui.label(RichText::new(e).color(t.danger));
}
if web {
ui.label(RichText::new("Trained models are available in the desktop app; the browser uses the classic engine.").color(t.text_dim));
} else if let Some(f) = info["folder"].as_str() {
ui.label(RichText::new(format!("Models folder: {f}")).color(t.text_faint));
}
}
/// Settings ▸ Disk ▸ Browser Storage (the web app's storage manager, `storage.*`): where the
/// data lives, the origin's usage and quota, persistent storage, and Clear buttons.
fn browser_storage_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, t: &Tokens, acts: &mut Vec<Act>) {
let Some(host) = app.session.storage.clone() else { return };
let info = host.info();
let u = |v: &Value| v.as_u64().unwrap_or(0);
ui.add_space(6.0);
ui.label(RichText::new("Browser Storage").font(Tokens::semibold(12.5)).color(t.tab_text_active));
ui.separator();
let backend = match info["backend"].as_str().unwrap_or("") {
"opfs" => "Origin Private File System",
"indexeddb" => "IndexedDB",
"memory" => "Memory only: nothing is kept after a reload",
"" => "Unknown",
other => other,
};
let r = ui.label(format!("Stored in: {backend}"));
reg(app, "settings.storage.backend", &r, backend);
let (usage, quota) = (u(&info["usage"]), u(&info["quota"]));
let frac = if quota > 0 { usage as f32 / quota as f32 } else { 0.0 };
let text = if quota > 0 { format!("{} of {} used ({:.1} %)", human_bytes(usage), human_bytes(quota), frac * 100.0) } else { "Usage unknown".into() };
let r = ui
.horizontal(|ui| {
ui.add(egui::ProgressBar::new(frac.clamp(0.0, 1.0)).desired_width(220.0).desired_height(8.0));
ui.label(&text);
})
.response;
reg(app, "settings.storage.usage", &r, &text);
let f = &info["files"];
let row = |what: &str, k: &str| format!("{what}: {} ({})", u(&f[k]["count"]), human_bytes(u(&f[k]["bytes"])));
ui.label(
RichText::new(format!("{} · {} · {}", row("Projects", "projects"), row("Imported media", "media"), row("Auto-saves", "autoSaves"))).color(t.text_dim),
);
let d = &info["diskCache"];
let dc = if d["enabled"].as_bool().unwrap_or(false) {
format!(
"Disk cache: {} frames, {} of {} (hits {}, misses {})",
u(&d["entries"]),
human_bytes(u(&d["bytes"])),
human_bytes(u(&d["maxBytes"])),
u(&d["hits"]),
u(&d["misses"])
)
} else {
"Disk cache: off".into()
};
let r = ui.label(RichText::new(&dc).color(t.text_dim));
reg(app, "settings.storage.diskCache", &r, &dc);
ui.horizontal(|ui| {
let persisted = info["persisted"].as_bool().unwrap_or(false);
let state = if persisted { "Persistent storage: granted" } else { "Persistent storage: not granted (the browser may clear it when space runs low)" };
ui.label(state);
if !persisted {
let r = ui.button("Request Persistent Storage");
reg(app, "settings.storage.persist", &r, "Request Persistent Storage");
if r.clicked() {
acts.push(Act::Run("storage.persist".into(), json!({})));
}
}
});
ui.horizontal_wrapped(|ui| {
for (what, label) in
[("diskCache", "Clear Disk Cache"), ("media", "Clear Imported Media"), ("autoSaves", "Clear Auto-Saves"), ("projects", "Clear Saved Projects")]
{
let r = ui.button(label);
reg(app, &format!("settings.storage.clear.{what}"), &r, label);
if r.clicked() {
acts.push(Act::Run("storage.clear".into(), json!({"what": what})));
}
}
});
// The numbers refresh in the background.
ui.ctx().request_repaint_after(std::time::Duration::from_secs(1));
}
2026-10-02 09:14:45 -04:00
fn labels_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, cur: &Value, acts: &mut Vec<Act>) {
ui.label("Label Colors and Names:");
ui.add_space(4.0);
let labels = cur.get("labels").and_then(Value::as_array).cloned().unwrap_or_default();
egui::Grid::new("settings-labels").num_columns(4).spacing([10.0, 4.0]).show(ui, |ui| {
for (i, l) in labels.iter().enumerate() {
let c = crate::panels::viewer::hex_rgb(l["color"].as_str().unwrap_or("")).unwrap_or([128, 128, 128]);
let mut rgb = c;
let r = ui.color_edit_button_srgb(&mut rgb);
app.auto.add(&format!("settings.labels.{i}.color"), r.rect, "label colour");
if rgb != c {
acts.push(Act::Set(format!("labels.{i}.color"), json!(hex(rgb))));
}
let mut name = l["name"].as_str().unwrap_or("").to_string();
let r = ui.add_sized(vec2(160.0, 20.0), egui::TextEdit::singleline(&mut name));
app.auto.add(&format!("settings.labels.{i}.name"), r.rect, "label name");
if r.changed() {
acts.push(Act::Set(format!("labels.{i}.name"), json!(name)));
}
if i % 2 == 1 {
ui.end_row();
}
}
});
ui.add_space(8.0);
let r = ui.button("Reset Labels");
app.auto.add("settings.button.Reset Labels", r.rect, "Reset Labels");
if r.clicked() {
acts.push(Act::Run("prefs.reset".into(), json!({"page": "labels"})));
}
}
pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
let all = pages();
let mut page = app.dialog_state.settings_page.clone();
if !all.iter().any(|p| p.id == page) {
page = "general".into();
}
let idx = all.iter().position(|p| p.id == page).unwrap_or(0);
let cur = serde_json::to_value(&app.session.prefs).unwrap_or_default();
let mut acts: Vec<Act> = vec![];
let (mut ok, mut cancel) = (false, false);
super::dialogs::modal(ctx, "Settings", vec2(820.0, 600.0), t, |ui| {
let body_h = (ctx.content_rect().height() - 170.0).clamp(120.0, 470.0);
2026-10-02 09:14:45 -04:00
ui.allocate_ui_with_layout(vec2(ui.available_width(), body_h), egui::Layout::left_to_right(egui::Align::Min), |ui| {
ui.set_height(body_h);
// Page list (left, like After Effects).
ui.vertical(|ui| {
ui.set_width(180.0);
egui::ScrollArea::vertical().id_salt("settings-pages").max_height(body_h).auto_shrink([false, false]).show(ui, |ui| {
for p in &all {
let (r, resp) = ui.allocate_exact_size(vec2(176.0, 24.0), egui::Sense::click());
let sel = page == p.id;
if sel {
ui.painter().rect_filled(r, 3.0, t.accent);
} else if resp.hovered() {
ui.painter().rect_filled(r, 3.0, t.hover);
}
ui.painter().text(
r.left_center() + vec2(10.0, 0.0),
egui::Align2::LEFT_CENTER,
p.title,
Tokens::ui(12.5),
if sel { Color32::WHITE } else { t.text },
);
app.auto.add(&format!("settings.page.{}", p.id), r, p.title);
if resp.clicked() {
page = p.id.to_string();
}
2026-10-02 09:14:45 -04:00
}
});
2026-10-02 09:14:45 -04:00
});
ui.separator();
ui.vertical(|ui| {
// The rest of the dialog's width: a fixed width ran past it, so the whole
// dialog scrolled sideways a little (#284).
ui.set_width(ui.available_width());
2026-10-02 09:14:45 -04:00
let p = &all[idx];
ui.label(RichText::new(p.title).font(Tokens::semibold(14.0)).color(t.tab_text_active));
ui.add_space(6.0);
egui::ScrollArea::vertical().max_height(body_h - 30.0).auto_shrink([false, false]).show(ui, |ui| {
page_ui(app, ui, p, &cur, t, &mut acts);
});
});
});
ui.add_space(8.0);
ui.separator();
ui.horizontal(|ui| {
let r = ui.add_enabled(idx > 0, egui::Button::new("Previous"));
app.auto.add("settings.previous", r.rect, "Previous");
if r.clicked() {
page = all[idx - 1].id.to_string();
}
let r = ui.add_enabled(idx + 1 < all.len(), egui::Button::new("Next"));
app.auto.add("settings.next", r.rect, "Next");
if r.clicked() {
page = all[idx + 1].id.to_string();
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let r = ui.add(egui::Button::new(RichText::new(" OK ").color(Color32::WHITE)).fill(t.accent));
app.auto.add("settings.ok", r.rect, "OK");
ok |= r.clicked();
let r = ui.button("Cancel");
app.auto.add("settings.cancel", r.rect, "Cancel");
cancel |= r.clicked();
});
});
});
app.dialog_state.settings_page = page;
for a in acts {
match a {
Act::Set(k, v) => {
if let Err(e) = app.session.prefs.set(&k, v) {
app.ui.status = e;
}
app.session.prefs_changed();
}
Act::Run(cmd, params) => {
if let Err(e) = crate::menus::invoke(app, ctx, &cmd, params) {
app.ui.status = e;
}
// Buttons such as Reset Settings change the baseline Cancel returns to.
if cmd.starts_with("prefs.") {
app.dialog_state.prefs_snapshot = Some(app.session.prefs.clone());
}
if app.dialog != Some(Dialog::Settings) && app.dialog != Some(Dialog::Info) {
app.dialog = Some(Dialog::Settings);
}
}
Act::PickFolder(k) => {
if let Some(f) = app.hooks.pick_folder.as_ref().and_then(|f| f()) {
let _ = app.session.prefs.set(&k, json!(f));
app.session.prefs_changed();
}
}
Act::PickProject(k) => {
if let Some(f) = app.hooks.pick_open_project.as_ref().and_then(|f| f()) {
let _ = app.session.prefs.set(&k, json!(f));
app.session.prefs_changed();
}
}
Act::PickModel(task) => {
// The registry's file types for the task (`.pt`, `.task`).
let mut exts: Vec<&str> = effectcraft_engine::segment::models(task).filter_map(|m| m.file_name.rsplit_once('.').map(|x| x.1)).collect();
exts.dedup();
let picked = app.hooks.pick_files.as_ref().map(|f| f(&exts)).unwrap_or_default();
let cmd = if task == Task::Face { "face.model.install" } else { "roto.model.install" };
if let Some(path) = picked.into_iter().next()
&& let Err(e) = crate::menus::invoke(app, ctx, cmd, json!({"path": path}))
{
app.ui.status = e;
}
}
2026-10-02 09:14:45 -04:00
}
}
if cancel {
if let Some(p) = app.dialog_state.prefs_snapshot.take() {
app.session.prefs = p;
app.session.prefs_changed();
}
app.dialog = None;
} else if ok {
app.dialog_state.prefs_snapshot = None;
app.session.save_prefs();
app.dialog = None;
}
}
2026-10-02 09:15:04 -04:00
/// Crash recovery: the previous session didn't exit cleanly; offer its latest auto-save.
pub fn recovery(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
let Some(r) = app.recovery.clone() else {
app.dialog = None;
return;
};
let mut choice: Option<&str> = None;
super::dialogs::modal(ctx, "Recover Project", vec2(560.0, 230.0), t, |ui| {
ui.label("EffectCraft didn't quit normally last time.");
ui.add_space(6.0);
if let Some(p) = &r.project {
ui.label(format!("Project: {p}"));
}
if let Some(a) = &r.autosave {
let when = std::fs::metadata(a).and_then(|m| m.modified()).ok().and_then(|m| m.elapsed().ok()).map(|d| {
let m = d.as_secs() / 60;
if m < 1 {
"less than a minute ago".to_string()
} else if m < 120 {
format!("{m} minutes ago")
} else {
format!("{} hours ago", m / 60)
}
});
ui.label(format!("Latest auto-save: {a}"));
if let Some(w) = when {
ui.label(RichText::new(format!("Saved {w}")).color(t.text_dim));
}
}
ui.add_space(14.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let b = ui.add(egui::Button::new(RichText::new(" Open Auto-Save ").color(Color32::WHITE)).fill(t.accent));
app.auto.add("recovery.openAutoSave", b.rect, "Open Auto-Save");
if b.clicked() {
choice = Some("autosave");
}
if r.project.is_some() {
let b = ui.button("Open Last Saved Project");
app.auto.add("recovery.openProject", b.rect, "Open Last Saved Project");
if b.clicked() {
choice = Some("project");
}
}
let b = ui.button("Don't Recover");
app.auto.add("recovery.dismiss", b.rect, "Don't Recover");
if b.clicked() {
choice = Some("none");
}
});
});
let Some(c) = choice else { return };
app.dialog = None;
app.recovery = None;
let path = match c {
"autosave" => r.autosave,
"project" => r.project,
_ => None,
};
if let Some(p) = path
&& let Err(e) = crate::menus::invoke(app, ctx, "file.open", json!({"path": p}))
{
app.ui.status = e;
}
}