Skip to content

Commit

Permalink
shortcuts actually (de)serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
samclane committed Dec 11, 2024
1 parent e8a350b commit d82b5ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ impl Default for MantleApp {
impl MantleApp {
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
if let Some(storage) = cc.storage {
return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default();
let mut app =
eframe::get_value::<MantleApp>(storage, eframe::APP_KEY).unwrap_or_default();
for shortcut in app.settings.custom_shortcuts.clone() {
if let Err(e) = app.shortcut_manager.add_action(shortcut.clone()) {
log::error!("Failed to add shortcut action: {}", e);
}
}
return app;
}
Default::default()
}
Expand Down
11 changes: 10 additions & 1 deletion src/shortcut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Display for KeyboardShortcut {
}
}

#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct KeyboardShortcutAction {
pub shortcut: KeyboardShortcut,
pub action: UserAction,
Expand Down Expand Up @@ -105,6 +105,15 @@ impl ShortcutManager {
}
}

pub fn add_action<'a>(
&'a mut self,
action: KeyboardShortcutAction,
) -> Result<(), Box<dyn std::error::Error + 'a>> {
let mut shortcuts = self.shortcuts.lock()?;
shortcuts.push(action);
Ok(())
}

pub fn add_shortcut(
&self,
name: String,
Expand Down

0 comments on commit d82b5ae

Please sign in to comment.