From 7aeac39e7fb97dc57ca278f1c097058275c20aa2 Mon Sep 17 00:00:00 2001 From: Vladimir Stoilov Date: Mon, 29 Jul 2024 16:26:13 +0300 Subject: [PATCH] feat(core): make setting of gtk app id optional (#10397) * feat(core): make setting of gtk app id optional * Fix change file * Update .changes/linux-option-gtk-app-id.md Co-authored-by: Fabian-Lars * [skip ci] Update linux-option-gtk-app-id.md * Update app.rs * Update app.rs --------- Co-authored-by: Fabian-Lars --- .changes/linux-option-gtk-app-id.md | 6 ++++++ core/tauri-config-schema/schema.json | 6 ++++++ core/tauri-utils/src/config.rs | 8 +++++++- core/tauri/src/app.rs | 8 +++++++- core/tauri/src/test/mod.rs | 1 + tooling/cli/schema.json | 6 ++++++ 6 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 .changes/linux-option-gtk-app-id.md diff --git a/.changes/linux-option-gtk-app-id.md b/.changes/linux-option-gtk-app-id.md new file mode 100644 index 000000000..f050fd6a7 --- /dev/null +++ b/.changes/linux-option-gtk-app-id.md @@ -0,0 +1,6 @@ +--- +"tauri-utils": "patch:enhance" +"tauri": "patch:enhance" +--- + +Make the set of gtk application id optional, to allow more then one instance of the app running at the same time. diff --git a/core/tauri-config-schema/schema.json b/core/tauri-config-schema/schema.json index b2c168b6e..91f179323 100644 --- a/core/tauri-config-schema/schema.json +++ b/core/tauri-config-schema/schema.json @@ -34,6 +34,7 @@ "app": { "description": "The App configuration.", "default": { + "enableGTKAppId": false, "macOSPrivateApi": false, "security": { "assetProtocol": { @@ -195,6 +196,11 @@ "description": "Whether we should inject the Tauri API on `window.__TAURI__` or not.", "default": false, "type": "boolean" + }, + "enableGTKAppId": { + "description": "If set to true \"identifier\" will be set as GTK app ID (on systems that use GTK).", + "default": false, + "type": "boolean" } }, "additionalProperties": false diff --git a/core/tauri-utils/src/config.rs b/core/tauri-utils/src/config.rs index 90e41c635..eab684af0 100644 --- a/core/tauri-utils/src/config.rs +++ b/core/tauri-utils/src/config.rs @@ -1803,6 +1803,9 @@ pub struct AppConfig { /// Whether we should inject the Tauri API on `window.__TAURI__` or not. #[serde(default, alias = "with-global-tauri")] pub with_global_tauri: bool, + /// If set to true "identifier" will be set as GTK app ID (on systems that use GTK). + #[serde(rename = "enableGTKAppId", alias = "enable-gtk-app-id", default)] + pub enable_gtk_app_id: bool, } impl AppConfig { @@ -2732,6 +2735,7 @@ mod build { let tray_icon = opt_lit(self.tray_icon.as_ref()); let macos_private_api = self.macos_private_api; let with_global_tauri = self.with_global_tauri; + let enable_gtk_app_id = self.enable_gtk_app_id; literal_struct!( tokens, @@ -2740,7 +2744,8 @@ mod build { security, tray_icon, macos_private_api, - with_global_tauri + with_global_tauri, + enable_gtk_app_id ); } } @@ -2817,6 +2822,7 @@ mod test { tray_icon: None, macos_private_api: false, with_global_tauri: false, + enable_gtk_app_id: false, }; // create a build config diff --git a/core/tauri/src/app.rs b/core/tauri/src/app.rs index 4b76f89de..eb1c8b471 100644 --- a/core/tauri/src/app.rs +++ b/core/tauri/src/app.rs @@ -1706,6 +1706,12 @@ tauri::Builder::default() self.invoke_key, )); + let app_id = if manager.config.app.enable_gtk_app_id { + Some(manager.config.identifier.clone()) + } else { + None + }; + let runtime_args = RuntimeInitArgs { #[cfg(any( target_os = "linux", @@ -1714,7 +1720,7 @@ tauri::Builder::default() target_os = "netbsd", target_os = "openbsd" ))] - app_id: Some(manager.config.identifier.clone()), + app_id, #[cfg(windows)] msg_hook: { diff --git a/core/tauri/src/test/mod.rs b/core/tauri/src/test/mod.rs index c33e38544..b7ecc9021 100644 --- a/core/tauri/src/test/mod.rs +++ b/core/tauri/src/test/mod.rs @@ -113,6 +113,7 @@ pub fn mock_context>(assets: A) -> crate::Context { security: Default::default(), tray_icon: None, macos_private_api: false, + enable_gtk_app_id: false, }, bundle: Default::default(), build: Default::default(), diff --git a/tooling/cli/schema.json b/tooling/cli/schema.json index b2c168b6e..91f179323 100644 --- a/tooling/cli/schema.json +++ b/tooling/cli/schema.json @@ -34,6 +34,7 @@ "app": { "description": "The App configuration.", "default": { + "enableGTKAppId": false, "macOSPrivateApi": false, "security": { "assetProtocol": { @@ -195,6 +196,11 @@ "description": "Whether we should inject the Tauri API on `window.__TAURI__` or not.", "default": false, "type": "boolean" + }, + "enableGTKAppId": { + "description": "If set to true \"identifier\" will be set as GTK app ID (on systems that use GTK).", + "default": false, + "type": "boolean" } }, "additionalProperties": false