Skip to content

Commit

Permalink
feat: alternative notification style (windows)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Jan 7, 2025
1 parent 7e34138 commit 5a703df
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 9 deletions.
25 changes: 23 additions & 2 deletions src-tauri/Cargo.lock

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

4 changes: 2 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ tauri-plugin-window-state = "2.0"
[target.'cfg(windows)'.dependencies]
tauri-winrt-notification = "0.7"
webview2-com = "0.34.0"
windows-core = "0.58.0"
windows-implement = "0.58.0"
win7-notifications = "0.4.5"
windows-implement = "0.59.0"

[target.'cfg(windows)'.dependencies.windows]
version = "0.58.0"
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub struct Config {
pub keybinds: Option<HashMap<String, Vec<KeyStruct>>>,
pub keybinds_enabled: Option<bool>,

pub win7_style_notifications: Option<bool>,

// RPC-specific options
pub rpc_process_scanner: Option<bool>,
pub rpc_ipc_connector: Option<bool>,
Expand Down Expand Up @@ -87,6 +89,8 @@ impl Config {
keybinds: Option::from(HashMap::new()),
keybinds_enabled: Option::from(true),

win7_style_notifications: Option::from(false),

// RPC-specific options
rpc_process_scanner: Option::from(true),
rpc_ipc_connector: Option::from(true),
Expand Down Expand Up @@ -131,6 +135,10 @@ impl Config {
keybinds: other.keybinds.or(self.keybinds.clone()),
keybinds_enabled: other.keybinds_enabled.or(self.keybinds_enabled),

win7_style_notifications: other
.win7_style_notifications
.or(self.win7_style_notifications),

rpc_process_scanner: other.rpc_process_scanner.or(self.rpc_process_scanner),
rpc_ipc_connector: other.rpc_ipc_connector.or(self.rpc_ipc_connector),
rpc_websocket_connector: other
Expand Down
34 changes: 32 additions & 2 deletions src-tauri/src/util/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,20 @@ fn send_notification_internal(
) {
#[cfg(target_os = "windows")]
{
if !is_windows_7() {
use crate::config::get_config;

if !is_windows_7() && !get_config().win7_style_notifications.unwrap_or(false) {
send_notification_internal_windows(app, title, body, icon_path)
} else {
send_notification_internal_other(app, title, body, icon_path)
send_notification_internal_windows7(app, title, body, icon_path)
}
}

#[cfg(not(target_os = "windows"))]
send_notification_internal_other(app, title, body, icon_path)
}

#[cfg(not(target_os = "windows"))]
fn send_notification_internal_other(
_app: &tauri::AppHandle,
title: String,
Expand Down Expand Up @@ -125,6 +128,33 @@ fn send_notification_internal_windows(
.unwrap_or_else(|e| log!("Failed to send notification: {:?}", e));
}

#[cfg(target_os = "windows")]
fn send_notification_internal_windows7(
app: &tauri::AppHandle,
title: String,
body: String,
icon: String,
) {
use std::path::Path;
use win7_notifications::Notification;

let icon = tauri::image::Image::from_path(Path::new(&icon));
let mut notification = Notification::new();

notification
.appname(&app.package_info().name)
.summary(&title)
.body(&body);

if let Ok(icon) = icon {
notification.icon(icon.rgba().to_vec(), icon.width(), icon.height());
}

notification
.show()
.unwrap_or_else(|e| log!("Failed to send notification: {:?}", e));
}

#[tauri::command]
pub fn notification_count(window: tauri::WebviewWindow, amount: i64) {
log!("Setting notification count: {}", amount);
Expand Down
3 changes: 1 addition & 2 deletions src-tauri/src/util/window_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ pub fn remove_top_bar(_win: tauri::WebviewWindow) {}
pub fn set_user_agent(win: &tauri::WebviewWindow) {
use tauri::webview::PlatformWebview;
use webview2_com::Microsoft::Web::WebView2::Win32::{ICoreWebView2Settings2, ICoreWebView2_2};
use windows::core::{Interface, HSTRING};
use windows_core::PWSTR;
use windows::core::{Interface, HSTRING, PWSTR};

win
.with_webview(|webview| unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
"csp": null
}
}
}
}

0 comments on commit 5a703df

Please sign in to comment.