From 367a140e2ab3bc30c2073b40c395446f8d49a991 Mon Sep 17 00:00:00 2001 From: Joseph Montanaro Date: Thu, 21 Sep 2023 14:55:02 -0700 Subject: [PATCH] disable keyboard shortcuts if registration fails --- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/src/app.rs | 4 +++- src-tauri/src/config.rs | 9 ++++++++- src-tauri/tauri.conf.json | 2 +- 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 41fdfcd..cadea19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "creddy", - "version": "0.3.3", + "version": "0.3.4", "scripts": { "dev": "vite", "build": "vite build", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index c03df5c..25e9d84 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1035,7 +1035,7 @@ dependencies = [ [[package]] name = "creddy" -version = "0.3.2" +version = "0.3.4" dependencies = [ "argon2", "auto-launch", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 2779185..475298c 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "creddy" -version = "0.3.3" +version = "0.3.4" description = "A friendly AWS credentials manager" authors = ["Joseph Montanaro"] license = "" diff --git a/src-tauri/src/app.rs b/src-tauri/src/app.rs index 63cc441..5db14c3 100644 --- a/src-tauri/src/app.rs +++ b/src-tauri/src/app.rs @@ -81,7 +81,7 @@ async fn setup(app: &mut App) -> Result<(), Box> { let pool = connect_db().await?; let mut setup_errors: Vec = vec![]; - let conf = match AppConfig::load(&pool).await { + let mut conf = match AppConfig::load(&pool).await { Ok(c) => c, Err(SetupError::ConfigParseError(_)) => { setup_errors.push( @@ -100,6 +100,8 @@ async fn setup(app: &mut App) -> Result<(), Box> { setup_errors.push("Error: Failed to manage autolaunch.".into()); } if let Err(e) = config::register_hotkeys(&conf.hotkeys) { + conf.hotkeys.show_window.enabled = false; + conf.hotkeys.launch_terminal.enabled = false; setup_errors.push(format!("{e}")); } diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs index 37e2891..96cf5f6 100644 --- a/src-tauri/src/config.rs +++ b/src-tauri/src/config.rs @@ -202,10 +202,17 @@ fn default_hotkey_config() -> HotkeysConfig { // note: will panic if called before APP is set pub fn register_hotkeys(hotkeys: &HotkeysConfig) -> tauri::Result<()> { + let app = crate::app::APP.get().unwrap(); let mut manager = app.global_shortcut_manager(); - manager.unregister_all()?; + if let Err(_e) = manager.unregister_all() { + if !hotkeys.show_window.enabled && !hotkeys.launch_terminal.enabled { + // if both are disabled and we failed to unregister, then probably + // we also failed to register in the first place + return Ok(()) + } + } if hotkeys.show_window.enabled { let handle = app.app_handle(); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 6fcdc2a..e9f80b7 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "creddy", - "version": "0.3.3" + "version": "0.3.4" }, "tauri": { "allowlist": {