Skip to content

Commit

Permalink
feat: reimpl windows 7 notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Dec 17, 2024
1 parent b48cef6 commit 2c3d07a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ tauri-plugin-single-instance = "2.0"
tauri-plugin-process = "2.0"
tauri-plugin-autostart = "2.0"
tauri-plugin-http = "2.0"
tauri-plugin-notification = "2.0"
# window blur
window-vibrancy = { version = "0.5.0", optional = true }

Expand All @@ -52,9 +53,6 @@ rsrpc = { git = "https://www.github.com/SpikeHD/rsRPC", tag = "v0.21.1", optiona
window_titles = { git = "https://github.com/SpikeHD/window_titles", branch = "master" }
mundy = { version = "0.1.2", features = ["accent-color", "callback"] }

[target.'cfg(not(windows))'.dependencies]
tauri-plugin-notification = "2.0"

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
webkit2gtk = { version = "2.0", features = ["v2_4"] }
wgpu = { version = "23.0", default-features = false }
Expand Down Expand Up @@ -107,6 +105,8 @@ features = [
"Win32_System_Com",
"Win32_Graphics",
"Win32_Graphics_Dwm",
"Win32_System_SystemInformation",
"Wdk_System_SystemServices"
]

[target.armv7-unknown-linux-gnueabihf]
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ fn main() {
log!("Panic occurred: {:?}", info);
}));

log!("Are we on Windows 7: {}", helpers::is_windows_7());

let mut config = get_config();

// Check if the deprecated theme option is being used
Expand Down
14 changes: 14 additions & 0 deletions src-tauri/src/util/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,17 @@ pub fn get_platform() -> &'static str {
#[cfg(target_os = "linux")]
"linux"
}

#[cfg(target_os = "windows")]
pub fn is_windows_7() -> bool {
use windows::{Wdk::System::SystemServices::RtlGetVersion, Win32::System::SystemInformation::OSVERSIONINFOW};

let mut osvi = OSVERSIONINFOW::default();
osvi.dwOSVersionInfoSize = std::mem::size_of::<OSVERSIONINFOW>() as u32;

unsafe {
let _ = RtlGetVersion(&mut osvi);
}

osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1
}
18 changes: 13 additions & 5 deletions src-tauri/src/util/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::{
};
use tauri::Manager;

use super::helpers::is_windows_7;

#[tauri::command]
pub fn send_notification(win: tauri::WebviewWindow, title: String, body: String, icon: String) {
// Write the result of the icon
Expand Down Expand Up @@ -51,11 +53,18 @@ pub fn send_notification(win: tauri::WebviewWindow, title: String, body: String,

icon_path.push_str(&tmp_file.to_str().unwrap_or_default().replace('\\', "/"));

send_notification_internal(app, title, body, icon_path);
send_notification_internal(app, title, body, icon_path.clone());
}

fn send_notification_internal(app: &tauri::AppHandle, title: String, body: String, icon_path: String) {
if cfg!(target_os = "windows") && !is_windows_7() {
send_notification_internal_windows(app, title, body, icon_path)
} else {
send_notification_internal_other(app, title, body, icon_path)
}
}

#[cfg(not(target_os = "windows"))]
fn send_notification_internal(app: &tauri::AppHandle, title: String, body: String, icon: String) {
fn send_notification_internal_other(app: &tauri::AppHandle, title: String, body: String, icon: String) {
use tauri_plugin_notification::NotificationExt;

app
Expand All @@ -68,8 +77,7 @@ 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) {
fn send_notification_internal_windows(app: &tauri::AppHandle, title: String, body: String, icon: String) {
use crate::util::window_helpers::ultrashow;
use std::path::Path;
use tauri_winrt_notification::{IconCrop, Toast};
Expand Down

0 comments on commit 2c3d07a

Please sign in to comment.