diff --git a/README.md b/README.md index 4450d69..c5c694e 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ The following results were obtained with an almost brand new account: 3 servers, - [ ] File Dropping - [ ] Push To Talk - [ ] Custom Settings -- [x] Works on Linux +- [x] Works on Linux & MacOS --- diff --git a/package.json b/package.json index 641154c..16a88f8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "discord-tauri", "scripts": { - "tauri": "tauri" + "serve": "cargo tauri dev" }, "devDependencies": { "@tauri-apps/cli": "^1.2.2" diff --git a/src-tauri/icons/icon.icns b/src-tauri/icons/icon.icns index 06330ad..51f71c0 100644 Binary files a/src-tauri/icons/icon.icns and b/src-tauri/icons/icon.icns differ diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index b6fa160..f1f490a 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -135,3 +135,65 @@ fn main() { .run(tauri::generate_context!()) .expect("Error running discord-tauri"); } + +#[cfg(target_os = "macos")] +fn main() { + // We can't make a separate file for a Desktop Tray yet, so we make it here + // Create an item of the context menu called `quit` with the string `Quit Discord` + let quit_item = CustomMenuItem::new("quit".to_string(), "Quit Discord"); + // Create a new context menu with the item above + let context_menu = SystemTrayMenu::new().add_item(quit_item); + // Create a new system tray with the context menu above + let desktop_tray = SystemTray::new().with_menu(context_menu); + + // Start Tauri + tauri::Builder::default() + // Register the commands + .invoke_handler(tauri::generate_handler![]) + // Show the main window + .setup(|app| { + let window = app.get_window(&"main").unwrap(); + window.show().unwrap(); + Ok(()) + }) + // Register the desktop tray + .system_tray(desktop_tray) + // Add events for the desktop tray + .on_system_tray_event(|app, event| match event { + // If the event is a left click into the icon, + // verify that the window is closed and re-open it + // while setting it up again (Tauri doesn't save + // the status of hidden windows). + SystemTrayEvent::LeftClick { + position: _, + size: _, + .. + } => { + let window = app.get_window("main").unwrap(); + // If the window is closed + if !window.is_visible().unwrap() { + // Re-open the window + window.show().unwrap(); + } + // Even if the window isn't closed, it could be minimized in the taskbar; set it as focused + else { + window.set_focus().unwrap(); + } + } + // If the event is a click to an item + SystemTrayEvent::MenuItemClick { id, .. } => { + // We compare the name of the item to... + match id.as_str() { + // `quit` is the item with the string `Quit Discord` + // If the user clicks quit, close discord-tauri + "quit" => { + std::process::exit(0); + } + _ => {} + } + } + _ => {} + }) + .run(tauri::generate_context!()) + .expect("Error running discord-tauri"); +} \ No newline at end of file