Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show system notifications #510

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 144 additions & 3 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ minotari_node_grpc_client = { git = "https://github.com/tari-project/tari.git",
minotari_wallet_grpc_client = { git = "https://github.com/tari-project/tari.git", branch = "development" }
monero-address-creator = { git = "https://github.com/tari-project/monero-address-creator.git", rev = "6129ca0" }
nix = { version = "0.29.0", features = ["signal"] }
notify-rust = "4.11.3"
nvml-wrapper = "0.10.0"
open = "5"
phraze = "0.3.15"
Expand Down Expand Up @@ -87,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"

# temporary fix for openssl
openssl = { version = "0.10", features = ["vendored"] }
Expand All @@ -102,6 +104,7 @@ log = "0.4.22"
nvml-wrapper = "0.10.0"
rand = "0.8.5"
sys-locale = "0.3.1"
notify-rust = "4.11.3"
# tonic = "0.12.0"

[features]
Expand Down
8 changes: 7 additions & 1 deletion src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
"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",
"notification:allow-is-permission-granted",
"notification:default"
]
}
24 changes: 4 additions & 20 deletions src-tauri/src/auto_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,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<AutoLauncher> = LazyLock::new(AutoLauncher::new);

pub enum CurrentOperatingSystem {
Windows,
Linux,
MacOS,
}

pub struct AutoLauncher {
auto_launcher: RwLock<Option<AutoLaunch>>,
}
Expand All @@ -50,22 +46,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<AutoLaunch, anyhow::Error> {
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)
Expand Down Expand Up @@ -101,7 +85,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
Expand Down
23 changes: 23 additions & 0 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,6 +45,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};
Expand Down Expand Up @@ -524,6 +526,27 @@ 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();
// NotificationManager::current().trigger_notification(&summary, &body).map_err(|e| e.to_string())?;
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>,
Expand Down
Loading
Loading