mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-26 21:41:48 +02:00
fix: use bundle identifier in dbus path and name (#10)
This commit is contained in:
Generated
+12
-14
@@ -1715,12 +1715,11 @@ checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nix"
|
name = "nix"
|
||||||
version = "0.23.1"
|
version = "0.24.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6"
|
checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cc",
|
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
"memoffset",
|
"memoffset",
|
||||||
@@ -3969,9 +3968,9 @@ checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zbus"
|
name = "zbus"
|
||||||
version = "2.3.2"
|
version = "3.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2d8f1a037b2c4a67d9654dc7bdfa8ff2e80555bbefdd3c1833c1d1b27c963a6b"
|
checksum = "1faa83cd7c79d3a669220c634528577b98ff43c35aa7c827ab3e9990692f7868"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-broadcast",
|
"async-broadcast",
|
||||||
"async-channel",
|
"async-channel",
|
||||||
@@ -3990,7 +3989,6 @@ dependencies = [
|
|||||||
"futures-sink",
|
"futures-sink",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"hex",
|
"hex",
|
||||||
"lazy_static",
|
|
||||||
"nix",
|
"nix",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"ordered-stream",
|
"ordered-stream",
|
||||||
@@ -4009,9 +4007,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zbus_macros"
|
name = "zbus_macros"
|
||||||
version = "2.3.2"
|
version = "3.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1f8fb5186d1c87ae88cf234974c240671238b4a679158ad3b94ec465237349a6"
|
checksum = "fd5874c328b945cab1865a299e31f855072fa528bafbbfa3249394b352d5742b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro-crate",
|
"proc-macro-crate",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@@ -4022,9 +4020,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zbus_names"
|
name = "zbus_names"
|
||||||
version = "2.1.0"
|
version = "2.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "45dfcdcf87b71dad505d30cc27b1b7b88a64b6d1c435648f48f9dbc1fdc4b7e1"
|
checksum = "41a408fd8a352695690f53906dc7fd036be924ec51ea5e05666ff42685ed0af5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
@@ -4033,9 +4031,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zvariant"
|
name = "zvariant"
|
||||||
version = "3.4.1"
|
version = "3.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf2c71467724d4a77f0a1f0339dab10ca5d63f6a82411289cdcdfbfd47d2e407"
|
checksum = "1bd68e4e6432ef19df47d7e90e2e72b5e7e3d778e0ae3baddf12b951265cc758"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"enumflags2",
|
"enumflags2",
|
||||||
@@ -4047,9 +4045,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zvariant_derive"
|
name = "zvariant_derive"
|
||||||
version = "3.4.1"
|
version = "3.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2c47f3630ce926a03abf21f5a8db90c60c81ed71599b5c86ad1a54fd3c7564c5"
|
checksum = "08e977eaa3af652f63d479ce50d924254ad76722a6289ec1a1eac3231ca30430"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro-crate",
|
"proc-macro-crate",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
|
|||||||
@@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
use crate::SingleInstanceCallback;
|
use crate::SingleInstanceCallback;
|
||||||
use tauri::{
|
use tauri::{
|
||||||
AppHandle,
|
|
||||||
plugin::{self, TauriPlugin},
|
plugin::{self, TauriPlugin},
|
||||||
Manager, RunEvent, Runtime,
|
AppHandle, Manager, RunEvent, Runtime,
|
||||||
};
|
};
|
||||||
use zbus::{
|
use zbus::{
|
||||||
blocking::{Connection, ConnectionBuilder},
|
blocking::{Connection, ConnectionBuilder},
|
||||||
@@ -19,22 +18,31 @@ struct SingleInstanceDBus<R: Runtime> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[dbus_interface(name = "org.SingleInstance.DBus")]
|
#[dbus_interface(name = "org.SingleInstance.DBus")]
|
||||||
impl<R:Runtime> SingleInstanceDBus<R> {
|
impl<R: Runtime> SingleInstanceDBus<R> {
|
||||||
fn execute_callback(&mut self, argv: Vec<String>, cwd: String) {
|
fn execute_callback(&mut self, argv: Vec<String>, cwd: String) {
|
||||||
(self.callback)(&self.app_handle, argv, cwd);
|
(self.callback)(&self.app_handle, argv, cwd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dbus_id<R: Runtime>(app: &AppHandle<R>) -> String {
|
||||||
|
app.config()
|
||||||
|
.tauri
|
||||||
|
.bundle
|
||||||
|
.identifier
|
||||||
|
.replace('.', "_")
|
||||||
|
.replace('-', "_")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn init<R: Runtime>(f: Box<SingleInstanceCallback<R>>) -> TauriPlugin<R> {
|
pub fn init<R: Runtime>(f: Box<SingleInstanceCallback<R>>) -> TauriPlugin<R> {
|
||||||
plugin::Builder::new("single-instance")
|
plugin::Builder::new("single-instance")
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
let app_name = app.package_info().name.clone();
|
let id = dbus_id(app);
|
||||||
let single_instance_dbus = SingleInstanceDBus {
|
let single_instance_dbus = SingleInstanceDBus {
|
||||||
callback: f,
|
callback: f,
|
||||||
app_handle: app.clone(),
|
app_handle: app.clone(),
|
||||||
};
|
};
|
||||||
let dbus_name = format!("org.{}.SingleInstance", app_name);
|
let dbus_name = format!("org.{}.SingleInstance", id);
|
||||||
let dbus_path = format!("/org/{}/SingleInstance", app_name);
|
let dbus_path = format!("/org/{}/SingleInstance", id);
|
||||||
|
|
||||||
match ConnectionBuilder::session()
|
match ConnectionBuilder::session()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -73,8 +81,7 @@ pub fn init<R: Runtime>(f: Box<SingleInstanceCallback<R>>) -> TauriPlugin<R> {
|
|||||||
.on_event(|app, event| {
|
.on_event(|app, event| {
|
||||||
if let RunEvent::Exit = event {
|
if let RunEvent::Exit = event {
|
||||||
if let Some(connection) = app.try_state::<ConnectionHandle>() {
|
if let Some(connection) = app.try_state::<ConnectionHandle>() {
|
||||||
let app_name = app.package_info().name.clone();
|
let dbus_name = format!("org.{}.SingleInstance", dbus_id(app));
|
||||||
let dbus_name = format!("org.{}.SingleInstance", app_name);
|
|
||||||
let _ = connection.0.release_name(dbus_name);
|
let _ = connection.0.release_name(dbus_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user