Skip to content

Commit

Permalink
feat(ui): tray allow to open app
Browse files Browse the repository at this point in the history
Signed-off-by: Martichou <m@rtin.fyi>
  • Loading branch information
Martichou committed Feb 27, 2024
1 parent 072ac8d commit 748cbbb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
30 changes: 26 additions & 4 deletions frontend/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ extern crate log;

use rquickshare::channel::{ChannelDirection, ChannelMessage};
use rquickshare::RQS;
use tauri::{CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu};
use tauri::{
CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem,
};
use tokio::sync::broadcast::Sender;

pub struct AppState {
Expand Down Expand Up @@ -38,8 +40,12 @@ async fn main() -> Result<(), anyhow::Error> {
let (sender, mut receiver) = rqs.channel;

// Configure System Tray
let show = CustomMenuItem::new("show".to_string(), "Show");
let quit = CustomMenuItem::new("quit".to_string(), "Quit");
let tray_menu = SystemTrayMenu::new().add_item(quit);
let tray_menu = SystemTrayMenu::new()
.add_item(show)
.add_native_item(SystemTrayMenuItem::Separator)
.add_item(quit);
let tray = SystemTray::new().with_menu(tray_menu);

// Build and run Tauri app
Expand All @@ -65,11 +71,27 @@ async fn main() -> Result<(), anyhow::Error> {
.system_tray(tray)
.on_system_tray_event(|_app, event| {
if let SystemTrayEvent::MenuItemClick { id, .. } = event {
if id.as_str() == "quit" {
std::process::exit(0);
match id.as_str() {
"show" => {
let widow = _app.get_window("main").unwrap();
let _ = widow.show();
let _ = widow.set_focus();
}
"quit" => {
// TODO - Clean exit
std::process::exit(0);
}
_ => {}
}
}
})
.on_window_event(|event| match event.event() {
tauri::WindowEvent::CloseRequested { api, .. } => {
event.window().hide().unwrap();
api.prevent_close();
}
_ => {}
})
.build(tauri::generate_context!())
.expect("error while building tauri application")
.run(|_app_handle, event| {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ window.addEventListener('blur', () => {
</script>

<template>
<div class="flex flex-col bg-green-50 bg-opacity-75 w-full h-full max-w-full max-h-full">
<div class="flex flex-col bg-green-50 w-full h-full max-w-full max-h-full">
<div class="flex flex-row justify-between items-center px-6 py-4">
<!-- Header, Pc name left and options right -->
<div>
Expand Down

0 comments on commit 748cbbb

Please # to comment.