diff --git a/src-tauri/src/application_watcher.rs b/src-tauri/src/application_watcher.rs index fd1c6604..7b8007a6 100644 --- a/src-tauri/src/application_watcher.rs +++ b/src-tauri/src/application_watcher.rs @@ -40,24 +40,26 @@ pub fn init_application_watcher() { }; if app_name != previous { - let application_profiles = &APPLICATION_PROFILES.read().await.value; - let application = application_profiles.get(&app_name); - let default = application_profiles.get("opendeck_default"); - for value in crate::shared::DEVICES.iter() { - let device = value.key(); - let Some(profile) = application.and_then(|d| d.get(device)).or(default.and_then(|d| d.get(device))) else { - continue; - }; - if crate::store::profiles::DEVICE_STORES.write().await.get_selected_profile(device).ok().as_ref() == Some(profile) { - continue; + if crate::store::get_settings().value.autoswitch { + let application_profiles = &APPLICATION_PROFILES.read().await.value; + let application = application_profiles.get(&app_name); + let default = application_profiles.get("opendeck_default"); + for value in crate::shared::DEVICES.iter() { + let device = value.key(); + let Some(profile) = application.and_then(|d| d.get(device)).or(default.and_then(|d| d.get(device))) else { + continue; + }; + if crate::store::profiles::DEVICE_STORES.write().await.get_selected_profile(device).ok().as_ref() == Some(profile) { + continue; + } + let _ = app_handle.get_webview_window("main").unwrap().emit( + "switch_profile", + SwitchProfileEvent { + device: device.clone(), + profile: profile.clone(), + }, + ); } - let _ = app_handle.get_webview_window("main").unwrap().emit( - "switch_profile", - SwitchProfileEvent { - device: device.clone(), - profile: profile.clone(), - }, - ); } previous = app_name; } diff --git a/src-tauri/src/store/mod.rs b/src-tauri/src/store/mod.rs index d0109b06..fc693fc5 100644 --- a/src-tauri/src/store/mod.rs +++ b/src-tauri/src/store/mod.rs @@ -140,6 +140,7 @@ pub struct Settings { pub separatewine: bool, pub developer: bool, pub disableelgato: bool, + pub autoswitch: bool, } impl Default for Settings { @@ -159,6 +160,7 @@ impl Default for Settings { separatewine: false, developer: false, disableelgato: false, + autoswitch: true, } } } diff --git a/src/components/SettingsView.svelte b/src/components/SettingsView.svelte index 04310cd2..9adc3a9d 100644 --- a/src/components/SettingsView.svelte +++ b/src/components/SettingsView.svelte @@ -114,6 +114,12 @@ +
+ + + {$t("settings.autoswitch.tooltip")} +
+
diff --git a/src/lib/settings.ts b/src/lib/settings.ts index 08115657..f357c182 100644 --- a/src/lib/settings.ts +++ b/src/lib/settings.ts @@ -12,6 +12,7 @@ export type Settings = { separatewine: boolean; developer: boolean; disableelgato: boolean; + autoswitch: boolean; }; import { invoke } from "@tauri-apps/api/core"; diff --git a/translations/de.json b/translations/de.json index 7b293a17..fb05e501 100644 --- a/translations/de.json +++ b/translations/de.json @@ -113,6 +113,8 @@ "settings.autolaunch": "Beim Anmelden starten:", "settings.autolaunch.tooltip.1": "Wenn diese Option aktiviert ist, wird {{PRODUCT_NAME}} automatisch beim Anmelden gestartet.", "settings.autolaunch.tooltip.2": "Wenn du {{PRODUCT_NAME}} mit Flatpak installiert hast, funktioniert diese Option möglicherweise nicht wie vorgesehen", + "settings.autoswitch": "Profil-Autoumschaltung aktivieren:", + "settings.autoswitch.tooltip": "Wenn diese Option aktiviert ist, wechselt das aktive Profil automatisch basierend auf der aktuell fokussierten Anwendung.", "settings.background": "Im Hintergrund weiterlaufen lassen:", "settings.background.tooltip": "Wenn diese Option aktiviert ist, wird {{PRODUCT_NAME}} in das System-Tray minimiert und im Hintergrund ausgeführt.", "settings.backup_config.button": "Konfiguration sichern", diff --git a/translations/en.json b/translations/en.json index dc9076c3..1681c8fd 100644 --- a/translations/en.json +++ b/translations/en.json @@ -113,6 +113,8 @@ "settings.autolaunch": "Start at login:", "settings.autolaunch.tooltip.1": "If this option is enabled, {{PRODUCT_NAME}} will automatically start at login.", "settings.autolaunch.tooltip.2": "If you used Flatpak to install {{PRODUCT_NAME}}, this option may not function as intended.", + "settings.autoswitch": "Enable profile auto switching:", + "settings.autoswitch.tooltip": "If this option is enabled, the active profile will switch automatically based on the currently focussed application.", "settings.background": "Run in background:", "settings.background.tooltip": "If this option is enabled, {{PRODUCT_NAME}} will minimise to the tray and run in the background.", "settings.backup_config.button": "Back up config",