mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-10-18 23:07:27 +02:00
fix(single-instance): propagate D-Bus setup and handoff errors (#3584)
* fix(single-instance): propagate D-Bus setup and handoff errors * chore: satisfy release metadata and test header checks * fix(single-instance): launch normally without a D-Bus session bus Log a warning instead of failing setup when the session bus is unreachable, and add context to handoff errors. * ci: run the single-instance D-Bus test under dbus-run-session Run it in test-rust on Linux and keep it out of the updater integration job, which has no session bus. --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
1 parent
6a263bec1c
commit
f83c5d3b0f
6 files changed
+237
-13
No files matched your search
@@ -53,22 +53,30 @@ pub fn init<R: Runtime>(
|
||||
app_handle: app.clone(),
|
||||
};
|
||||
|
||||
match zbus::blocking::connection::Builder::session()
|
||||
.unwrap()
|
||||
.name(dbus_name.as_str())
|
||||
.unwrap()
|
||||
let builder = match zbus::blocking::connection::Builder::session() {
|
||||
Ok(builder) => builder,
|
||||
Err(error) => {
|
||||
tracing::warn!(
|
||||
"single-instance: invalid D-Bus session address, launching normally: {error}"
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
match builder
|
||||
.name(dbus_name.as_str())?
|
||||
.replace_existing_names(false)
|
||||
.allow_name_replacements(false)
|
||||
.serve_at(dbus_path.as_str(), single_instance_dbus)
|
||||
.unwrap()
|
||||
.serve_at(dbus_path.as_str(), single_instance_dbus)?
|
||||
.build()
|
||||
{
|
||||
Ok(connection) => {
|
||||
app.manage(ConnectionHandle(connection));
|
||||
}
|
||||
Err(zbus::Error::NameTaken) => {
|
||||
if let Ok(connection) = Connection::session() {
|
||||
let _ = connection.call_method(
|
||||
let connection = Connection::session()?;
|
||||
connection
|
||||
.call_method(
|
||||
Some(dbus_name.as_str()),
|
||||
dbus_path.as_str(),
|
||||
Some("org.SingleInstance.DBus"),
|
||||
@@ -82,12 +90,21 @@ pub fn init<R: Runtime>(
|
||||
.to_string_lossy()
|
||||
.as_ref(),
|
||||
),
|
||||
);
|
||||
}
|
||||
)
|
||||
.map_err(|error| {
|
||||
format!("failed to forward arguments to the running instance: {error}")
|
||||
})?;
|
||||
// Exit successfully only after the primary accepted the arguments.
|
||||
app.cleanup_before_exit();
|
||||
std::process::exit(0);
|
||||
}
|
||||
_ => {}
|
||||
Err(error) => {
|
||||
// Without a session bus there is no way to find other instances.
|
||||
tracing::warn!(
|
||||
"single-instance: D-Bus session bus unavailable, launching normally: {error}"
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
app.manage(DBusName(dbus_name));
|
||||
|
||||
Reference in new issue
Block a user