Implement toast notification on macOS and Linux
This commit is contained in:
		
							
								
								
									
										36
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								src/lib.rs
									
									
									
									
									
								
							@@ -137,6 +137,8 @@ pub mod pomodoro {
 | 
			
		||||
                self.next();
 | 
			
		||||
                self.alert.play();
 | 
			
		||||
 | 
			
		||||
                Self::notify(&self.state);
 | 
			
		||||
 | 
			
		||||
                match self.state {
 | 
			
		||||
                    State::Work => {
 | 
			
		||||
                        Self::send_to_clock(&tx, self.state, config.work_time);
 | 
			
		||||
@@ -167,6 +169,40 @@ pub mod pomodoro {
 | 
			
		||||
 | 
			
		||||
            tx.send(status).unwrap();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #[cfg(any(target_os = "macos", target_os = "linux"))]
 | 
			
		||||
        fn notify(state: &State) {
 | 
			
		||||
            let mut toast = notify_rust::Notification::new();
 | 
			
		||||
 | 
			
		||||
            match state {
 | 
			
		||||
                State::Work => {
 | 
			
		||||
                    toast
 | 
			
		||||
                        .summary("Time to Work!")
 | 
			
		||||
                        .body("Remember to stay focused!")
 | 
			
		||||
                        .show()
 | 
			
		||||
                        .unwrap();
 | 
			
		||||
                }
 | 
			
		||||
                State::ShortBreak | State::LongBreak => {
 | 
			
		||||
                    toast
 | 
			
		||||
                        .summary("Break Time!")
 | 
			
		||||
                        .body("Enjoy your well deserved rest!")
 | 
			
		||||
                        .show()
 | 
			
		||||
                        .unwrap();
 | 
			
		||||
                }
 | 
			
		||||
                State::Inactive => {
 | 
			
		||||
                    toast
 | 
			
		||||
                        .summary("Pomodoro Cycle Complete.")
 | 
			
		||||
                        .body("Now waiting for user input....")
 | 
			
		||||
                        .show()
 | 
			
		||||
                        .unwrap();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #[cfg(target_os = "windows")]
 | 
			
		||||
        fn notify(state: &State) {
 | 
			
		||||
            unimplemented!();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[derive(Copy, Clone, Debug)]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user