Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add EventLoopBuilderExtUnix::with_app_id on Linux #912

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/app_id_gtk.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 10 additions & 0 deletions src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: Into<String>>(&mut self, id: S) -> &mut Self;
}

impl<T> EventLoopBuilderExtUnix for EventLoopBuilder<T> {
Expand All @@ -46,6 +51,11 @@ impl<T> EventLoopBuilderExtUnix for EventLoopBuilder<T> {
self.platform_specific.any_thread = any_thread;
self
}

fn with_app_id<S: Into<String>>(&mut self, id: S) -> &mut Self {
self.platform_specific.app_id = Some(id.into());
self
}
}

/// Additional methods on `Window` that are specific to Unix.
Expand Down
11 changes: 7 additions & 4 deletions src/platform_impl/linux/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ pub struct EventLoop<T: 'static> {
run_device_thread: Option<Rc<AtomicBool>>,
}

#[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<String>,
}

impl<T: 'static> EventLoop<T> {
Expand All @@ -184,13 +185,15 @@ impl<T: 'static> EventLoop<T> {

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<EventLoop<T>, Box<dyn Error>> {
fn new_gtk(app_id: Option<&str>) -> Result<EventLoop<T>, Box<dyn Error>> {
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)?;
Expand Down
2 changes: 0 additions & 2 deletions src/platform_impl/linux/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading