[READ-ONLY] Mirror of https://github.com/probablykasper/remind-me-again. Toggleable cron reminders app for Mac, Linux and Windows
linux macos notifications reminder tauri windows
0

Configure Feed

Select the types of activity you want to include in your feed.

Show only `Done` button on macOS

Kasper (May 6, 2023, 11:25 PM +0200) 3131c992 f3e3c558

+64 -24
+3
CHANGELOG.md
··· 1 1 # Changelog 2 2 3 + ## Next 4 + - Show only `Done` button on macOS 5 + 3 6 ## 1.1.1 - 2022 Dec 10 4 7 - Update dependencies 5 8
+14 -2
src-tauri/Cargo.lock
··· 1796 1796 ] 1797 1797 1798 1798 [[package]] 1799 + name = "mac-notification-sys" 1800 + version = "0.5.6" 1801 + source = "git+https://github.com/probablykasper/mac-notification-sys?rev=43a2fbf9c4ef8717f7736a99c456e21725ab274d#43a2fbf9c4ef8717f7736a99c456e21725ab274d" 1802 + dependencies = [ 1803 + "cc", 1804 + "dirs-next", 1805 + "objc-foundation", 1806 + "objc_id", 1807 + "time 0.3.15", 1808 + ] 1809 + 1810 + [[package]] 1799 1811 name = "macos-app-nap" 1800 1812 version = "0.0.1" 1801 1813 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1972 1984 checksum = "2bfa211d18e360f08e36c364308f394b5eb23a6629150690e109a916dc6f610e" 1973 1985 dependencies = [ 1974 1986 "log", 1975 - "mac-notification-sys", 1987 + "mac-notification-sys 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", 1976 1988 "serde", 1977 1989 "tauri-winrt-notification", 1978 1990 "zbus", ··· 2621 2633 "atomicwrites", 2622 2634 "chrono", 2623 2635 "cocoa", 2624 - "mac-notification-sys", 2636 + "mac-notification-sys 0.5.6 (git+https://github.com/probablykasper/mac-notification-sys?rev=43a2fbf9c4ef8717f7736a99c456e21725ab274d)", 2625 2637 "macos-app-nap", 2626 2638 "nanoid", 2627 2639 "objc",
+2 -1
src-tauri/Cargo.toml
··· 26 26 macos-app-nap = "0.0" 27 27 cocoa = "0.24" 28 28 objc = "0.2" 29 - mac-notification-sys = "0.5" 29 + # mac-notification-sys = "0.5" 30 + mac-notification-sys = { git = "https://github.com/probablykasper/mac-notification-sys", rev = "43a2fbf9c4ef8717f7736a99c456e21725ab274d" } 30 31 31 32 [features] 32 33 default = [ "custom-protocol" ]
+5 -5
src-tauri/src/main.rs
··· 49 49 data::RemindersFile { groups: Vec::new() } 50 50 } 51 51 }; 52 - let instance = Instance { 53 - file: reminders_file, 52 + 53 + let instance = Instance::init( 54 + reminders_file, 54 55 app_paths, 55 - scheduler: None, 56 - bundle_identifier: ctx.config().tauri.bundle.identifier.clone(), 57 - }; 56 + &ctx.config().tauri.bundle.identifier, 57 + ); 58 58 59 59 let app = tauri::Builder::default() 60 60 .invoke_handler(tauri::generate_handler![
+40 -16
src-tauri/src/notifications.rs
··· 8 8 use std::str::FromStr; 9 9 use std::sync::Mutex; 10 10 use tauri::api::dialog; 11 - use tauri::api::notification::Notification; 12 11 use tauri::{command, State}; 13 12 14 13 #[derive(Serialize, Deserialize)] ··· 25 24 Err(e) => throw!("Invalid schedule: {}", e), 26 25 } 27 26 } 27 + 28 + #[cfg(not(target_os = "macos"))] 29 + static mut APP_IDENTIFIER: Option<String> = Option::None; 28 30 29 31 #[derive(Serialize, Deserialize, Clone)] 30 32 pub struct Group { ··· 37 39 pub cron: String, 38 40 } 39 41 impl Group { 40 - pub fn create_job(&mut self, cron: cron::Schedule, scheduler: &mut Scheduler<Local>, a: String) { 42 + pub fn create_job(&mut self, cron: cron::Schedule, scheduler: &mut Scheduler<Local>) { 41 43 if self.enabled { 42 44 let job = Job::cron_schedule(cron); 43 45 let group = self.clone(); 44 46 let job_id = scheduler.insert(job, move |_id| { 45 - let result = Notification::new(&a) 46 - .title(&group.title) 47 - .body(&group.description) 48 - .show(); 47 + #[cfg(target_os = "macos")] 48 + let result = mac_notification_sys::send_notification( 49 + &group.title, 50 + None, 51 + &group.description, 52 + Some(mac_notification_sys::Notification::new().close_button("Done")), 53 + ); 54 + 55 + #[cfg(not(target_os = "macos"))] 56 + let result = unsafe { 57 + tauri::api::notification::Notification::new(APP_IDENTIFIER.as_ref().unwrap()) 58 + .title(&group.title) 59 + .body(&group.description) 60 + .show() 61 + }; 62 + 49 63 match result { 50 64 Ok(_) => println!("Show \"{}\"", group.title), 51 65 Err(e) => eprintln!("Could not show notification: {}", e), ··· 58 72 } 59 73 60 74 pub struct Instance { 61 - pub file: RemindersFile, 62 - pub scheduler: Option<Scheduler<Local>>, 63 - pub app_paths: AppPaths, 64 - pub bundle_identifier: String, 75 + file: RemindersFile, 76 + scheduler: Option<Scheduler<Local>>, 77 + app_paths: AppPaths, 65 78 } 66 79 impl Instance { 80 + pub fn init(file: RemindersFile, app_paths: AppPaths, app_identifier: &str) -> Self { 81 + #[cfg(target_os = "macos")] 82 + mac_notification_sys::set_application(&app_identifier).unwrap(); 83 + #[cfg(not(target_os = "macos"))] 84 + unsafe { 85 + APP_IDENTIFIER = Some(app_identifier.to_string()); 86 + } 87 + Self { 88 + file, 89 + scheduler: None, 90 + app_paths, 91 + } 92 + } 67 93 pub fn save(&self) -> Result<(), String> { 68 94 self.file.save(&self.app_paths) 69 95 } ··· 71 97 match &mut self.scheduler { 72 98 Some(scheduler) => { 73 99 let schedule = parse_cron(&group.cron)?; 74 - group.create_job(schedule, scheduler, self.bundle_identifier.clone()); 100 + group.create_job(schedule, scheduler); 75 101 self.file.groups.push(group); 76 102 } 77 103 None => { ··· 115 141 Some(scheduler) => scheduler, 116 142 None => return Ok(()), 117 143 }; 118 - new_group.create_job(schedule, scheduler, self.bundle_identifier.clone()); 144 + new_group.create_job(schedule, scheduler); 119 145 Ok(()) 120 146 } 121 147 pub fn update_job(&mut self, job_id: JobId, new_group: &mut Group) -> Result<(), String> { ··· 125 151 None => return Ok(()), 126 152 }; 127 153 scheduler.remove(job_id); 128 - new_group.create_job(schedule, scheduler, self.bundle_identifier.clone()); 154 + new_group.create_job(schedule, scheduler); 129 155 println!("Update job \"{}\" at {}", new_group.title, new_group.cron); 130 156 Ok(()) 131 157 } 132 158 pub fn start(&mut self) { 133 - let bundle_identifier = self.bundle_identifier.clone(); 134 - 135 159 let (mut scheduler, sched_service) = Scheduler::<Local>::launch(tokio::time::sleep); 136 160 137 161 let mut errors = Vec::new(); 138 162 for group in &mut self.file.groups { 139 163 match parse_cron(&group.cron) { 140 - Ok(schedule) => group.create_job(schedule, &mut scheduler, bundle_identifier.clone()), 164 + Ok(schedule) => group.create_job(schedule, &mut scheduler), 141 165 Err(e) => errors.push(e), 142 166 }; 143 167 }