1
0
mirror of https://github.com/4yn/slidershim.git synced 2024-11-12 00:40:49 +01:00

system tray

This commit is contained in:
4yn 2022-01-27 21:13:34 +08:00
parent c1f03c045e
commit 08186c0fc1
4 changed files with 81 additions and 4 deletions

24
src-tauri/Cargo.lock generated
View File

@ -2866,6 +2866,7 @@ dependencies = [
"raw-window-handle 0.3.4",
"scopeguard",
"serde",
"tauri-libappindicator",
"unicode-segmentation",
"winapi",
"x11-dl",
@ -2964,6 +2965,29 @@ dependencies = [
"zstd",
]
[[package]]
name = "tauri-libappindicator"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af6057bf1b03141122da159ad4136d8a474240db59d81af1840d7fce3b819ef2"
dependencies = [
"glib",
"gtk",
"gtk-sys",
"log",
"tauri-libappindicator-sys",
]
[[package]]
name = "tauri-libappindicator-sys"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c40a817171cf25d69dd31e3fa9360fd4367e54948e30f3356962f0b1d9f23dad"
dependencies = [
"gtk-sys",
"pkg-config",
]
[[package]]
name = "tauri-macros"
version = "1.0.0-beta.5"

View File

@ -17,7 +17,7 @@ tauri-build = { version = "1.0.0-beta.4" }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0-beta.8", features = ["api-all"] }
tauri = { version = "1.0.0-beta.8", features = ["api-all", "system-tray"] }
[features]
default = [ "custom-protocol" ]

View File

@ -3,8 +3,57 @@
windows_subsystem = "windows"
)]
use tauri::{
CustomMenuItem, Event, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu,
};
fn main() {
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("error while running tauri application");
.system_tray(
SystemTray::new().with_menu(
SystemTrayMenu::new()
.add_item(CustomMenuItem::new("slidershim".to_string(), "slidershim").disabled())
.add_item(CustomMenuItem::new("show".to_string(), "Show"))
.add_item(CustomMenuItem::new("quit".to_string(), "Quit")),
),
)
.on_system_tray_event(|app, event| match event {
SystemTrayEvent::LeftClick {
position: _,
size: _,
..
} => {
app
.get_window("main")
.unwrap()
.show().ok();
}
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
"show" => {
app
.get_window("main")
.unwrap()
.show().ok();
}
"quit" => {
std::process::exit(0);
}
_ => {
panic!("Unexpected menu item click {}", id.as_str());
}
},
_ => {}
})
.build(tauri::generate_context!())
.expect("error while running tauri application")
.run(|app_handle, event| match event {
Event::CloseRequested { label, api, .. } if label.as_str() == "main" => {
api.prevent_close();
app_handle
.get_window("main")
.unwrap()
.hide().ok();
}
_ => {}
});
}

View File

@ -56,12 +56,16 @@
"title": "slidershim",
"width": 800,
"height": 600,
"resizable": true,
"resizable": false,
"fullscreen": false
}
],
"security": {
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'"
},
"systemTray": {
"iconPath": "icons/icon.png",
"iconAsTemplate": true
}
}
}