Skip to content
This repository was archived by the owner on May 27, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

---

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "discord-tauri",
"scripts": {
"tauri": "tauri"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making this, I have one question tough, won't removing "tauri" from the scripts make "yarn tauri" or "npm run tauri" not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned yarn serve and npm run server in my comment. Would you like me to replace serve with tauri?

"serve": "cargo tauri dev"
},
"devDependencies": {
"@tauri-apps/cli": "^1.2.2"
Expand Down
Binary file modified src-tauri/icons/icon.icns
Binary file not shown.
62 changes: 62 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}