disable hotkeys if initial registration fails

This commit is contained in:
Joseph Montanaro 2023-10-09 08:50:31 -07:00
parent 2079f99d04
commit 1b749a857c
4 changed files with 15 additions and 4 deletions

View File

@ -82,7 +82,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,8 +100,12 @@ async fn setup(app: &mut App) -> Result<(), Box<dyn Error>> {
if let Err(_e) = config::set_auto_launch(conf.start_on_login) {
setup_errors.push("Error: Failed to manage autolaunch.".into());
}
if let Err(e) = shortcuts::register_hotkeys(&conf.hotkeys) {
setup_errors.push(format!("{e}"));
// if hotkeys fail to register, disable them so that this error doesn't have to keep showing up
if let Err(_e) = shortcuts::register_hotkeys(&conf.hotkeys) {
conf.hotkeys.disable_all();
conf.save(&pool).await?;
setup_errors.push("Failed to register hotkeys. Hotkey settings have been disabled.".into());
}
// if session is empty, this is probably the first launch, so don't autohide

View File

@ -33,6 +33,13 @@ pub struct HotkeysConfig {
pub launch_terminal: Hotkey,
}
impl HotkeysConfig {
pub fn disable_all(&mut self) {
self.show_window.enabled = false;
self.launch_terminal.enabled = false;
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct AppConfig {

View File

@ -1,6 +1,7 @@
<script>
import { onMount } from 'svelte';
import { invoke } from '@tauri-apps/api/tauri';
import { emit } from '@tauri-apps/api/event';
import { getRootCause } from '../lib/errors.js';
import { appState } from '../lib/state.js';

View File

@ -20,7 +20,6 @@
let error = null;
async function save() {
console.log('updating config');
try {
await invoke('save_config', {config});
$appState.config = await invoke('get_config');