diff --git a/.changes/app_id_gtk.md b/.changes/app_id_gtk.md new file mode 100644 index 000000000..6d7549700 --- /dev/null +++ b/.changes/app_id_gtk.md @@ -0,0 +1,5 @@ +--- +"tao": "patch" +--- + +Add `EventLoopBuilderExtUnix::with_app_id` on Linux to allow setting a unique app id for the underlying gtk application. diff --git a/src/platform/unix.rs b/src/platform/unix.rs index e479778cb..c7c49328c 100644 --- a/src/platform/unix.rs +++ b/src/platform/unix.rs @@ -38,6 +38,11 @@ pub trait EventLoopBuilderExtUnix { /// terminates. Attempting to use a `Window` after its parent thread terminates has /// unspecified, although explicitly not undefined, behavior. fn with_any_thread(&mut self, any_thread: bool) -> &mut Self; + + /// Set the gtk application id. + /// + /// If no application ID is given then some features (most notably application uniqueness) will be disabled. + fn with_app_id>(&mut self, id: S) -> &mut Self; } impl EventLoopBuilderExtUnix for EventLoopBuilder { @@ -46,6 +51,11 @@ impl EventLoopBuilderExtUnix for EventLoopBuilder { self.platform_specific.any_thread = any_thread; self } + + fn with_app_id>(&mut self, id: S) -> &mut Self { + self.platform_specific.app_id = Some(id.into()); + self + } } /// Additional methods on `Window` that are specific to Unix. diff --git a/src/platform_impl/linux/event_loop.rs b/src/platform_impl/linux/event_loop.rs index 8cf68e622..2e8bc27a6 100644 --- a/src/platform_impl/linux/event_loop.rs +++ b/src/platform_impl/linux/event_loop.rs @@ -171,9 +171,10 @@ pub struct EventLoop { run_device_thread: Option>, } -#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)] pub(crate) struct PlatformSpecificEventLoopAttributes { pub(crate) any_thread: bool, + pub(crate) app_id: Option, } impl EventLoop { @@ -184,13 +185,15 @@ impl EventLoop { let context = MainContext::default(); context - .with_thread_default(|| EventLoop::new_gtk().expect("Failed to initialize gtk backend!")) + .with_thread_default(|| { + EventLoop::new_gtk(attrs.app_id.as_deref()).expect("Failed to initialize gtk backend!") + }) .expect("Failed to initialize gtk backend!") } - fn new_gtk() -> Result, Box> { + fn new_gtk(app_id: Option<&str>) -> Result, Box> { let context = MainContext::default(); - let app = gtk::Application::new(None, gio::ApplicationFlags::empty()); + let app = gtk::Application::new(app_id, gio::ApplicationFlags::empty()); let app_ = app.clone(); let cancellable: Option<&Cancellable> = None; app.register(cancellable)?; diff --git a/src/platform_impl/linux/icon.rs b/src/platform_impl/linux/icon.rs index 7cdfff990..bc1c18df1 100644 --- a/src/platform_impl/linux/icon.rs +++ b/src/platform_impl/linux/icon.rs @@ -2,8 +2,6 @@ // Copyright 2021-2023 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 -use std::{fs::File, io::BufWriter, path::Path}; - use gtk::gdk_pixbuf::{Colorspace, Pixbuf}; use crate::window::BadIcon;