diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 6836d71e..dc07ad3f 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -29,11 +29,11 @@ dependencies = [ "tauri-build", "tauri-plugin-autostart", "tauri-plugin-http", - "tauri-plugin-notification", "tauri-plugin-process", "tauri-plugin-shell", "tauri-plugin-single-instance", "tauri-plugin-window-state", + "tauri-winrt-notification", "webkit2gtk", "webview2-com", "wgpu", @@ -41,7 +41,7 @@ dependencies = [ "window_titles", "windows 0.58.0", "windows-core 0.58.0", - "windows-implement 0.58.0", + "windows-implement", ] [[package]] @@ -1034,16 +1034,6 @@ dependencies = [ "dirs-sys 0.4.1", ] -[[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" @@ -1067,17 +1057,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "dirs-sys-next" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - [[package]] name = "dispatch" version = "0.2.0" @@ -2510,19 +2489,6 @@ 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", - "objc-foundation", - "objc_id", - "time", -] - [[package]] name = "macos-accessibility-client" version = "0.0.1" @@ -2773,19 +2739,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" -[[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" @@ -2840,17 +2793,6 @@ 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" @@ -3069,15 +3011,6 @@ 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" @@ -4840,27 +4773,6 @@ dependencies = [ "urlpattern", ] -[[package]] -name = "tauri-plugin-notification" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef492a2d19b6376bb4c9e0c4fab3f3bf8a220ea112d24f35027b737ff55de20c" -dependencies = [ - "log", - "notify-rust", - "rand 0.8.5", - "serde", - "serde_json", - "serde_repr", - "tauri", - "tauri-plugin", - "thiserror", - "time", - "url", - "win7-notifications", - "windows-version", -] - [[package]] name = "tauri-plugin-process" version = "2.0.1" @@ -5013,12 +4925,13 @@ dependencies = [ [[package]] name = "tauri-winrt-notification" -version = "0.2.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f89f5fb70d6f62381f5d9b2ba9008196150b40b75f3068eb24faeddf1c686871" +checksum = "e3ecbfeedbd4e41fd66dc3c01951f49af81a824c4f493c02d91b837cf01caf69" dependencies = [ "quick-xml 0.31.0", - "windows 0.56.0", + "thiserror", + "windows 0.58.0", "windows-version", ] @@ -5720,8 +5633,8 @@ dependencies = [ "webview2-com-sys", "windows 0.58.0", "windows-core 0.58.0", - "windows-implement 0.58.0", - "windows-interface 0.58.0", + "windows-implement", + "windows-interface", ] [[package]] @@ -5853,16 +5766,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" -[[package]] -name = "win7-notifications" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63b4745047a00800bd8f2b8fb4b0eb6f7d96822084127f0ff7d68d07f692fe38" -dependencies = [ - "once_cell", - "windows-sys 0.59.0", -] - [[package]] name = "winapi" version = "0.3.9" @@ -5936,16 +5839,6 @@ 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.58.0" @@ -5965,42 +5858,19 @@ 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.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" dependencies = [ - "windows-implement 0.58.0", - "windows-interface 0.58.0", - "windows-result 0.2.0", + "windows-implement", + "windows-interface", + "windows-result", "windows-strings", "windows-targets 0.52.6", ] -[[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.85", -] - [[package]] name = "windows-implement" version = "0.58.0" @@ -6012,17 +5882,6 @@ dependencies = [ "syn 2.0.85", ] -[[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.85", -] - [[package]] name = "windows-interface" version = "0.58.0" @@ -6040,20 +5899,11 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" dependencies = [ - "windows-result 0.2.0", + "windows-result", "windows-strings", "windows-targets 0.52.6", ] -[[package]] -name = "windows-result" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-result" version = "0.2.0" @@ -6069,7 +5919,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" dependencies = [ - "windows-result 0.2.0", + "windows-result", "windows-targets 0.52.6", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 1c37fe64..fcfe5edd 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -36,8 +36,8 @@ tauri-plugin-shell = "=2.0.1" tauri-plugin-single-instance = "2.0" tauri-plugin-process = "2.0" tauri-plugin-autostart = "2.0" -tauri-plugin-notification = { version = "2.0", features = ["win7-notifications", "windows7-compat"] } tauri-plugin-http = "2.0" +tauri-winrt-notification = "0.6" # window blur window-vibrancy = { version = "0.5.0", optional = true } diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index a491c257..63ac79b5 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -31,7 +31,6 @@ "process:default", "autostart:default", "window-state:default", - "notification:default", { "identifier": "http:default", "allow": [ diff --git a/src-tauri/injection/preinject.ts b/src-tauri/injection/preinject.ts index 99103df3..1602829d 100644 --- a/src-tauri/injection/preinject.ts +++ b/src-tauri/injection/preinject.ts @@ -1,4 +1,4 @@ -import { badPostMessagePatch, createLocalStorage, proxyFetch, proxyXHR, proxyAddEventListener, proxyOpen } from './shared/recreate' +import { badPostMessagePatch, createLocalStorage, proxyFetch, proxyXHR, proxyAddEventListener, proxyOpen, proxyNotification } from './shared/recreate' import { extraCssChangeWatch, safemodeTimer, typingAnim } from './shared/ui' import { cssSanitize, fetchImage, isJson, waitForApp, waitForElm, saferEval } from './shared/util' import { applyNotificationCount } from './shared/window' @@ -41,6 +41,7 @@ if (!window.__DORION_INITIALIZED__) window.__DORION_INITIALIZED__ = false proxyFetch() proxyXHR() proxyAddEventListener() + proxyNotification() while (!window.__TAURI__) { console.log('Waiting for definition...') diff --git a/src-tauri/injection/shared/recreate.ts b/src-tauri/injection/shared/recreate.ts index 7524c00b..c4ba8226 100644 --- a/src-tauri/injection/shared/recreate.ts +++ b/src-tauri/injection/shared/recreate.ts @@ -137,3 +137,40 @@ export function badPostMessagePatch() { return null } } + +export function proxyNotification() { + let permVal = 'granted' + + // @ts-expect-error shut up + window.nativeNotification = window.Notification + + // @ts-expect-error shut up + window.Notification = function(title, options) { + const { invoke } = window.__TAURI__.core + const body = options?.body || '' + let icon = options?.icon || '' + + // If the icon is a relative path, convert to full path using URI + if (icon.startsWith('/')) { + icon = window.location.origin + icon + } + + invoke('send_notification', { + title, + body, + icon, + }) + + // return new window.nativeNotification(title, options) + } + + window.Notification.requestPermission = async () => 'granted' + + Object.defineProperty(window.Notification, 'permission', { + enumerable: true, + get: () => permVal, + set: (v) => { + permVal = v + } + }) +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 0422f379..446fb472 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -124,13 +124,11 @@ fn main() { tauri::Builder::default() .plugin(tauri_plugin_http::init()) .plugin(tauri_plugin_shell::init()) - .plugin(tauri_plugin_notification::init()) .plugin(tauri_plugin_autostart::init( tauri_plugin_autostart::MacosLauncher::LaunchAgent, Some(vec!["--startup"]), )) .plugin(tauri_plugin_process::init()) - .plugin(tauri_plugin_notification::init()) .plugin(tauri_plugin_window_state::Builder::new().build()) .invoke_handler(tauri::generate_handler![ should_disable_plugins, diff --git a/src-tauri/src/util/notifications.rs b/src-tauri/src/util/notifications.rs index fa75de8d..f1407c3c 100644 --- a/src-tauri/src/util/notifications.rs +++ b/src-tauri/src/util/notifications.rs @@ -5,7 +5,6 @@ use crate::{ log, }; use tauri::Manager; -use tauri_plugin_notification::NotificationExt; #[tauri::command] pub fn send_notification(win: tauri::WebviewWindow, title: String, body: String, icon: String) { @@ -14,7 +13,8 @@ pub fn send_notification(win: tauri::WebviewWindow, title: String, body: String, let client = reqwest::blocking::Client::new(); let mut res = match client.get(icon).send() { Ok(res) => res, - Err(_) => { + Err(e) => { + log!("Failed to fetch notification icon: {:?}", e); send_notification_internal(app, title, body, String::new()); return; } @@ -27,6 +27,7 @@ pub fn send_notification(win: tauri::WebviewWindow, title: String, body: String, let file = match std::fs::File::create(&tmp_file) { Ok(file) => file, Err(_) => { + log!("Failed to create temp file for notification icon"); send_notification_internal(app, title, body, String::new()); return; } @@ -41,10 +42,10 @@ pub fn send_notification(win: tauri::WebviewWindow, title: String, body: String, } } - // Create file:// uri #[cfg(target_os = "windows")] - let mut icon_path = String::from("file:///"); + let mut icon_path = String::new(); + // Create file:// uri #[cfg(not(target_os = "windows"))] let mut icon_path = String::from("file://"); @@ -53,7 +54,10 @@ pub fn send_notification(win: tauri::WebviewWindow, title: String, body: String, send_notification_internal(app, title, body, icon_path); } +#[cfg(not(target_os = "windows"))] fn send_notification_internal(app: &tauri::AppHandle, title: String, body: String, icon: String) { + use tauri_plugin_notification::NotificationExt; + app .notification() .builder() @@ -64,6 +68,20 @@ fn send_notification_internal(app: &tauri::AppHandle, title: String, body: Strin .unwrap_or_default(); } +#[cfg(target_os = "windows")] +fn send_notification_internal(_app: &tauri::AppHandle, title: String, body: String, icon: String) { + use std::path::Path; + use tauri_winrt_notification::{IconCrop, Toast}; + + Toast::new(Toast::POWERSHELL_APP_ID) + .icon(Path::new(&icon), IconCrop::Circular, "") + .title(title.as_str()) + .text2(body.as_str()) + .sound(None) + .show() + .unwrap_or_else(|e| log!("Failed to send notification: {:?}", e)); +} + #[tauri::command] pub fn notif_count(window: tauri::WebviewWindow, amount: i32) { log!("Setting notification count: {}", amount);