From 959608fffbefe056d30f2b0291135a422b1c2ef0 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Tue, 17 Sep 2024 14:06:04 +0200 Subject: [PATCH 01/17] commit for testing implementation --- src-tauri/Cargo.lock | 413 ++++++++++++++++++++++++-- src-tauri/Cargo.toml | 1 + src-tauri/src/main.rs | 12 +- src-tauri/src/notification_manager.rs | 33 ++ 4 files changed, 439 insertions(+), 20 deletions(-) create mode 100644 src-tauri/src/notification_manager.rs diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 0e60491f4..6c663f91a 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -147,11 +147,23 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d26004fe83b2d1cd3a97609b21e39f9a31535822210fe83205d2ce48866ea61" dependencies = [ - "event-listener", + "event-listener 2.5.3", "futures-core", "parking_lot", ] +[[package]] +name = "async-broadcast" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cd0e2e25ea8e5f7e9df04578dc6cf5c83577fd09b1a46aaf5c85e1c33f2a7e" +dependencies = [ + "event-listener 5.3.1", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + [[package]] name = "async-channel" version = "1.9.0" @@ -159,10 +171,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" dependencies = [ "concurrent-queue", - "event-listener", + "event-listener 2.5.3", "futures-core", ] +[[package]] +name = "async-channel" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b47800b0be77592da0afd425cc03468052844aff33b84e33cc696f64e77b6a" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + [[package]] name = "async-compression" version = "0.4.12" @@ -194,13 +218,24 @@ dependencies = [ "slab", ] +[[package]] +name = "async-fs" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebcd09b382f40fcd159c2d695175b2ae620ffa5f3bd6f664131efff4e8b9e04a" +dependencies = [ + "async-lock 3.4.0", + "blocking", + "futures-lite 2.3.0", +] + [[package]] name = "async-io" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" dependencies = [ - "async-lock", + "async-lock 2.8.0", "autocfg", "cfg-if", "concurrent-queue", @@ -214,13 +249,62 @@ dependencies = [ "waker-fn", ] +[[package]] +name = "async-io" +version = "2.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "444b0228950ee6501b3568d3c93bf1176a1fdbc3b758dcd9475046d30f4dc7e8" +dependencies = [ + "async-lock 3.4.0", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite 2.3.0", + "parking", + "polling 3.7.3", + "rustix 0.38.37", + "slab", + "tracing", + "windows-sys 0.59.0", +] + [[package]] name = "async-lock" version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" dependencies = [ - "event-listener", + "event-listener 2.5.3", +] + +[[package]] +name = "async-lock" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" +dependencies = [ + "event-listener 5.3.1", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "async-process" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63255f1dc2381611000436537bbedfe83183faa303a5a0edaf191edef06526bb" +dependencies = [ + "async-channel 2.3.1", + "async-io 2.3.4", + "async-lock 3.4.0", + "async-signal", + "async-task", + "blocking", + "cfg-if", + "event-listener 5.3.1", + "futures-lite 2.3.0", + "rustix 0.38.37", + "tracing", ] [[package]] @@ -234,6 +318,35 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "async-recursion" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + +[[package]] +name = "async-signal" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "637e00349800c0bdf8bfc21ebbc0b6524abea702b0da4168ac00d070d0c0b9f3" +dependencies = [ + "async-io 2.3.4", + "async-lock 3.4.0", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix 0.38.37", + "signal-hook-registry", + "slab", + "windows-sys 0.59.0", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -512,6 +625,19 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blocking" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "703f41c54fc768e63e091340b424302bb1c29ef4aa0c7f10fe849dfb114d29ea" +dependencies = [ + "async-channel 2.3.1", + "async-task", + "futures-io", + "futures-lite 2.3.0", + "piper", +] + [[package]] name = "borsh" version = "1.5.1" @@ -1488,6 +1614,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "endi" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf" + [[package]] name = "endian-type" version = "0.1.2" @@ -1549,6 +1681,27 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +[[package]] +name = "event-listener" +version = "5.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1" +dependencies = [ + "event-listener 5.3.1", + "pin-project-lite", +] + [[package]] name = "fastrand" version = "1.9.0" @@ -3136,6 +3289,19 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" +[[package]] +name = "mac-notification-sys" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce8f34f3717aa37177e723df6c1fc5fb02b2a1087374ea3fe0ea42316dc8f91" +dependencies = [ + "cc", + "dirs-next 2.0.0", + "objc-foundation", + "objc_id", + "time", +] + [[package]] name = "mach2" version = "0.4.2" @@ -3616,6 +3782,7 @@ dependencies = [ "cfg-if", "cfg_aliases 0.2.1", "libc", + "memoffset 0.9.1", ] [[package]] @@ -3640,6 +3807,19 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "notify-rust" +version = "4.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5134a72dc570b178bff81b01e81ab14a6fcc015391ed4b3b14853090658cd3a3" +dependencies = [ + "log", + "mac-notification-sys", + "serde", + "tauri-winrt-notification", + "zbus 4.4.0", +] + [[package]] name = "ntapi" version = "0.4.1" @@ -3906,6 +4086,16 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "ordered-stream" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aa2b01e1d916879f73a53d01d1d6cee68adbb31d6d9177a8cfce093cced1d50" +dependencies = [ + "futures-core", + "pin-project-lite", +] + [[package]] name = "os_info" version = "3.8.2" @@ -4258,6 +4448,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "piper" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c8c490f422ef9a4efd2cb5b42b76c8613d7e7dfc1caf667b8a3350a5acc066" +dependencies = [ + "atomic-waker", + "fastrand 2.1.1", + "futures-io", +] + [[package]] name = "pkg-config" version = "0.3.30" @@ -4278,7 +4479,7 @@ checksum = "42cf17e9a1800f5f396bc67d193dc9411b59012a5876445ef450d449881e1016" dependencies = [ "base64 0.22.1", "indexmap 2.5.0", - "quick-xml", + "quick-xml 0.32.0", "serde", "time", ] @@ -4521,6 +4722,15 @@ dependencies = [ "prost", ] +[[package]] +name = "quick-xml" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" +dependencies = [ + "memchr", +] + [[package]] name = "quick-xml" version = "0.32.0" @@ -6092,6 +6302,7 @@ dependencies = [ "minotari_node_grpc_client", "minotari_wallet_grpc_client", "nix 0.29.0", + "notify-rust", "nvml-wrapper", "open 5.3.0", "rand 0.8.5", @@ -6710,7 +6921,7 @@ dependencies = [ "tauri", "thiserror", "windows-sys 0.59.0", - "zbus", + "zbus 3.3.0", ] [[package]] @@ -6797,6 +7008,17 @@ dependencies = [ "toml 0.7.8", ] +[[package]] +name = "tauri-winrt-notification" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f89f5fb70d6f62381f5d9b2ba9008196150b40b75f3068eb24faeddf1c686871" +dependencies = [ + "quick-xml 0.31.0", + "windows 0.56.0", + "windows-version", +] + [[package]] name = "tempfile" version = "3.12.0" @@ -7901,6 +8123,16 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1de69df01bdf1ead2f4ac895dc77c9351aefff65b2f3db429a343f9cbf05e132" +dependencies = [ + "windows-core 0.56.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows" version = "0.57.0" @@ -7930,6 +8162,18 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4698e52ed2d08f8658ab0c39512a7c00ee5fe2688c65f8c0a4f06750d729f2a6" +dependencies = [ + "windows-implement 0.56.0", + "windows-interface 0.56.0", + "windows-result 0.1.2", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.57.0" @@ -7937,7 +8181,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" dependencies = [ "windows-implement 0.57.0", - "windows-interface", + "windows-interface 0.57.0", "windows-result 0.1.2", "windows-targets 0.52.6", ] @@ -7952,6 +8196,17 @@ dependencies = [ "windows-tokens", ] +[[package]] +name = "windows-implement" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + [[package]] name = "windows-implement" version = "0.57.0" @@ -7963,6 +8218,17 @@ dependencies = [ "syn 2.0.77", ] +[[package]] +name = "windows-interface" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] + [[package]] name = "windows-interface" version = "0.57.0" @@ -8428,6 +8694,16 @@ dependencies = [ "rustix 0.38.37", ] +[[package]] +name = "xdg-home" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec1cdab258fb55c0da61328dc52c8764709b249011b2cad0454c72f0bf10a1f6" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "xz2" version = "0.1.7" @@ -8468,26 +8744,26 @@ version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41ce2de393c874ba871292e881bf3c13a0d5eb38170ebab2e50b4c410eaa222b" dependencies = [ - "async-broadcast", - "async-channel", + "async-broadcast 0.4.1", + "async-channel 1.9.0", "async-executor", - "async-io", - "async-lock", - "async-recursion", + "async-io 1.13.0", + "async-lock 2.8.0", + "async-recursion 0.3.2", "async-task", "async-trait", "byteorder", "derivative", "dirs", "enumflags2", - "event-listener", + "event-listener 2.5.3", "futures-core", "futures-sink", "futures-util", "hex", "nix 0.24.3", "once_cell", - "ordered-stream", + "ordered-stream 0.0.1", "rand 0.8.5", "serde", "serde_repr", @@ -8496,9 +8772,47 @@ dependencies = [ "tracing", "uds_windows", "winapi", - "zbus_macros", - "zbus_names", - "zvariant", + "zbus_macros 3.3.0", + "zbus_names 2.2.0", + "zvariant 3.7.1", +] + +[[package]] +name = "zbus" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb97012beadd29e654708a0fdb4c84bc046f537aecfde2c3ee0a9e4b4d48c725" +dependencies = [ + "async-broadcast 0.7.1", + "async-executor", + "async-fs", + "async-io 2.3.4", + "async-lock 3.4.0", + "async-process", + "async-recursion 1.1.1", + "async-task", + "async-trait", + "blocking", + "enumflags2", + "event-listener 5.3.1", + "futures-core", + "futures-sink", + "futures-util", + "hex", + "nix 0.29.0", + "ordered-stream 0.2.0", + "rand 0.8.5", + "serde", + "serde_repr", + "sha1 0.10.6", + "static_assertions", + "tracing", + "uds_windows", + "windows-sys 0.52.0", + "xdg-home", + "zbus_macros 4.4.0", + "zbus_names 3.0.0", + "zvariant 4.2.0", ] [[package]] @@ -8514,6 +8828,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "zbus_macros" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267db9407081e90bbfa46d841d3cbc60f59c0351838c4bc65199ecd79ab1983e" +dependencies = [ + "proc-macro-crate 3.2.0", + "proc-macro2", + "quote", + "syn 2.0.77", + "zvariant_utils", +] + [[package]] name = "zbus_names" version = "2.2.0" @@ -8522,7 +8849,18 @@ checksum = "41a408fd8a352695690f53906dc7fd036be924ec51ea5e05666ff42685ed0af5" dependencies = [ "serde", "static_assertions", - "zvariant", + "zvariant 3.7.1", +] + +[[package]] +name = "zbus_names" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c" +dependencies = [ + "serde", + "static_assertions", + "zvariant 4.2.0", ] [[package]] @@ -8668,7 +9006,20 @@ dependencies = [ "libc", "serde", "static_assertions", - "zvariant_derive", + "zvariant_derive 3.7.1", +] + +[[package]] +name = "zvariant" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2084290ab9a1c471c38fc524945837734fbf124487e105daec2bb57fd48c81fe" +dependencies = [ + "endi", + "enumflags2", + "serde", + "static_assertions", + "zvariant_derive 4.2.0", ] [[package]] @@ -8682,3 +9033,27 @@ dependencies = [ "quote", "syn 1.0.109", ] + +[[package]] +name = "zvariant_derive" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73e2ba546bda683a90652bac4a279bc146adad1386f25379cf73200d2002c449" +dependencies = [ + "proc-macro-crate 3.2.0", + "proc-macro2", + "quote", + "syn 2.0.77", + "zvariant_utils", +] + +[[package]] +name = "zvariant_utils" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c51bcff7cc3dbb5055396bcf774748c3dab426b4b8659046963523cee4808340" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", +] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 696f3489a..14032ee93 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -85,6 +85,7 @@ nvml-wrapper = "0.10.0" sentry-tauri = "0.3.0" chrono = "0.4.38" sys-locale = "0.3.1" +notify-rust = "4.11.3" # tonic = "0.12.0" [features] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index cf0fe241c..72129c09a 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,8 +1,10 @@ // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +use hardware_monitor::{HardwareMonitor, HardwareParameters}; use log::trace; use log::{debug, error, info, warn}; +use notification_manager::NotificationManager; use serde::Serialize; use std::collections::HashMap; use std::fs::{read_dir, remove_dir_all, remove_file}; @@ -22,7 +24,6 @@ use app_config::AppConfig; use app_in_memory_config::{AirdropInMemoryConfig, AppInMemoryConfig}; use binary_resolver::{Binaries, BinaryResolver}; use gpu_miner_adapter::{GpuMinerStatus, GpuNodeSource}; -use hardware_monitor::{HardwareMonitor, HardwareParameters}; use node_manager::NodeManagerError; use progress_tracker::ProgressTracker; use setup_status_event::SetupStatusEvent; @@ -77,6 +78,7 @@ mod wallet_adapter; mod wallet_manager; mod xmrig; mod xmrig_adapter; +mod notification_manager; const MAX_ACCEPTABLE_COMMAND_TIME: Duration = Duration::from_secs(1); @@ -709,6 +711,13 @@ async fn get_seed_words( Ok(res) } +#[tauri::command] +async fn trigger_block_win_notification( +) -> Result<(), String> { + NotificationManager::current().trigger_notification("Test", "test"); + Ok(()) +} + #[tauri::command] async fn start_mining<'r>( window: tauri::Window, @@ -1471,6 +1480,7 @@ fn main() { restart_application, resolve_application_language, set_application_language, + trigger_block_win_notification, get_miner_metrics, get_app_config, get_p2pool_stats, diff --git a/src-tauri/src/notification_manager.rs b/src-tauri/src/notification_manager.rs new file mode 100644 index 000000000..95521687e --- /dev/null +++ b/src-tauri/src/notification_manager.rs @@ -0,0 +1,33 @@ +use std::sync::LazyLock; +use notify_rust::{Notification, Timeout}; + +use log::info; + +const LOG_TARGET: &str = "tari::universe::notification_manager"; +static INSTANCE: LazyLock = LazyLock::new(NotificationManager::new); + +pub struct NotificationManager {} + +impl NotificationManager { + pub fn new() -> Self { + Self {} + } + + pub fn trigger_notification(&self, summary: &str, body: &str) { + info!(target: LOG_TARGET, "Triggering notification with summary: {} and body: {}", summary, body); + Notification::new() + .summary("Firefox News") + .body("This will almost look like a real firefox notification.") + .icon("firefox") + .timeout(Timeout::Milliseconds(6000)) //milliseconds + .show().unwrap().on_close( + || { + info!(target: LOG_TARGET,"Notification closed"); + } + ); + } + + pub fn current() -> &'static NotificationManager { + &INSTANCE + } +} \ No newline at end of file From 911fb51c82b36ca49f49239923342e5ab8aab3bf Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Tue, 17 Sep 2024 14:06:25 +0200 Subject: [PATCH 02/17] frontend part --- src/types/invoke.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/invoke.ts b/src/types/invoke.ts index 22309990c..7f104d0dc 100644 --- a/src/types/invoke.ts +++ b/src/types/invoke.ts @@ -9,6 +9,7 @@ declare module '@tauri-apps/api/tauri' { ): Promise; function invoke(param: 'set_application_language', payload: { applicationLanguage: Language }): Promise; function invoke(param: 'resolve_application_language'): Promise; + function invoke(param: 'trigger_block_win_notification'): Promise; function invoke(param: 'setup_application'): Promise; function invoke(param: 'open_log_dir'): Promise; function invoke(param: 'start_mining'): Promise; From e3911593bef8fb59fcc58a5ec35561b825bb8b58 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Tue, 17 Sep 2024 16:27:36 +0200 Subject: [PATCH 03/17] Different implementation per platform --- src-tauri/src/main.rs | 8 ++-- src-tauri/src/notification_manager.rs | 60 +++++++++++++++++++++++---- src/hooks/mining/useBalanceChanges.ts | 4 ++ src/hooks/useNotifications.ts | 20 +++++++++ src/types/invoke.ts | 2 +- 5 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 src/hooks/useNotifications.ts diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 72129c09a..6d14c9be6 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -712,9 +712,11 @@ async fn get_seed_words( } #[tauri::command] -async fn trigger_block_win_notification( +async fn trigger_notification( + summary: &str, + body: &str, ) -> Result<(), String> { - NotificationManager::current().trigger_notification("Test", "test"); + NotificationManager::current().trigger_notification(summary, body); Ok(()) } @@ -1480,7 +1482,7 @@ fn main() { restart_application, resolve_application_language, set_application_language, - trigger_block_win_notification, + trigger_notification, get_miner_metrics, get_app_config, get_p2pool_stats, diff --git a/src-tauri/src/notification_manager.rs b/src-tauri/src/notification_manager.rs index 95521687e..32a21249d 100644 --- a/src-tauri/src/notification_manager.rs +++ b/src-tauri/src/notification_manager.rs @@ -6,6 +6,12 @@ use log::info; const LOG_TARGET: &str = "tari::universe::notification_manager"; static INSTANCE: LazyLock = LazyLock::new(NotificationManager::new); +pub enum CurrentOperatingSystem { + Windows, + Linux, + MacOS, +} + pub struct NotificationManager {} impl NotificationManager { @@ -15,16 +21,52 @@ impl NotificationManager { pub fn trigger_notification(&self, summary: &str, body: &str) { info!(target: LOG_TARGET, "Triggering notification with summary: {} and body: {}", summary, body); - Notification::new() - .summary("Firefox News") - .body("This will almost look like a real firefox notification.") - .icon("firefox") - .timeout(Timeout::Milliseconds(6000)) //milliseconds - .show().unwrap().on_close( - || { - info!(target: LOG_TARGET,"Notification closed"); + let notification = self.build_notification(summary, body); + + match Self::detect_current_os() { + CurrentOperatingSystem::Linux => { + notification.show().unwrap().on_close( + |notification| { + info!(target: LOG_TARGET, "Notification closed: {:?}", notification); + }, + ); + } + CurrentOperatingSystem::MacOS => { + notification.show().unwrap(); + } + CurrentOperatingSystem::Windows => { + notification.show().unwrap(); + } + } + } + + fn build_notification(&self, summary: &str, body: &str) -> Notification { + let mut notification = Notification::new() + .summary(summary) + .body(body).finalize(); + + match Self::detect_current_os() { + CurrentOperatingSystem::Linux => { + return notification.auto_icon().appname("Tari Universe").finalize(); + } + CurrentOperatingSystem::MacOS => { + return notification.finalize(); + } + CurrentOperatingSystem::Windows => { + return notification.finalize(); + } + } + } + fn detect_current_os() -> CurrentOperatingSystem { + if cfg!(target_os = "windows") { + CurrentOperatingSystem::Windows + } else if cfg!(target_os = "linux") { + CurrentOperatingSystem::Linux + } else if cfg!(target_os = "macos") { + CurrentOperatingSystem::MacOS + } else { + panic!("Unsupported OS"); } - ); } pub fn current() -> &'static NotificationManager { diff --git a/src/hooks/mining/useBalanceChanges.ts b/src/hooks/mining/useBalanceChanges.ts index 54c133400..d8055e22a 100644 --- a/src/hooks/mining/useBalanceChanges.ts +++ b/src/hooks/mining/useBalanceChanges.ts @@ -2,6 +2,8 @@ import { useCallback, useEffect, useRef, useState } from 'react'; import { useMiningStore } from '@app/store/useMiningStore.ts'; import { useVisualisation } from '@app/hooks/mining/useVisualisation.ts'; import { useWalletStore } from '@app/store/useWalletStore'; +import { useNotifcations } from '../useNotifications'; +import formatBalance from '@app/utils/formatBalance'; function logBalanceChanges({ balance, prevBalance, balanceDiff }) { console.groupCollapsed('Balance changes:'); @@ -13,6 +15,7 @@ function logBalanceChanges({ balance, prevBalance, balanceDiff }) { const TIMER_VALUE = 15 * 1000; // 15s export function useBalanceChanges() { + const { winNotification } = useNotifcations(); const { handleWin, handleFail } = useVisualisation(); const [balanceChangeBlock, setBalanceChangeBlock] = useState(null); const [blockHeightChanged, setBlockHeightChanged] = useState(false); @@ -44,6 +47,7 @@ export function useBalanceChanges() { const hasEarnings = Boolean(balance > 0 && diff > 0 && diff !== balance); if (hasEarnings) { handleWin(); + winNotification(formatBalance(diff).toString()); setEarnings(diff); } balanceRef.current = balance; diff --git a/src/hooks/useNotifications.ts b/src/hooks/useNotifications.ts new file mode 100644 index 000000000..8daf53af5 --- /dev/null +++ b/src/hooks/useNotifications.ts @@ -0,0 +1,20 @@ +import { invoke } from '@tauri-apps/api/tauri'; +import { useCallback } from 'react'; + +export const useNotifcations = () => { + const winNotification = useCallback(async (winAmount: string) => { + await invoke('trigger_notification', { + summary: 'You won!', + body: `You won ${winAmount}!`, + }); + }, []); + + const testNotification = useCallback(async () => { + await invoke('trigger_notification', { + summary: 'Test Notification', + body: 'This is a test notification.', + }); + }, []); + + return { winNotification, testNotification }; +}; diff --git a/src/types/invoke.ts b/src/types/invoke.ts index 7f104d0dc..15c103966 100644 --- a/src/types/invoke.ts +++ b/src/types/invoke.ts @@ -9,7 +9,7 @@ declare module '@tauri-apps/api/tauri' { ): Promise; function invoke(param: 'set_application_language', payload: { applicationLanguage: Language }): Promise; function invoke(param: 'resolve_application_language'): Promise; - function invoke(param: 'trigger_block_win_notification'): Promise; + function invoke(param: 'trigger_notification', payload: { summary: string; body: string }): Promise; function invoke(param: 'setup_application'): Promise; function invoke(param: 'open_log_dir'): Promise; function invoke(param: 'start_mining'): Promise; From 3aa8b69b1122b8f0032a18fa33235e08908cdd08 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Tue, 17 Sep 2024 16:35:47 +0200 Subject: [PATCH 04/17] Add extra platform flagh --- src-tauri/src/notification_manager.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src-tauri/src/notification_manager.rs b/src-tauri/src/notification_manager.rs index 32a21249d..edd6f33e8 100644 --- a/src-tauri/src/notification_manager.rs +++ b/src-tauri/src/notification_manager.rs @@ -25,6 +25,7 @@ impl NotificationManager { match Self::detect_current_os() { CurrentOperatingSystem::Linux => { + #[cfg(target_os = "linux")] notification.show().unwrap().on_close( |notification| { info!(target: LOG_TARGET, "Notification closed: {:?}", notification); @@ -32,9 +33,11 @@ impl NotificationManager { ); } CurrentOperatingSystem::MacOS => { + #[cfg(target_os = "macos")] notification.show().unwrap(); } CurrentOperatingSystem::Windows => { + #[cfg(target_os = "windows")] notification.show().unwrap(); } } From 070a887cfcb121e443a80cb9d1c15042bf075089 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Wed, 18 Sep 2024 12:09:06 +0200 Subject: [PATCH 05/17] Reverted to single library implementation --- src-tauri/src/notification_manager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/src/notification_manager.rs b/src-tauri/src/notification_manager.rs index edd6f33e8..16ab874d2 100644 --- a/src-tauri/src/notification_manager.rs +++ b/src-tauri/src/notification_manager.rs @@ -1,5 +1,5 @@ use std::sync::LazyLock; -use notify_rust::{Notification, Timeout}; +use notify_rust::Notification; use log::info; From 8f14dbf4ad9c90804fc77fc2664f1c19af870805 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Thu, 19 Sep 2024 09:47:24 +0200 Subject: [PATCH 06/17] Fix lint and cargo fmt --- src-tauri/src/main.rs | 7 ++----- src-tauri/src/notification_manager.rs | 24 ++++++++++-------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6d14c9be6..54752cdb1 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -61,6 +61,7 @@ mod mm_proxy_manager; mod network_utils; mod node_adapter; mod node_manager; +mod notification_manager; mod p2pool; mod p2pool_adapter; mod p2pool_manager; @@ -78,7 +79,6 @@ mod wallet_adapter; mod wallet_manager; mod xmrig; mod xmrig_adapter; -mod notification_manager; const MAX_ACCEPTABLE_COMMAND_TIME: Duration = Duration::from_secs(1); @@ -712,10 +712,7 @@ async fn get_seed_words( } #[tauri::command] -async fn trigger_notification( - summary: &str, - body: &str, -) -> Result<(), String> { +async fn trigger_notification(summary: &str, body: &str) -> Result<(), String> { NotificationManager::current().trigger_notification(summary, body); Ok(()) } diff --git a/src-tauri/src/notification_manager.rs b/src-tauri/src/notification_manager.rs index 16ab874d2..2d943d016 100644 --- a/src-tauri/src/notification_manager.rs +++ b/src-tauri/src/notification_manager.rs @@ -1,5 +1,5 @@ -use std::sync::LazyLock; use notify_rust::Notification; +use std::sync::LazyLock; use log::info; @@ -26,11 +26,9 @@ impl NotificationManager { match Self::detect_current_os() { CurrentOperatingSystem::Linux => { #[cfg(target_os = "linux")] - notification.show().unwrap().on_close( - |notification| { - info!(target: LOG_TARGET, "Notification closed: {:?}", notification); - }, - ); + notification.show().unwrap().on_close(|notification| { + info!(target: LOG_TARGET, "Notification closed: {:?}", notification); + }); } CurrentOperatingSystem::MacOS => { #[cfg(target_os = "macos")] @@ -44,22 +42,20 @@ impl NotificationManager { } fn build_notification(&self, summary: &str, body: &str) -> Notification { - let mut notification = Notification::new() - .summary(summary) - .body(body).finalize(); + let mut notification = Notification::new().summary(summary).body(body).finalize(); match Self::detect_current_os() { CurrentOperatingSystem::Linux => { - return notification.auto_icon().appname("Tari Universe").finalize(); + notification.auto_icon().appname("Tari Universe").finalize() } CurrentOperatingSystem::MacOS => { - return notification.finalize(); + notification.finalize() } CurrentOperatingSystem::Windows => { - return notification.finalize(); + notification.finalize() + } } } - } fn detect_current_os() -> CurrentOperatingSystem { if cfg!(target_os = "windows") { CurrentOperatingSystem::Windows @@ -75,4 +71,4 @@ impl NotificationManager { pub fn current() -> &'static NotificationManager { &INSTANCE } -} \ No newline at end of file +} From 1de81b494ddf121a96596e890ee63bf127175f72 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Thu, 19 Sep 2024 09:52:50 +0200 Subject: [PATCH 07/17] Change win notification text --- src/hooks/useNotifications.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hooks/useNotifications.ts b/src/hooks/useNotifications.ts index 8daf53af5..8b3b9e967 100644 --- a/src/hooks/useNotifications.ts +++ b/src/hooks/useNotifications.ts @@ -4,8 +4,8 @@ import { useCallback } from 'react'; export const useNotifcations = () => { const winNotification = useCallback(async (winAmount: string) => { await invoke('trigger_notification', { - summary: 'You won!', - body: `You won ${winAmount}!`, + summary: 'Congratulations !', + body: `You won a block! We are sending you rewards of ${winAmount} tXTM!`, }); }, []); From a9b9a0340c8348fc6c02c519028c95511113c798 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Thu, 19 Sep 2024 09:56:26 +0200 Subject: [PATCH 08/17] cargo fmt --- src-tauri/src/notification_manager.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/notification_manager.rs b/src-tauri/src/notification_manager.rs index 2d943d016..2967e5cb7 100644 --- a/src-tauri/src/notification_manager.rs +++ b/src-tauri/src/notification_manager.rs @@ -48,12 +48,8 @@ impl NotificationManager { CurrentOperatingSystem::Linux => { notification.auto_icon().appname("Tari Universe").finalize() } - CurrentOperatingSystem::MacOS => { - notification.finalize() - } - CurrentOperatingSystem::Windows => { - notification.finalize() - } + CurrentOperatingSystem::MacOS => notification.finalize(), + CurrentOperatingSystem::Windows => notification.finalize(), } } fn detect_current_os() -> CurrentOperatingSystem { From 7e7a4ed436dc8f7917795762c40a3f55bacec357 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Fri, 25 Oct 2024 17:16:21 +0200 Subject: [PATCH 09/17] complete merge --- src-tauri/Cargo.lock | 39 ++++++++++++++++++++++----- src/hooks/mining/useBalanceChanges.ts | 0 2 files changed, 33 insertions(+), 6 deletions(-) delete mode 100644 src/hooks/mining/useBalanceChanges.ts diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 665339f7f..762c24253 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -381,6 +381,24 @@ dependencies = [ "syn 2.0.82", ] +[[package]] +name = "async-signal" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "637e00349800c0bdf8bfc21ebbc0b6524abea702b0da4168ac00d070d0c0b9f3" +dependencies = [ + "async-io 2.3.4", + "async-lock 3.4.0", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix 0.38.37", + "signal-hook-registry", + "slab", + "windows-sys 0.59.0", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -5045,6 +5063,15 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "quick-xml" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" +dependencies = [ + "memchr", +] + [[package]] name = "quick-xml" version = "0.32.0" @@ -8536,7 +8563,7 @@ checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.82", ] [[package]] @@ -9088,8 +9115,8 @@ dependencies = [ "async-broadcast 0.4.1", "async-channel 1.9.0", "async-executor", - "async-io", - "async-lock", + "async-io 1.13.0", + "async-lock 2.8.0", "async-recursion 0.3.2", "async-task", "async-trait", @@ -9178,7 +9205,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.82", "zvariant_utils", ] @@ -9375,7 +9402,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.82", "zvariant_utils", ] @@ -9387,5 +9414,5 @@ checksum = "c51bcff7cc3dbb5055396bcf774748c3dab426b4b8659046963523cee4808340" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.82", ] diff --git a/src/hooks/mining/useBalanceChanges.ts b/src/hooks/mining/useBalanceChanges.ts deleted file mode 100644 index e69de29bb..000000000 From a6ceb209e9299feb991499e8f8c452d4ab4d8d69 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Fri, 25 Oct 2024 17:25:11 +0200 Subject: [PATCH 10/17] bring back triggering notification --- src-tauri/Cargo.toml | 1 + src-tauri/src/main.rs | 3 ++- src/store/appStateStore.ts | 12 ++++++++++++ src/store/useBlockchainVisualisationStore.ts | 8 ++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 0dc607024..6df21a6cb 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -38,6 +38,7 @@ log4rs = "1.3.0" minotari_node_grpc_client = {git = "https://github.com/tari-project/tari.git", branch = "development"} minotari_wallet_grpc_client = {git = "https://github.com/tari-project/tari.git", branch = "development"} nix = {version = "0.29.0", features = ["signal"]} +notify-rust = "4.11.3" nvml-wrapper = "0.10.0" open = "5" phraze = "0.3.15" diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index c88932257..36a636e77 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -4,10 +4,11 @@ use ::sentry::integrations::anyhow::capture_anyhow; use auto_launcher::AutoLauncher; use external_dependencies::{ExternalDependencies, ExternalDependency, RequiredExternalDependency}; +use hardware_monitor::{HardwareMonitor, HardwareParameters}; use log::trace; use log::{debug, error, info, warn}; -use regex::Regex; use notification_manager::NotificationManager; +use regex::Regex; use serde::Serialize; use std::fs::{read_dir, remove_dir_all, remove_file}; use std::sync::atomic::{AtomicBool, Ordering}; diff --git a/src/store/appStateStore.ts b/src/store/appStateStore.ts index 2ffeefb9c..79425ac32 100644 --- a/src/store/appStateStore.ts +++ b/src/store/appStateStore.ts @@ -29,6 +29,7 @@ interface AppState { fetchApplicationsVersions: () => Promise; fetchApplicationsVersionsWithRetry: () => Promise; updateApplicationsVersions: () => Promise; + triggerNotification: (summary: string, body: string) => Promise; } export const useAppStateStore = create()((set, getState) => ({ @@ -108,4 +109,15 @@ export const useAppStateStore = create()((set, getState) => ({ }, missingExternalDependencies: [], loadExternalDependencies: (externalDependencies: ExternalDependency[]) => set({ externalDependencies }), + triggerNotification: async (summary: string, body: string) => { + try { + await invoke('trigger_notification', { + summary, + body, + }); + } catch (error) { + Sentry.captureException(error); + console.error('Error triggering notification', error); + } + }, })); diff --git a/src/store/useBlockchainVisualisationStore.ts b/src/store/useBlockchainVisualisationStore.ts index e7bab0e9e..d79c50c01 100644 --- a/src/store/useBlockchainVisualisationStore.ts +++ b/src/store/useBlockchainVisualisationStore.ts @@ -6,6 +6,7 @@ import { BlockTimeData } from '@app/types/mining.ts'; import { setAnimationState } from '@app/visuals.ts'; import { TransactionInfo } from '@app/types/app-status.ts'; import { useWalletStore } from '@app/store/useWalletStore.ts'; +import { useAppStateStore } from './appStateStore.ts'; interface Recap { count: number; @@ -58,6 +59,13 @@ export const useBlockchainVisualisationStore = create Date: Fri, 25 Oct 2024 17:33:10 +0200 Subject: [PATCH 11/17] move detect os to utility class --- src-tauri/src/auto_launcher.rs | 24 ++++----------------- src-tauri/src/hardware_monitor.rs | 24 ++++----------------- src-tauri/src/notification_manager.rs | 23 ++++---------------- src-tauri/src/systemtray_manager.rs | 31 +++++++-------------------- src-tauri/src/utils/mod.rs | 1 + src-tauri/src/utils/platform_utils.rs | 20 +++++++++++++++++ 6 files changed, 41 insertions(+), 82 deletions(-) create mode 100644 src-tauri/src/utils/platform_utils.rs diff --git a/src-tauri/src/auto_launcher.rs b/src-tauri/src/auto_launcher.rs index 04eae4d73..ef57a7a11 100644 --- a/src-tauri/src/auto_launcher.rs +++ b/src-tauri/src/auto_launcher.rs @@ -7,16 +7,12 @@ use log::{info, warn}; use tauri::utils::platform::current_exe; use tokio::sync::RwLock; +use crate::utils::platform_utils::{CurrentOperatingSystem, PlatformUtils}; + const LOG_TARGET: &str = "tari::universe::auto_launcher"; static INSTANCE: LazyLock = LazyLock::new(AutoLauncher::new); -pub enum CurrentOperatingSystem { - Windows, - Linux, - MacOS, -} - pub struct AutoLauncher { auto_launcher: RwLock>, } @@ -28,22 +24,10 @@ impl AutoLauncher { } } - fn detect_current_os() -> CurrentOperatingSystem { - if cfg!(target_os = "windows") { - CurrentOperatingSystem::Windows - } else if cfg!(target_os = "linux") { - CurrentOperatingSystem::Linux - } else if cfg!(target_os = "macos") { - CurrentOperatingSystem::MacOS - } else { - panic!("Unsupported OS"); - } - } - fn build_auto_launcher(app_name: &str, app_path: &str) -> Result { info!(target: LOG_TARGET, "Building auto-launcher with app_name: {} and app_path: {}", app_name, app_path); - match AutoLauncher::detect_current_os() { + match PlatformUtils::detect_current_os() { CurrentOperatingSystem::Windows => { return AutoLaunchBuilder::new() .set_app_name(app_name) @@ -79,7 +63,7 @@ impl AutoLauncher { if config_is_auto_launcher_enabled && !is_auto_launcher_enabled { info!(target: LOG_TARGET, "Enabling auto-launcher"); - match AutoLauncher::detect_current_os() { + match PlatformUtils::detect_current_os() { CurrentOperatingSystem::MacOS => { // This for some reason fixes the issue where macOS starts two instances of the app // when auto-launcher is enabled and when during shutdown user selects to reopen the apps after restart diff --git a/src-tauri/src/hardware_monitor.rs b/src-tauri/src/hardware_monitor.rs index 7f7ff3ede..bd5cdfafe 100644 --- a/src-tauri/src/hardware_monitor.rs +++ b/src-tauri/src/hardware_monitor.rs @@ -7,16 +7,12 @@ use serde::{Deserialize, Serialize}; use sysinfo::{Component, Components, CpuRefreshKind, RefreshKind, System}; use tokio::sync::RwLock; +use crate::utils::platform_utils::{CurrentOperatingSystem, PlatformUtils}; + const LOG_TARGET: &str = "tari::universe::hardware_monitor"; static INSTANCE: LazyLock> = LazyLock::new(|| RwLock::new(HardwareMonitor::new())); -enum CurrentOperatingSystem { - Windows, - Linux, - MacOS, -} - #[derive(Clone, Debug, Serialize)] pub struct HardwareParameters { pub label: String, @@ -80,8 +76,8 @@ pub struct HardwareMonitor { impl HardwareMonitor { pub fn new() -> Self { HardwareMonitor { - current_os: HardwareMonitor::detect_current_os(), - current_implementation: match HardwareMonitor::detect_current_os() { + current_os: PlatformUtils::detect_current_os(), + current_implementation: match PlatformUtils::detect_current_os() { CurrentOperatingSystem::Windows => Box::new(WindowsHardwareMonitor { nvml: HardwareMonitor::initialize_nvml(), gpu_status_file: None, @@ -118,18 +114,6 @@ impl HardwareMonitor { } } - fn detect_current_os() -> CurrentOperatingSystem { - if cfg!(target_os = "windows") { - CurrentOperatingSystem::Windows - } else if cfg!(target_os = "linux") { - CurrentOperatingSystem::Linux - } else if cfg!(target_os = "macos") { - CurrentOperatingSystem::MacOS - } else { - panic!("Unsupported OS"); - } - } - pub fn read_hardware_parameters(&mut self) -> HardwareStatus { // USED FOR DEBUGGING // println!("Reading hardware parameters for {}", self.current_implementation.get_implementation_name()); diff --git a/src-tauri/src/notification_manager.rs b/src-tauri/src/notification_manager.rs index 2967e5cb7..7c52757e7 100644 --- a/src-tauri/src/notification_manager.rs +++ b/src-tauri/src/notification_manager.rs @@ -3,15 +3,11 @@ use std::sync::LazyLock; use log::info; +use crate::utils::platform_utils::{CurrentOperatingSystem, PlatformUtils}; + const LOG_TARGET: &str = "tari::universe::notification_manager"; static INSTANCE: LazyLock = LazyLock::new(NotificationManager::new); -pub enum CurrentOperatingSystem { - Windows, - Linux, - MacOS, -} - pub struct NotificationManager {} impl NotificationManager { @@ -23,7 +19,7 @@ impl NotificationManager { info!(target: LOG_TARGET, "Triggering notification with summary: {} and body: {}", summary, body); let notification = self.build_notification(summary, body); - match Self::detect_current_os() { + match PlatformUtils::detect_current_os() { CurrentOperatingSystem::Linux => { #[cfg(target_os = "linux")] notification.show().unwrap().on_close(|notification| { @@ -44,7 +40,7 @@ impl NotificationManager { fn build_notification(&self, summary: &str, body: &str) -> Notification { let mut notification = Notification::new().summary(summary).body(body).finalize(); - match Self::detect_current_os() { + match PlatformUtils::detect_current_os() { CurrentOperatingSystem::Linux => { notification.auto_icon().appname("Tari Universe").finalize() } @@ -52,17 +48,6 @@ impl NotificationManager { CurrentOperatingSystem::Windows => notification.finalize(), } } - fn detect_current_os() -> CurrentOperatingSystem { - if cfg!(target_os = "windows") { - CurrentOperatingSystem::Windows - } else if cfg!(target_os = "linux") { - CurrentOperatingSystem::Linux - } else if cfg!(target_os = "macos") { - CurrentOperatingSystem::MacOS - } else { - panic!("Unsupported OS"); - } - } pub fn current() -> &'static NotificationManager { &INSTANCE diff --git a/src-tauri/src/systemtray_manager.rs b/src-tauri/src/systemtray_manager.rs index cb1357155..cc29d1525 100644 --- a/src-tauri/src/systemtray_manager.rs +++ b/src-tauri/src/systemtray_manager.rs @@ -6,7 +6,10 @@ use tauri::{ SystemTrayMenuItem, }; -use crate::hardware_monitor::HardwareStatus; +use crate::{ + hardware_monitor::HardwareStatus, + utils::platform_utils::{CurrentOperatingSystem, PlatformUtils}, +}; const LOG_TARGET: &str = "tari::universe::systemtray_manager"; static INSTANCE: LazyLock = LazyLock::new(SystemtrayManager::new); @@ -64,12 +67,6 @@ impl SystrayItemId { } } -pub enum CurrentOperatingSystem { - Windows, - Linux, - MacOS, -} - #[derive(Debug, Clone)] pub struct SystrayData { pub cpu_hashrate: f64, @@ -135,7 +132,7 @@ impl SystemtrayManager { fn initialize_systray() -> SystemTray { info!(target: LOG_TARGET, "Initializing system tray"); - let current_os = SystemtrayManager::detect_current_os(); + let current_os = PlatformUtils::detect_current_os(); let systray = SystemTray::new(); let empty_data = SystrayData { @@ -162,7 +159,7 @@ impl SystemtrayManager { } fn internal_create_tooltip_from_data(data: SystrayData) -> String { - let current_os = SystemtrayManager::detect_current_os(); + let current_os = PlatformUtils::detect_current_os(); match current_os { CurrentOperatingSystem::Windows => { @@ -223,20 +220,8 @@ impl SystemtrayManager { .set_enabled(window.is_minimized().expect("Could not get is_minimized")); } - fn detect_current_os() -> CurrentOperatingSystem { - if cfg!(target_os = "windows") { - CurrentOperatingSystem::Windows - } else if cfg!(target_os = "linux") { - CurrentOperatingSystem::Linux - } else if cfg!(target_os = "macos") { - CurrentOperatingSystem::MacOS - } else { - panic!("Unsupported OS"); - } - } - pub fn update_systray(&self, app: AppHandle, data: SystrayData) { - let current_os = SystemtrayManager::detect_current_os(); + let current_os = PlatformUtils::detect_current_os(); let tooltip = SystemtrayManager::internal_create_tooltip_from_data(data.clone()); match current_os { @@ -284,7 +269,7 @@ impl SystemtrayManager { match id.as_str() { "unminimize" => { info!(target: LOG_TARGET, "Unminimizing window"); - match SystemtrayManager::detect_current_os() { + match PlatformUtils::detect_current_os() { CurrentOperatingSystem::Linux => { let is_minimized = window.is_minimized().unwrap_or(false); let is_visible = window.is_visible().unwrap_or(false); diff --git a/src-tauri/src/utils/mod.rs b/src-tauri/src/utils/mod.rs index ed44ce721..b78c24335 100644 --- a/src-tauri/src/utils/mod.rs +++ b/src-tauri/src/utils/mod.rs @@ -1,2 +1,3 @@ pub mod auto_rollback; pub mod file_utils; +pub mod platform_utils; diff --git a/src-tauri/src/utils/platform_utils.rs b/src-tauri/src/utils/platform_utils.rs new file mode 100644 index 000000000..61a2da481 --- /dev/null +++ b/src-tauri/src/utils/platform_utils.rs @@ -0,0 +1,20 @@ +pub enum CurrentOperatingSystem { + Windows, + Linux, + MacOS, +} + +pub struct PlatformUtils {} +impl PlatformUtils { + pub fn detect_current_os() -> CurrentOperatingSystem { + if cfg!(target_os = "windows") { + CurrentOperatingSystem::Windows + } else if cfg!(target_os = "linux") { + CurrentOperatingSystem::Linux + } else if cfg!(target_os = "macos") { + CurrentOperatingSystem::MacOS + } else { + panic!("Unsupported OS"); + } + } +} From 44cd444abc5008920ba75d58899cd5e9ba653f57 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Mon, 28 Oct 2024 08:59:27 +0100 Subject: [PATCH 12/17] remove unwraps --- src-tauri/src/main.rs | 2 +- src-tauri/src/notification_manager.rs | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 36a636e77..447088a5e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1070,7 +1070,7 @@ async fn get_seed_words( #[tauri::command] async fn trigger_notification(summary: &str, body: &str) -> Result<(), String> { - NotificationManager::current().trigger_notification(summary, body); + let _ = NotificationManager::current().trigger_notification(summary, body); Ok(()) } diff --git a/src-tauri/src/notification_manager.rs b/src-tauri/src/notification_manager.rs index 7c52757e7..c809be0cb 100644 --- a/src-tauri/src/notification_manager.rs +++ b/src-tauri/src/notification_manager.rs @@ -1,8 +1,8 @@ +use anyhow::Error; +use log::{info, warn}; use notify_rust::Notification; use std::sync::LazyLock; -use log::info; - use crate::utils::platform_utils::{CurrentOperatingSystem, PlatformUtils}; const LOG_TARGET: &str = "tari::universe::notification_manager"; @@ -15,24 +15,34 @@ impl NotificationManager { Self {} } - pub fn trigger_notification(&self, summary: &str, body: &str) { + pub fn trigger_notification(&self, summary: &str, body: &str) -> Result<(), Error> { info!(target: LOG_TARGET, "Triggering notification with summary: {} and body: {}", summary, body); let notification = self.build_notification(summary, body); match PlatformUtils::detect_current_os() { CurrentOperatingSystem::Linux => { #[cfg(target_os = "linux")] - notification.show().unwrap().on_close(|notification| { + let handle = notification.show().inspect_err( + |e| warn!(target: LOG_TARGET, "Failed to show notification: {:?}", e), + )?; + handle.on_close(|notification| { info!(target: LOG_TARGET, "Notification closed: {:?}", notification); }); + Ok(()) } CurrentOperatingSystem::MacOS => { #[cfg(target_os = "macos")] - notification.show().unwrap(); + notification.show().inspect_err( + |e| warn!(target: LOG_TARGET, "Failed to show notification: {:?}", e), + )?; + Ok(()) } CurrentOperatingSystem::Windows => { #[cfg(target_os = "windows")] - notification.show().unwrap(); + notification.show().inspect_err( + |e| warn!(target: LOG_TARGET, "Failed to show notification: {:?}", e), + )?; + Ok(()) } } } From 99ba6ee41e8606a616f5964359e4f64cfe2bfb0b Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Mon, 28 Oct 2024 09:18:43 +0100 Subject: [PATCH 13/17] fix unused --- src-tauri/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 447088a5e..4239febf3 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1070,7 +1070,7 @@ async fn get_seed_words( #[tauri::command] async fn trigger_notification(summary: &str, body: &str) -> Result<(), String> { - let _ = NotificationManager::current().trigger_notification(summary, body); + let _unused = NotificationManager::current().trigger_notification(summary, body); Ok(()) } From 4707e7afb91d4569bbc1cf1aa03f8f4891176106 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Tue, 10 Dec 2024 12:14:01 +0100 Subject: [PATCH 14/17] save --- src-tauri/Cargo.lock | 242 ++++++++++++++------------ src-tauri/Cargo.toml | 1 + src-tauri/capabilities/default.json | 6 +- src-tauri/src/commands.rs | 21 +++ src-tauri/src/main.rs | 4 +- src-tauri/src/notification_manager.rs | 1 + 6 files changed, 163 insertions(+), 112 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 0fe1ff007..d5c97d7ad 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -385,9 +385,9 @@ dependencies = [ [[package]] name = "atk" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4af014b17dd80e8af9fa689b2d4a211ddba6eb583c1622f35d0cb543f6b17e4" +checksum = "241b621213072e993be4f6f3a9e4b45f65b7e6faad43001be957184b7bb1824b" dependencies = [ "atk-sys", "glib", @@ -396,9 +396,9 @@ dependencies = [ [[package]] name = "atk-sys" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "251e0b7d90e33e0ba930891a505a9a35ece37b2dd37a14f3ffc306c13b980009" +checksum = "c5e48b684b0ca77d2bbadeef17424c2ea3c897d44d566a1617e7e8f30614d086" dependencies = [ "glib-sys", "gobject-sys", @@ -922,9 +922,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.38" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" dependencies = [ "android-tzdata", "iana-time-zone", @@ -1603,6 +1603,16 @@ dependencies = [ "dirs-sys-next", ] +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + [[package]] name = "dirs-sys" version = "0.3.7" @@ -2172,9 +2182,9 @@ checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" [[package]] name = "gdk" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5ba081bdef3b75ebcdbfc953699ed2d7417d6bd853347a42a37d76406a33646" +checksum = "d9f245958c627ac99d8e529166f9823fb3b838d1d41fd2b297af3075093c2691" dependencies = [ "cairo-rs", "gdk-pixbuf", @@ -2213,9 +2223,9 @@ dependencies = [ [[package]] name = "gdk-sys" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31ff856cb3386dae1703a920f803abafcc580e9b5f711ca62ed1620c25b51ff2" +checksum = "5c2d13f38594ac1e66619e188c6d5a1adb98d11b2fcf7894fc416ad76aa2f3f7" dependencies = [ "cairo-sys-rs", "gdk-pixbuf-sys", @@ -2230,9 +2240,9 @@ dependencies = [ [[package]] name = "gdkwayland-sys" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a90fbf5c033c65d93792192a49a8efb5bb1e640c419682a58bb96f5ae77f3d4a" +checksum = "140071d506d223f7572b9f09b5e155afbd77428cd5cc7af8f2694c41d98dfe69" dependencies = [ "gdk-sys", "glib-sys", @@ -2244,9 +2254,9 @@ dependencies = [ [[package]] name = "gdkx11" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db2ea8a4909d530f79921290389cbd7c34cb9d623bfe970eaae65ca5f9cd9cce" +checksum = "3caa00e14351bebbc8183b3c36690327eb77c49abc2268dd4bd36b856db3fbfe" dependencies = [ "gdk", "gdkx11-sys", @@ -2258,9 +2268,9 @@ dependencies = [ [[package]] name = "gdkx11-sys" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fee8f00f4ee46cad2939b8990f5c70c94ff882c3028f3cc5abf950fa4ab53043" +checksum = "6e2e7445fe01ac26f11601db260dd8608fe172514eb63b3b5e261ea6b0f4428d" dependencies = [ "gdk-sys", "glib-sys", @@ -2449,9 +2459,9 @@ dependencies = [ [[package]] name = "gtk" -version = "0.18.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93c4f5e0e20b60e10631a5f06da7fe3dda744b05ad0ea71fee2f47adf865890c" +checksum = "fd56fb197bfc42bd5d2751f4f017d44ff59fbb58140c6b49f9b3b2bdab08506a" dependencies = [ "atk", "cairo-rs", @@ -2470,9 +2480,9 @@ dependencies = [ [[package]] name = "gtk-sys" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771437bf1de2c1c0b496c11505bdf748e26066bbe942dfc8f614c9460f6d7722" +checksum = "8f29a1c21c59553eb7dd40e918be54dccd60c52b049b75119d5d96ce6b624414" dependencies = [ "atk-sys", "cairo-sys-rs", @@ -2488,9 +2498,9 @@ dependencies = [ [[package]] name = "gtk3-macros" -version = "0.18.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6063efb63db582968fb7df72e1ae68aa6360dcfb0a75143f34fc7d616bad75e" +checksum = "52ff3c5b21f14f0736fed6dcfc0bfb4225ebf5725f3c0209edeec181e4d73e9d" dependencies = [ "proc-macro-crate 1.1.3", "proc-macro-error", @@ -3415,9 +3425,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.167" +version = "0.2.168" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" +checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" [[package]] name = "liblmdb-sys" @@ -3835,9 +3845,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "minisign-verify" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a05b5d0594e0cb1ad8cee3373018d2b84e25905dc75b2468114cc9a8e86cfc20" +checksum = "6367d84fb54d4242af283086402907277715b8fe46976963af5ebf173f8efba3" [[package]] name = "miniz_oxide" @@ -3852,7 +3862,7 @@ dependencies = [ [[package]] name = "minotari_app_grpc" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "argon2", "base64 0.13.1", @@ -3882,7 +3892,7 @@ dependencies = [ [[package]] name = "minotari_ledger_wallet_common" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "bs58 0.5.1", ] @@ -3890,7 +3900,7 @@ dependencies = [ [[package]] name = "minotari_node_grpc_client" version = "0.1.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "minotari_app_grpc", ] @@ -3898,7 +3908,7 @@ dependencies = [ [[package]] name = "minotari_wallet_grpc_client" version = "0.1.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "minotari_app_grpc", "tari_common_types", @@ -4147,7 +4157,16 @@ dependencies = [ "mac-notification-sys", "serde", "tauri-winrt-notification", - "zbus 4.4.0", + "zbus", +] + +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", ] [[package]] @@ -4258,6 +4277,17 @@ dependencies = [ "malloc_buf", ] +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + [[package]] name = "objc-sys" version = "0.3.5" @@ -4476,6 +4506,15 @@ dependencies = [ "objc2-foundation", ] +[[package]] +name = "objc_id" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +dependencies = [ + "objc", +] + [[package]] name = "object" version = "0.36.5" @@ -4972,7 +5011,7 @@ checksum = "42cf17e9a1800f5f396bc67d193dc9411b59012a5876445ef450d449881e1016" dependencies = [ "base64 0.22.1", "indexmap 2.7.0", - "quick-xml", + "quick-xml 0.32.0", "serde", "time", ] @@ -6819,6 +6858,7 @@ dependencies = [ "tari_utilities", "tauri", "tauri-build", + "tauri-plugin-notification", "tauri-plugin-os", "tauri-plugin-process", "tauri-plugin-sentry", @@ -6857,11 +6897,11 @@ dependencies = [ [[package]] name = "tari_common" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "anyhow", "config", - "dirs-next", + "dirs-next 1.0.2", "log", "log4rs", "multiaddr", @@ -6881,7 +6921,7 @@ dependencies = [ [[package]] name = "tari_common_sqlite" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "diesel", "diesel_migrations", @@ -6895,7 +6935,7 @@ dependencies = [ [[package]] name = "tari_common_types" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "base64 0.21.7", "bitflags 2.6.0", @@ -6921,7 +6961,7 @@ dependencies = [ [[package]] name = "tari_comms" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "anyhow", "async-trait", @@ -6965,7 +7005,7 @@ dependencies = [ [[package]] name = "tari_comms_dht" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "anyhow", "bitflags 2.6.0", @@ -7000,7 +7040,7 @@ dependencies = [ [[package]] name = "tari_comms_rpc_macros" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "proc-macro2", "quote", @@ -7010,7 +7050,7 @@ dependencies = [ [[package]] name = "tari_core" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "anyhow", "async-trait", @@ -7024,7 +7064,7 @@ dependencies = [ "decimal-rs", "derivative", "digest", - "dirs-next", + "dirs-next 1.0.2", "fs2", "futures 0.3.31", "hex", @@ -7104,12 +7144,12 @@ dependencies = [ [[package]] name = "tari_features" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" [[package]] name = "tari_hashing" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "borsh", "digest", @@ -7119,7 +7159,7 @@ dependencies = [ [[package]] name = "tari_key_manager" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "argon2", "async-trait", @@ -7152,7 +7192,7 @@ dependencies = [ [[package]] name = "tari_max_size" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "borsh", "serde", @@ -7163,7 +7203,7 @@ dependencies = [ [[package]] name = "tari_mmr" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "borsh", "digest", @@ -7177,7 +7217,7 @@ dependencies = [ [[package]] name = "tari_p2p" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "anyhow", "fs2", @@ -7209,7 +7249,7 @@ dependencies = [ [[package]] name = "tari_script" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "blake2", "borsh", @@ -7227,7 +7267,7 @@ dependencies = [ [[package]] name = "tari_service_framework" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "anyhow", "async-trait", @@ -7242,7 +7282,7 @@ dependencies = [ [[package]] name = "tari_shutdown" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "futures 0.3.31", ] @@ -7250,7 +7290,7 @@ dependencies = [ [[package]] name = "tari_storage" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "bincode", "lmdb-zero", @@ -7262,7 +7302,7 @@ dependencies = [ [[package]] name = "tari_test_utils" version = "1.9.1-pre.0" -source = "git+https://github.com/tari-project/tari.git?branch=development#5f23ff054341edaaaed537ff2702a12a1fc5ef32" +source = "git+https://github.com/tari-project/tari.git?branch=development#317c74554315f6cd4d2c98802e20e4c2e4c5a0dc" dependencies = [ "futures 0.3.31", "rand 0.8.5", @@ -7422,11 +7462,30 @@ dependencies = [ "walkdir", ] +[[package]] +name = "tauri-plugin-notification" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46ab803095f14ac6521fdb6477210a49e86fed6623c3c97d8e4b2b35e045e922" +dependencies = [ + "log", + "notify-rust", + "rand 0.8.5", + "serde", + "serde_json", + "serde_repr", + "tauri", + "tauri-plugin", + "thiserror 2.0.6", + "time", + "url", +] + [[package]] name = "tauri-plugin-os" -version = "2.0.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc5f23a86f37687c7f4fecfdc706b279087bc44f7a46702f7307ff1551ee03a" +checksum = "dda2d571a9baf0664c1f2088db227e3072f9028602fafa885deade7547c3b738" dependencies = [ "gethostname", "log", @@ -7437,14 +7496,14 @@ dependencies = [ "sys-locale", "tauri", "tauri-plugin", - "thiserror 1.0.69", + "thiserror 2.0.6", ] [[package]] name = "tauri-plugin-process" -version = "2.0.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae06a00087c148962a52814a2d7265b1a0505bced5ffb74f8c284a5f96a4d03d" +checksum = "40cc553ab29581c8c43dfa5fb0c9d5aee8ba962ad3b42908eea26c79610441b7" dependencies = [ "tauri", "tauri-plugin", @@ -7468,9 +7527,9 @@ dependencies = [ [[package]] name = "tauri-plugin-shell" -version = "2.0.2" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad7880c5586b6b2104be451e3d7fc0f3800c84bda69e9ba81c828f87cb34267" +checksum = "bb2c50a63e60fb8925956cc5b7569f4b750ac197a4d39f13b8dd46ea8e2bad79" dependencies = [ "encoding_rs", "log", @@ -7483,15 +7542,15 @@ dependencies = [ "shared_child", "tauri", "tauri-plugin", - "thiserror 1.0.69", + "thiserror 2.0.6", "tokio", ] [[package]] name = "tauri-plugin-single-instance" -version = "2.0.2" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "494d348f82cfa766df4d2ebd96fc38b9cada6d120f13a36fd11395180213ec74" +checksum = "0f36019ee9832dc99e4450bb55a21cfad8633b19c2c18bd17c7741939b070ede" dependencies = [ "serde", "serde_json", @@ -7504,9 +7563,9 @@ dependencies = [ [[package]] name = "tauri-plugin-updater" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50ba9adaede60b0df5e0764692c6ac176eb133aade95d326bddeb968ad793320" +checksum = "4c3c24e75f8b9e6415968b9bafa746732dfa58d83294bc03b82975854af5e631" dependencies = [ "base64 0.22.1", "dirs 5.0.1", @@ -8839,16 +8898,14 @@ dependencies = [ ] [[package]] -name = "windows-core" -version = "0.58.0" +name = "windows-implement" +version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b" dependencies = [ - "windows-implement 0.58.0", - "windows-interface 0.58.0", - "windows-result 0.2.0", - "windows-strings", - "windows-targets 0.52.6", + "proc-macro2", + "quote", + "syn 2.0.90", ] [[package]] @@ -8884,17 +8941,6 @@ dependencies = [ "syn 2.0.90", ] -[[package]] -name = "windows-implement" -version = "0.58.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.90", -] - [[package]] name = "windows-interface" version = "0.57.0" @@ -9419,7 +9465,7 @@ dependencies = [ "async-trait", "blocking", "enumflags2", - "event-listener 2.5.3", + "event-listener", "futures-core", "futures-sink", "futures-util", @@ -9461,18 +9507,7 @@ checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c" dependencies = [ "serde", "static_assertions", - "zvariant 3.7.1", -] - -[[package]] -name = "zbus_names" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b9b1fef7d021261cc16cba64c351d291b715febe0fa10dc3a443ac5a5022e6c" -dependencies = [ - "serde", - "static_assertions", - "zvariant 4.2.0", + "zvariant", ] [[package]] @@ -9640,20 +9675,7 @@ dependencies = [ "enumflags2", "serde", "static_assertions", - "zvariant_derive 3.7.1", -] - -[[package]] -name = "zvariant" -version = "4.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2084290ab9a1c471c38fc524945837734fbf124487e105daec2bb57fd48c81fe" -dependencies = [ - "endi", - "enumflags2", - "serde", - "static_assertions", - "zvariant_derive 4.2.0", + "zvariant_derive", ] [[package]] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index ce2dd7f76..b881f5604 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -88,6 +88,7 @@ xz2 = { version = "0.1.7", features = ["static"] } # static bind lzma zip = "2.2.0" dirs = "5.0.1" tauri-plugin-process = "2" +tauri-plugin-notification = "2" [target.'cfg(windows)'.dependencies] winreg = "0.52.0" diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 540160433..9342eca63 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -16,6 +16,10 @@ "shell:allow-open", "sentry:default", "process:allow-restart", - "process:default" + "process:default", + "notification:allow-show", + "notification:allow-request-permission", + "notification:allow-permission-state", + "notification:allow-notify" ] } diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 290f262f9..6caf3979c 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -44,6 +44,7 @@ use log::{debug, error, info, warn}; use monero_address_creator::Seed as MoneroSeed; use regex::Regex; use serde::Serialize; +use tauri_plugin_notification::NotificationExt; use std::fs::{read_dir, remove_dir_all, remove_file, File}; use std::sync::atomic::Ordering; use std::thread::{available_parallelism, sleep}; @@ -524,6 +525,26 @@ pub async fn get_p2pool_stats( Ok(p2pool_stats) } +#[tauri::command] +pub async fn trigger_notification( + summary: String, + body: String, + app: tauri::AppHandle, +) -> Result<(), String> { + let timer = Instant::now(); + let notification = app.notification().builder() + .title(summary) + .body(body) + .icon("assets/icons/icon.png"); + + notification.show().map_err(|e| e.to_string())?; + + if timer.elapsed() > MAX_ACCEPTABLE_COMMAND_TIME { + warn!(target: LOG_TARGET, "trigger_notification took too long: {:?}", timer.elapsed()); + } + Ok(()) +} + #[tauri::command] pub async fn get_p2pool_connections( state: tauri::State<'_, UniverseAppState>, diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index e350e4186..ae8686709 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -682,6 +682,7 @@ fn main() { .plugin(tauri_plugin_process::init()) .plugin(tauri_plugin_sentry::init_with_no_injection(&client)) .plugin(tauri_plugin_os::init()) + .plugin(tauri_plugin_notification::init()) .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_single_instance::init(|app, argv, cwd| { println!("{}, {argv:?}, {cwd}", app.package_info().name); @@ -884,7 +885,8 @@ fn main() { commands::get_p2pool_connections, commands::set_p2pool_stats_server_port, commands::get_used_p2pool_stats_server_port, - commands::get_network + commands::get_network, + commands::trigger_notification ]) .build(tauri::generate_context!()) .inspect_err( diff --git a/src-tauri/src/notification_manager.rs b/src-tauri/src/notification_manager.rs index c809be0cb..f26dcd47b 100644 --- a/src-tauri/src/notification_manager.rs +++ b/src-tauri/src/notification_manager.rs @@ -3,6 +3,7 @@ use log::{info, warn}; use notify_rust::Notification; use std::sync::LazyLock; + use crate::utils::platform_utils::{CurrentOperatingSystem, PlatformUtils}; const LOG_TARGET: &str = "tari::universe::notification_manager"; From 3a7d11a4e001acd5da7f2f46fa47d35118a4adb7 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Tue, 10 Dec 2024 12:14:19 +0100 Subject: [PATCH 15/17] save --- src/containers/main/Dashboard/Dashboard.tsx | 8 ++++++++ src/hooks/useNotifications.ts | 3 ++- src/store/appStateStore.ts | 1 - src/store/useBlockchainVisualisationStore.ts | 7 ------- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/containers/main/Dashboard/Dashboard.tsx b/src/containers/main/Dashboard/Dashboard.tsx index ad8445f95..3ceae0fa3 100644 --- a/src/containers/main/Dashboard/Dashboard.tsx +++ b/src/containers/main/Dashboard/Dashboard.tsx @@ -1,7 +1,15 @@ +import { useNotifcations } from '@app/hooks/useNotifications'; import MiningView from './MiningView/MiningView'; import { DashboardContentContainer } from './styles'; +import { useEffect } from 'react'; export default function Dashboard() { + const { testNotification } = useNotifcations(); + + useEffect(() => { + testNotification(); + }, [testNotification]); + return ( diff --git a/src/hooks/useNotifications.ts b/src/hooks/useNotifications.ts index 8b3b9e967..e61020e37 100644 --- a/src/hooks/useNotifications.ts +++ b/src/hooks/useNotifications.ts @@ -1,4 +1,4 @@ -import { invoke } from '@tauri-apps/api/tauri'; +import { invoke } from '@tauri-apps/api/core'; import { useCallback } from 'react'; export const useNotifcations = () => { @@ -10,6 +10,7 @@ export const useNotifcations = () => { }, []); const testNotification = useCallback(async () => { + console.log('testNotification'); await invoke('trigger_notification', { summary: 'Test Notification', body: 'This is a test notification.', diff --git a/src/store/appStateStore.ts b/src/store/appStateStore.ts index 3c80fad31..77ecb0622 100644 --- a/src/store/appStateStore.ts +++ b/src/store/appStateStore.ts @@ -128,7 +128,6 @@ export const useAppStateStore = create()((set, getState) => ({ body, }); } catch (error) { - Sentry.captureException(error); console.error('Error triggering notification', error); } }, diff --git a/src/store/useBlockchainVisualisationStore.ts b/src/store/useBlockchainVisualisationStore.ts index 42baa7b50..c682c4cab 100644 --- a/src/store/useBlockchainVisualisationStore.ts +++ b/src/store/useBlockchainVisualisationStore.ts @@ -105,13 +105,6 @@ export const useBlockchainVisualisationStore = create Date: Thu, 12 Dec 2024 08:58:59 +0100 Subject: [PATCH 16/17] update --- src-tauri/capabilities/default.json | 4 +++- src-tauri/src/commands.rs | 2 ++ src/containers/main/Dashboard/Dashboard.tsx | 6 ------ .../components/MiningButton/MiningButton.tsx | 4 ++++ src/hooks/useNotifications.ts | 16 ++++++++++++++++ 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 9342eca63..27f023c98 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -20,6 +20,8 @@ "notification:allow-show", "notification:allow-request-permission", "notification:allow-permission-state", - "notification:allow-notify" + "notification:allow-notify", + "notification:allow-is-permission-granted", + "notification:default" ] } diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 03991eb2e..de156be20 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -32,6 +32,7 @@ use crate::gpu_miner_adapter::{GpuMinerStatus, GpuNodeSource}; use crate::hardware::hardware_status_monitor::{HardwareStatusMonitor, PublicDeviceProperties}; use crate::internal_wallet::{InternalWallet, PaperWalletConfig}; use crate::node_manager::NodeManagerError; +use crate::notification_manager::NotificationManager; use crate::p2pool::models::{Connections, Stats}; use crate::progress_tracker::ProgressTracker; use crate::tor_adapter::TorConfig; @@ -532,6 +533,7 @@ pub async fn trigger_notification( app: tauri::AppHandle, ) -> Result<(), String> { let timer = Instant::now(); + // NotificationManager::current().trigger_notification(&summary, &body).map_err(|e| e.to_string())?; let notification = app.notification().builder() .title(summary) .body(body) diff --git a/src/containers/main/Dashboard/Dashboard.tsx b/src/containers/main/Dashboard/Dashboard.tsx index 3ceae0fa3..c8947b54b 100644 --- a/src/containers/main/Dashboard/Dashboard.tsx +++ b/src/containers/main/Dashboard/Dashboard.tsx @@ -4,12 +4,6 @@ import { DashboardContentContainer } from './styles'; import { useEffect } from 'react'; export default function Dashboard() { - const { testNotification } = useNotifcations(); - - useEffect(() => { - testNotification(); - }, [testNotification]); - return ( diff --git a/src/containers/main/SideBar/components/MiningButton/MiningButton.tsx b/src/containers/main/SideBar/components/MiningButton/MiningButton.tsx index 4aa174225..ceba1f21f 100644 --- a/src/containers/main/SideBar/components/MiningButton/MiningButton.tsx +++ b/src/containers/main/SideBar/components/MiningButton/MiningButton.tsx @@ -12,6 +12,7 @@ import LoadingSvg from '@app/components/svgs/LoadingSvg.tsx'; import ButtonOrbitAnimation from '../../Miner/components/ButtonOrbitAnimation.tsx'; import { IconWrapper, StyledButton, ButtonWrapper } from './MiningButton.styles.ts'; import { SpinnerIcon } from '@app/components/elements/loaders/SpinnerIcon.tsx'; +import { useNotifcations } from '@app/hooks/useNotifications.ts'; enum MiningButtonStateText { STARTED = 'stop-mining', @@ -19,6 +20,8 @@ enum MiningButtonStateText { } export default function MiningButton() { + const { testNotification } = useNotifcations(); + const { t } = useTranslation('mining-view', { useSuspense: false }); const startMining = useMiningStore((s) => s.startMining); const stopMining = useMiningStore((s) => s.stopMining); @@ -40,6 +43,7 @@ export default function MiningButton() { }, [isMining, isMiningInitiated]); const handleClick = useCallback(async () => { + await testNotification(); if (!isMining) { await startMining(); } else { diff --git a/src/hooks/useNotifications.ts b/src/hooks/useNotifications.ts index e61020e37..d763631c2 100644 --- a/src/hooks/useNotifications.ts +++ b/src/hooks/useNotifications.ts @@ -1,5 +1,6 @@ import { invoke } from '@tauri-apps/api/core'; import { useCallback } from 'react'; +import { isPermissionGranted, requestPermission, sendNotification } from '@tauri-apps/plugin-notification'; export const useNotifcations = () => { const winNotification = useCallback(async (winAmount: string) => { @@ -11,6 +12,21 @@ export const useNotifcations = () => { const testNotification = useCallback(async () => { console.log('testNotification'); + // Do you have permission to send a notification? + let permissionGranted = await isPermissionGranted(); + + console.log('permissionGranted', permissionGranted); + // If not we need to request it + if (!permissionGranted) { + const permission = await requestPermission(); + permissionGranted = permission === 'granted'; + } + + // Once permission has been granted we can send the notification + if (permissionGranted) { + sendNotification({ title: 'Tauri', body: 'Tauri is awesome!' }); + } + await invoke('trigger_notification', { summary: 'Test Notification', body: 'This is a test notification.', From ad569f9fa604ce5f20fe42df152c0027d1518477 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Thu, 12 Dec 2024 14:14:46 +0100 Subject: [PATCH 17/17] adjust linux code --- src-tauri/src/notification_manager.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/notification_manager.rs b/src-tauri/src/notification_manager.rs index f26dcd47b..dad3f2d7b 100644 --- a/src-tauri/src/notification_manager.rs +++ b/src-tauri/src/notification_manager.rs @@ -23,12 +23,15 @@ impl NotificationManager { match PlatformUtils::detect_current_os() { CurrentOperatingSystem::Linux => { #[cfg(target_os = "linux")] - let handle = notification.show().inspect_err( - |e| warn!(target: LOG_TARGET, "Failed to show notification: {:?}", e), - )?; - handle.on_close(|notification| { - info!(target: LOG_TARGET, "Notification closed: {:?}", notification); - }); + { + let handle = notification.show().inspect_err( + |e| warn!(target: LOG_TARGET, "Failed to show notification: {:?}", e), + )?; + handle.on_close(|notification| { + info!(target: LOG_TARGET, "Notification closed: {:?}", notification); + }); + } + Ok(()) } CurrentOperatingSystem::MacOS => {