Skip to content

Commit

Permalink
feat: support notification on macos (no action)
Browse files Browse the repository at this point in the history
  • Loading branch information
polnico authored and Martichou committed Jul 3, 2024
1 parent 2e7857c commit 8a57a11
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions app/main/src-tauri/src/notification.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
#[cfg(target_os = "linux")]
use notify_rust::Notification;
use rqs_lib::channel::{ChannelAction, ChannelDirection, ChannelMessage};
use rqs_lib::Visibility;
use tauri::{AppHandle, Manager};
#[cfg(target_os = "linux")]
use rqs_lib::{
channel::{ChannelAction, ChannelDirection, ChannelMessage},
Visibility,
};
use tauri::AppHandle;
#[cfg(target_os = "linux")]
use tauri::Manager;
#[cfg(not(target_os = "linux"))]
use tauri_plugin_notification::NotificationExt;

#[cfg(target_os = "linux")]
use crate::cmds;

pub fn send_request_notification(name: String, id: String, app_handle: &AppHandle) {
pub fn send_request_notification(name: String, _id: String, app_handle: &AppHandle) {
let body = format!("{name} want to initiate a transfer");

#[cfg(not(target_os = "linux"))]
let _ = app_handle
.notification()
.builder()
.title("RQuickShare")
.body(&body)
.show();

#[cfg(target_os = "linux")]
match Notification::new()
.summary("RQuickShare")
Expand All @@ -21,12 +36,13 @@ pub fn send_request_notification(name: String, id: String, app_handle: &AppHandl
Ok(n) => {
let capp_handle = app_handle.clone();
// TODO - Meh, untracked, unwaited tasks...
#[cfg(target_os = "linux")]
tokio::task::spawn(async move {
n.wait_for_action(|action| match action {
"accept" => {
let _ = cmds::send_to_rs(
ChannelMessage {
id,
_id,
direction: ChannelDirection::FrontToLib,
action: Some(ChannelAction::AcceptTransfer),
..Default::default()
Expand All @@ -37,7 +53,7 @@ pub fn send_request_notification(name: String, id: String, app_handle: &AppHandl
"reject" => {
let _ = cmds::send_to_rs(
ChannelMessage {
id,
_id,
direction: ChannelDirection::FrontToLib,
action: Some(ChannelAction::RejectTransfer),
..Default::default()
Expand All @@ -53,6 +69,10 @@ pub fn send_request_notification(name: String, id: String, app_handle: &AppHandl
error!("Couldn't show notification: {}", e);
}
}
}

pub fn send_temporarily_notification(app_handle: &AppHandle) {
let body = format!("RQuickShare is temporarily hidden");

#[cfg(not(target_os = "linux"))]
let _ = app_handle
Expand All @@ -61,12 +81,11 @@ pub fn send_request_notification(name: String, id: String, app_handle: &AppHandl
.title("RQuickShare")
.body(&body)
.show();
}

pub fn send_temporarily_notification(app_handle: &AppHandle) {
#[cfg(target_os = "linux")]
match Notification::new()
.summary("RQuickShare")
.body("A device is sharing nearby")
.body(&body)
.action("visible", "Be visible (1m)")
.action("ignore", "Ignore")
.id(1919)
Expand All @@ -75,6 +94,7 @@ pub fn send_temporarily_notification(app_handle: &AppHandle) {
Ok(n) => {
let capp_handle = app_handle.clone();
// TODO - Meh, untracked, unwaited tasks...
#[cfg(target_os = "linux")]
tokio::task::spawn(async move {
n.wait_for_action(|action| match action {
"visible" => {
Expand Down

0 comments on commit 8a57a11

Please sign in to comment.