disable keyboard shortcuts if registration fails

This commit is contained in:
Joseph Montanaro 2023-09-21 14:55:02 -07:00
parent 3d093a3a45
commit 367a140e2a
6 changed files with 15 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"name": "creddy",
"version": "0.3.3",
"version": "0.3.4",
"scripts": {
"dev": "vite",
"build": "vite build",

2
src-tauri/Cargo.lock generated
View File

@ -1035,7 +1035,7 @@ dependencies = [
[[package]]
name = "creddy"
version = "0.3.2"
version = "0.3.4"
dependencies = [
"argon2",
"auto-launch",

View File

@ -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 = ""

View File

@ -81,7 +81,7 @@ async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
let pool = connect_db().await?;
let mut setup_errors: Vec<String> = 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<dyn Error>> {
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}"));
}

View File

@ -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();

View File

@ -8,7 +8,7 @@
},
"package": {
"productName": "creddy",
"version": "0.3.3"
"version": "0.3.4"
},
"tauri": {
"allowlist": {