pomodoro_timer/
pomodoro_timer.rs1use std::{thread, time};
2use win_hotkeys::HotkeyManager;
3use win_hotkeys::VKey;
4use windows::core::PCWSTR;
5use windows::Win32::Foundation::HWND;
6use windows::Win32::UI::WindowsAndMessaging::{MessageBoxW, MB_OK};
7
8fn main() {
9 let mut hkm = HotkeyManager::new();
10
11 hkm.register_hotkey(VKey::P, &[VKey::Control], || {
12 show_popup("Pomodoro Timer", "Pomodoro started! Focus for 25 minutes.");
13 thread::spawn(|| {
14 thread::sleep(time::Duration::from_secs(25 * 60));
15 show_popup("Pomodoro Timer", "Time's up! Take a break.");
16 });
17 })
18 .unwrap();
19
20 hkm.register_hotkey(VKey::S, &[VKey::Control], || {
21 show_popup("Pomodoro Timer", "Pomodoro stopped!");
22 })
23 .unwrap();
24
25 hkm.event_loop();
26}
27
28fn show_popup(title: &str, message: &str) {
29 unsafe {
30 MessageBoxW(
31 Some(HWND(std::ptr::null_mut())),
32 PCWSTR(to_wide_string(message).as_ptr()),
33 PCWSTR(to_wide_string(title).as_ptr()),
34 MB_OK,
35 );
36 }
37}
38
39fn to_wide_string(value: &str) -> Vec<u16> {
40 value.encode_utf16().chain(std::iter::once(0)).collect()
41}