|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
#![cfg(target_os = "linux")]
|
|
|
|
|
|
|
|
|
|
use crate::SingleInstanceCallback;
|
|
|
|
|
use std::{cell::RefCell, rc::Rc};
|
|
|
|
|
use tauri::{
|
|
|
|
|
plugin::{self, TauriPlugin},
|
|
|
|
|
Manager, RunEvent, Runtime,
|
|
|
|
@ -12,7 +11,6 @@ use zbus::{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ConnectionHandle(Connection);
|
|
|
|
|
const CLOSE_NEW_INSTANCE_ID: u32 = 1542;
|
|
|
|
|
|
|
|
|
|
struct SingleInstanceDBus {
|
|
|
|
|
callback: Box<SingleInstanceCallback>,
|
|
|
|
@ -20,19 +18,8 @@ struct SingleInstanceDBus {
|
|
|
|
|
|
|
|
|
|
#[dbus_interface(name = "org.SingleInstance.DBus")]
|
|
|
|
|
impl SingleInstanceDBus {
|
|
|
|
|
fn execute_callback(&mut self, argv: Vec<String>, cwd: String) -> u32 {
|
|
|
|
|
let ret = Rc::new(RefCell::new(1));
|
|
|
|
|
let ret_c = Rc::clone(&ret);
|
|
|
|
|
|
|
|
|
|
(self.callback)(
|
|
|
|
|
argv,
|
|
|
|
|
cwd,
|
|
|
|
|
Box::new(move || {
|
|
|
|
|
let mut ret = ret_c.borrow_mut();
|
|
|
|
|
*ret = CLOSE_NEW_INSTANCE_ID;
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
ret.take()
|
|
|
|
|
fn execute_callback(&mut self, argv: Vec<String>, cwd: String) {
|
|
|
|
|
(self.callback)(argv, cwd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -56,8 +43,8 @@ pub fn init<R: Runtime>(f: Box<SingleInstanceCallback>) -> TauriPlugin<R> {
|
|
|
|
|
app.manage(ConnectionHandle(connection));
|
|
|
|
|
}
|
|
|
|
|
Err(zbus::Error::NameTaken) => {
|
|
|
|
|
let connection = Connection::session().unwrap();
|
|
|
|
|
if let Ok(m) = connection.call_method(
|
|
|
|
|
if let Ok(connection) = Connection::session() {
|
|
|
|
|
let _ = connection.call_method(
|
|
|
|
|
Some(dbus_name.as_str()),
|
|
|
|
|
dbus_path.as_str(),
|
|
|
|
|
Some("org.SingleInstance.DBus"),
|
|
|
|
@ -69,12 +56,9 @@ pub fn init<R: Runtime>(f: Box<SingleInstanceCallback>) -> TauriPlugin<R> {
|
|
|
|
|
.to_str()
|
|
|
|
|
.unwrap_or_default(),
|
|
|
|
|
),
|
|
|
|
|
) {
|
|
|
|
|
let reply: u32 = m.body().unwrap_or_default();
|
|
|
|
|
if reply == CLOSE_NEW_INSTANCE_ID {
|
|
|
|
|
std::process::exit(0);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
std::process::exit(0)
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|