diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 528585c..4361768 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,7 +45,7 @@ jobs: - name: Install GTK4 and libfuse2 (Linux) # libfuse2 is needed for AppImage to run, librsvg2-dev is needed for AppImage to support SVG icons properly - run: sudo apt-get update && sudo apt-get install --no-install-recommends -y libgtk-4-dev libdbus-1-dev libfuse2 librsvg2-dev + run: sudo apt-get update && sudo apt-get install --no-install-recommends -y libgtk-4-dev libfuse2 librsvg2-dev if: runner.os == 'Linux' - name: Configure GTK4 cache (Windows) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9e21eda..28bfb5a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -64,7 +64,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Install GTK4 (Ubuntu) - run: sudo apt-get update && sudo apt-get install --no-install-recommends -y libgtk-4-dev libdbus-1-dev + run: sudo apt-get update && sudo apt-get install --no-install-recommends -y libgtk-4-dev if: runner.os == 'Linux' - name: Install GTK4 (macOS) @@ -185,7 +185,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Install GTK4 (Ubuntu) - run: sudo apt-get update && sudo apt-get install --no-install-recommends -y libgtk-4-dev libdbus-1-dev + run: sudo apt-get update && sudo apt-get install --no-install-recommends -y libgtk-4-dev if: runner.os == 'Linux' - name: Install GTK4 (macOS) diff --git a/Cargo.lock b/Cargo.lock index 772a95d..34ede58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -358,15 +358,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anstream" version = "0.6.15" @@ -1581,21 +1572,6 @@ dependencies = [ "inout 0.2.0-rc.1", ] -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "ansi_term", - "atty", - "bitflags 1.3.2", - "strsim 0.8.0", - "textwrap 0.11.0", - "unicode-width", - "vec_map", -] - [[package]] name = "clap" version = "3.2.25" @@ -1610,7 +1586,7 @@ dependencies = [ "once_cell", "strsim 0.10.0", "termcolor", - "textwrap 0.16.1", + "textwrap", ] [[package]] @@ -2222,7 +2198,7 @@ dependencies = [ "rust-ini", "web-sys", "winreg 0.10.1", - "zbus", + "zbus 4.4.0", ] [[package]] @@ -2264,37 +2240,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "dbus" -version = "0.9.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b" -dependencies = [ - "libc", - "libdbus-sys", - "winapi", -] - -[[package]] -name = "dbus-codegen" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a49da9fdfbe872d4841d56605dc42efa5e6ca3291299b87f44e1cde91a28617c" -dependencies = [ - "clap 2.34.0", - "dbus", - "xml-rs", -] - -[[package]] -name = "dbus-tree" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f456e698ae8e54575e19ddb1f9b7bce2298568524f215496b248eb9498b4f508" -dependencies = [ - "dbus", -] - [[package]] name = "dconf_rs" version = "0.3.0" @@ -4257,7 +4202,7 @@ dependencies = [ "serde_json", "walkdir", "zerocopy", - "zvariant", + "zvariant 4.2.0", ] [[package]] @@ -5378,14 +5323,15 @@ checksum = "c33070833c9ee02266356de0c43f723152bd38bd96ddf52c82b3af10c9138b28" [[package]] name = "ksni" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4934310bdd016e55725482b8d35ac0c16fd058c1b955d8959aa2d953b918c85b" +checksum = "8339e7c516f3e342aa9952d4c289a511e6662a1e3c3259ddbd7aca808b16c282" dependencies = [ - "dbus", - "dbus-codegen", - "dbus-tree", - "thiserror 1.0.65", + "futures-util", + "paste", + "serde", + "tokio", + "zbus 5.1.1", ] [[package]] @@ -5468,15 +5414,6 @@ version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" -[[package]] -name = "libdbus-sys" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72" -dependencies = [ - "pkg-config", -] - [[package]] name = "libfuzzer-sys" version = "0.4.7" @@ -7416,7 +7353,7 @@ dependencies = [ "mac-notification-sys", "serde", "tauri-winrt-notification", - "zbus", + "zbus 4.4.0", ] [[package]] @@ -12338,12 +12275,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.10.0" @@ -13026,15 +12957,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "textwrap" version = "0.16.1" @@ -13204,6 +13126,7 @@ dependencies = [ "signal-hook-registry", "socket2 0.5.7", "tokio-macros", + "tracing", "windows-sys 0.52.0", ] @@ -13483,9 +13406,9 @@ dependencies = [ [[package]] name = "tray-icon" -version = "0.19.1" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c92af36a182b46206723bdf8a7942e20838cde1cf062e5b97854d57eb01763b" +checksum = "d48a05076dd272615d03033bf04f480199f7d1b66a8ac64d75c625fc4a70c06b" dependencies = [ "core-graphics 0.24.0", "crossbeam-channel", @@ -13869,12 +13792,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version-compare" version = "0.2.0" @@ -14961,9 +14878,39 @@ dependencies = [ "uds_windows", "windows-sys 0.52.0", "xdg-home", - "zbus_macros", - "zbus_names", - "zvariant", + "zbus_macros 4.4.0", + "zbus_names 3.0.0", + "zvariant 4.2.0", +] + +[[package]] +name = "zbus" +version = "5.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1162094dc63b1629fcc44150bcceeaa80798cd28bcbe7fa987b65a034c258608" +dependencies = [ + "async-broadcast", + "async-recursion", + "async-trait", + "enumflags2", + "event-listener 5.3.1", + "futures-core", + "futures-util", + "hex", + "nix 0.29.0", + "ordered-stream", + "serde", + "serde_repr", + "static_assertions", + "tokio", + "tracing", + "uds_windows", + "windows-sys 0.59.0", + "winnow 0.6.20", + "xdg-home", + "zbus_macros 5.1.1", + "zbus_names 4.1.0", + "zvariant 5.1.0", ] [[package]] @@ -14976,7 +14923,22 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.87", - "zvariant_utils", + "zvariant_utils 2.1.0", +] + +[[package]] +name = "zbus_macros" +version = "5.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cd2dcdce3e2727f7d74b7e33b5a89539b3cc31049562137faf7ae4eb86cd16d" +dependencies = [ + "proc-macro-crate 3.2.0", + "proc-macro2", + "quote", + "syn 2.0.87", + "zbus_names 4.1.0", + "zvariant 5.1.0", + "zvariant_utils 3.0.2", ] [[package]] @@ -14987,7 +14949,19 @@ checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c" dependencies = [ "serde", "static_assertions", - "zvariant", + "zvariant 4.2.0", +] + +[[package]] +name = "zbus_names" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "856b7a38811f71846fd47856ceee8bccaec8399ff53fb370247e66081ace647b" +dependencies = [ + "serde", + "static_assertions", + "winnow 0.6.20", + "zvariant 5.1.0", ] [[package]] @@ -15131,7 +15105,22 @@ dependencies = [ "enumflags2", "serde", "static_assertions", - "zvariant_derive", + "zvariant_derive 4.2.0", +] + +[[package]] +name = "zvariant" +version = "5.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1200ee6ac32f1e5a312e455a949a4794855515d34f9909f4a3e082d14e1a56f" +dependencies = [ + "endi", + "enumflags2", + "serde", + "static_assertions", + "winnow 0.6.20", + "zvariant_derive 5.1.0", + "zvariant_utils 3.0.2", ] [[package]] @@ -15144,7 +15133,20 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.87", - "zvariant_utils", + "zvariant_utils 2.1.0", +] + +[[package]] +name = "zvariant_derive" +version = "5.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "687e3b97fae6c9104fbbd36c73d27d149abf04fb874e2efbd84838763daa8916" +dependencies = [ + "proc-macro-crate 3.2.0", + "proc-macro2", + "quote", + "syn 2.0.87", + "zvariant_utils 3.0.2", ] [[package]] @@ -15157,3 +15159,17 @@ dependencies = [ "quote", "syn 2.0.87", ] + +[[package]] +name = "zvariant_utils" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20d1d011a38f12360e5fcccceeff5e2c42a8eb7f27f0dcba97a0862ede05c9c6" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "static_assertions", + "syn 2.0.87", + "winnow 0.6.20", +] diff --git a/Cargo.toml b/Cargo.toml index 10ef368..57678c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -119,10 +119,10 @@ native-dialog = "0.7.0" tracing-panic = "0.1.2" [target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies] -tray-icon = "0.19.1" +tray-icon = "0.19.2" [target.'cfg(all(unix, not(target_os = "macos")))'.dependencies] -ksni = "0.2.2" +ksni = "0.3.0" [build-dependencies] fluent-static-codegen = "0.5.0" diff --git a/README.md b/README.md index 71e5376..6fc30af 100644 --- a/README.md +++ b/README.md @@ -64,9 +64,6 @@ In order to build this app you'll need to install both dependencies necessary fo [Subspace](https://github.com/autonomys/subspace) and [GTK4](https://github.com/gtk-rs/gtk4-rs), including the optional `librsvg`. Follow their documentation for details. -On Linux D-Bus development headers also need to be installed, can be done with `sudo apt-get install libdbus-1-dev` on -Ubuntu. - Then simply `cargo run` will get you where to want to be. ## Contribution diff --git a/src/frontend/tray_icon/unix.rs b/src/frontend/tray_icon/unix.rs index 154a1e6..88ec990 100644 --- a/src/frontend/tray_icon/unix.rs +++ b/src/frontend/tray_icon/unix.rs @@ -1,38 +1,42 @@ use crate::frontend::tray_icon::load_icon; use crate::frontend::{App, AppCommandOutput, T}; -use futures::channel::oneshot; use ksni::menu::{MenuItem, StandardItem}; -use ksni::{Icon, ToolTip, Tray, TrayService}; +use ksni::{Handle, Icon, ToolTip, Tray, TrayMethods}; use relm4::{AsyncComponentSender, Sender}; use std::any::Any; -use std::cell::RefCell; +use tokio::task; use tracing::{error, warn}; -pub(in super::super) async fn spawn(sender: &AsyncComponentSender) -> Option> { - let (initialized_sender, initialized_receiver) = oneshot::channel(); +struct ShutdownWrapper { + handle: Handle, +} - sender.spawn_command(move |sender| { - let icon = TrayIcon { - sender, - initialized: RefCell::new(Some(initialized_sender)), - }; +impl Drop for ShutdownWrapper { + fn drop(&mut self) { + let shutdown_awaiter = self.handle.shutdown(); - let tray_service = TrayService::new(icon); + task::block_in_place(|| { + tokio::runtime::Handle::current().block_on(shutdown_awaiter); + }) + } +} - if let Err(error) = tray_service.run() { - warn!(%error, "Tray icon error"); - } - }); +pub(in super::super) async fn spawn(sender: &AsyncComponentSender) -> Option> { + let icon = TrayIcon { + sender: sender.command_sender().clone(), + }; - initialized_receiver - .await - .unwrap_or_default() - .then_some(Box::new(())) + match icon.spawn().await { + Ok(handle) => Some(Box::new(ShutdownWrapper { handle })), + Err(error) => { + warn!(%error, "Tray icon not supported on this platform"); + None + } + } } pub(in super::super) struct TrayIcon { sender: Sender, - initialized: RefCell>>, } impl Tray for TrayIcon { @@ -87,23 +91,4 @@ impl Tray for TrayIcon { .into(), ] } - - fn watcher_online(&self) { - if let Some(initialized) = self.initialized.borrow_mut().take() { - if let Err(_error) = initialized.send(true) { - warn!("Failed to send initialized notification"); - } - } - } - - fn watcher_offine(&self) -> bool { - warn!("Tray icon not supported on this platform"); - - if let Some(initialized) = self.initialized.borrow_mut().take() { - if let Err(_error) = initialized.send(false) { - warn!("Failed to send initialized notification"); - } - } - false - } }