Skip to content

Commit

Permalink
Merge pull request #21 from davidchalifoux/main
Browse files Browse the repository at this point in the history
Add "Show" menu item to fix Linux support
  • Loading branch information
davidchalifoux authored Apr 20, 2024
2 parents 70fb6fc + 942b61e commit 10c8301
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use mdns_sd::{ServiceDaemon, ServiceEvent};
use tauri::{CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu};
use tauri::{
CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem,
};
use tauri_plugin_positioner::{Position, WindowExt};

#[derive(Clone, Debug, serde::Serialize)]
Expand Down Expand Up @@ -65,9 +67,14 @@ async fn scan() -> Vec<ElgatoService> {
}

fn main() {
let quit = CustomMenuItem::new("quit".to_string(), "Quit");
let quit_button = CustomMenuItem::new("quit".to_string(), "Quit");
let show_hide_button = CustomMenuItem::new("show".to_string(), "Show");

let tray_menu = SystemTrayMenu::new()
.add_item(show_hide_button)
.add_native_item(SystemTrayMenuItem::Separator)
.add_item(quit_button);

let tray_menu = SystemTrayMenu::new().add_item(quit);
let system_tray = SystemTray::new().with_menu(tray_menu);

tauri::Builder::default()
Expand All @@ -91,7 +98,6 @@ fn main() {
tauri::WindowEvent::Focused(focused) => {
// hide window whenever it loses focus
if !focused {
println!("Lost focus, hiding");
event.window().hide().unwrap();
}
}
Expand All @@ -103,23 +109,28 @@ fn main() {
match event {
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
"quit" => app.exit(0),
"show" => {
let window = app.get_window("main").unwrap();

let _ = window.move_window(Position::TrayCenter);

window.show().unwrap();
window.set_focus().unwrap();
}
_ => {}
},

SystemTrayEvent::LeftClick { .. } => {
println!("Left click on icon");
let window = app.get_window("main").unwrap();

let _ = window.move_window(Position::TrayCenter);

let is_visible = window.is_visible().unwrap_or_default();

if !is_visible {
println!("Showing");

window.show().unwrap();
window.set_focus().unwrap();
} else {
println!("Hiding");
window.hide().unwrap();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "Keylight Commander",
"version": "0.0.10"
"version": "0.0.11"
},
"tauri": {
"macOSPrivateApi": true,
Expand Down

0 comments on commit 10c8301

Please sign in to comment.