Skip to content

Commit d98c51a

Browse files
authored
Merge pull request #666 from multiplex55/codex/inspect-and-improve-settings-command-flow
Harden settings dialog activation and error handling
2 parents ad77978 + f5fefd3 commit d98c51a

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

src/gui/mod.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,29 @@ impl LauncherApp {
526526
self.error = Some(msg);
527527
self.error_time = Some(Instant::now());
528528
}
529+
530+
fn open_settings_dialog(&mut self) {
531+
if !self.show_settings {
532+
match Settings::load(&self.settings_path) {
533+
Ok(settings) => {
534+
self.settings_editor = SettingsEditor::new_with_plugins(&settings);
535+
}
536+
Err(e) => {
537+
let msg = format!("Failed to load settings: {e}");
538+
self.set_error(msg.clone());
539+
if self.enable_toasts {
540+
self.add_toast(Toast {
541+
text: msg.into(),
542+
kind: ToastKind::Error,
543+
options: ToastOptions::default()
544+
.duration_in_seconds(self.toast_duration as f64),
545+
});
546+
}
547+
}
548+
}
549+
}
550+
self.show_settings = true;
551+
}
529552
pub fn update_paths(
530553
&mut self,
531554
plugin_dirs: Option<Vec<String>>,
@@ -1554,7 +1577,7 @@ impl LauncherApp {
15541577
} else if a.action == "tempfile:dialog" {
15551578
self.tempfile_dialog.open();
15561579
} else if a.action == "settings:dialog" {
1557-
self.show_settings = true;
1580+
self.open_settings_dialog();
15581581
} else if a.action == "dashboard:settings" {
15591582
let registry = self.dashboard.registry().clone();
15601583
self.dashboard_editor.open(&self.dashboard_path, &registry);
@@ -2252,7 +2275,7 @@ impl LauncherApp {
22522275
Panel::CpuListDialog => self.cpu_list_dialog.open = true,
22532276
Panel::ToastLogDialog => self.toast_log_dialog.open = true,
22542277
Panel::Editor => self.show_editor = true,
2255-
Panel::Settings => self.show_settings = true,
2278+
Panel::Settings => self.open_settings_dialog(),
22562279
Panel::Plugins => self.show_plugins = true,
22572280
}
22582281
if !self.panel_stack.contains(&panel) {

src/plugins/settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Plugin for SettingsPlugin {
4747
Action {
4848
label: "settings".into(),
4949
desc: "Settings".into(),
50-
action: "query:settings".into(),
50+
action: "settings:dialog".into(),
5151
args: None,
5252
},
5353
Action {

src/settings_editor.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,16 @@ impl SettingsEditor {
812812
}
813813
}
814814
Err(e) => {
815-
app.set_error(format!("Failed to read settings: {e}"))
815+
let msg = format!("Failed to read settings: {e}");
816+
app.set_error(msg.clone());
817+
if app.enable_toasts {
818+
app.add_toast(Toast {
819+
text: msg.into(),
820+
kind: ToastKind::Error,
821+
options: ToastOptions::default()
822+
.duration_in_seconds(app.toast_duration as f64),
823+
});
824+
}
816825
}
817826
}
818827
}

0 commit comments

Comments
 (0)