check tray support on inux

Signed-off-by: FTCHD <144691102+FTCHD@users.noreply.github.com>
This commit is contained in:
FTCHD
2025-10-08 13:07:50 +02:00
parent 5633acfc13
commit 097047a1ce
4 changed files with 87 additions and 2 deletions
+39 -1
View File
@@ -603,6 +603,43 @@ async function checkVersion() {
} catch {}
}
async function checkTraySupport() {
let traySupported = false
try {
traySupported = await invoke<boolean>('is_tray_supported')
} catch {}
if (!traySupported) {
const msg =
'Your desktop environment does not appear to support system tray icons.\n\nRclone UI requires a tray to run. The application will exit automatically in 10 seconds.'
let alreadyExiting = false
const timer = setTimeout(async () => {
if (alreadyExiting) return
alreadyExiting = true
await exit(0)
}, 10_000)
ask(msg, {
title: 'Tray Not Supported',
kind: 'error',
okLabel: 'Exit Now',
cancelLabel: 'Cancel',
})
.then(async (confirmed) => {
if (!alreadyExiting && confirmed) {
alreadyExiting = true
clearTimeout(timer)
await exit(0)
}
})
.catch()
await new Promise(() => {})
}
}
getCurrentWindow().listen('tauri://close-requested', async (e) => {
console.log('(main) window close requested')
await getCurrentWindow().destroy()
@@ -617,7 +654,8 @@ getCurrentWindow().listen('rebuild-tray', async (e) => {
await showDefaultTray()
})
initTray()
checkTraySupport()
.then(() => initTray())
.then(() => showLoadingTray())
.then(() => waitForHydration())
.then(() => checkVersion())
+1
View File
@@ -284,6 +284,7 @@ dependencies = [
"tauri-plugin-single-instance",
"tauri-plugin-store",
"tauri-plugin-updater",
"zbus",
"zip 0.6.6",
]
+3
View File
@@ -48,3 +48,6 @@ sysinfo = "0.37"
[target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.26"
[target.'cfg(target_os = "linux")'.dependencies]
zbus = { version = "5" }
+44 -1
View File
@@ -14,6 +14,49 @@ use sysinfo::{System};
use tauri_plugin_sentry;
use sentry;
#[tauri::command]
fn is_tray_supported() -> bool {
#[cfg(not(target_os = "linux"))]
{
return true;
}
#[cfg(target_os = "linux")]
{
use zbus::blocking::fdo::DBusProxy;
use zbus::blocking::{Connection, Proxy};
let conn = match Connection::session() {
Ok(c) => c,
Err(_) => return false,
};
let dbus = match DBusProxy::new(&conn) {
Ok(p) => p,
Err(_) => return false,
};
let candidates = [
"org.kde.StatusNotifierWatcher",
"org.freedesktop.StatusNotifierWatcher",
];
for name in candidates {
if dbus.name_has_owner(name).unwrap_or(false) {
// Try to read the property; if it fails but watcher exists, assume true
if let Ok(proxy) = Proxy::new(&conn, name, "/StatusNotifierWatcher", "org.kde.StatusNotifierWatcher") {
if let Ok(registered) = proxy.get_property::<bool>("IsStatusNotifierHostRegistered") {
return registered;
}
}
return true;
}
}
false
}
}
#[tauri::command]
fn unzip_file(zip_path: &str, output_folder: &str) -> Result<(), String> {
// Open the zip file
@@ -644,7 +687,7 @@ pub fn run() {
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_prevent_default::debug())
.invoke_handler(tauri::generate_handler![unzip_file, get_arch, get_uid, is_rclone_running, stop_rclone_processes, prompt_password, prompt_text, stop_pid, update_system_rclone, test_proxy_connection])
.invoke_handler(tauri::generate_handler![unzip_file, get_arch, get_uid, is_rclone_running, stop_rclone_processes, prompt_password, prompt_text, stop_pid, update_system_rclone, test_proxy_connection, is_tray_supported])
.setup(|_app| Ok(()))
// .setup(|app| {
// if cfg!(debug_assertions) {