feat: add system tray and packaging config
This commit is contained in:
1 parent
5494b633ea
commit
8957a1b90c
3 files changed
+47
No files matched your search
@@ -5,6 +5,7 @@ pub mod injection;
|
||||
pub mod models;
|
||||
pub mod settings;
|
||||
pub mod transcription;
|
||||
pub mod tray;
|
||||
pub mod ui_commands;
|
||||
|
||||
use app_state::ManagedAppState;
|
||||
@@ -13,6 +14,10 @@ use app_state::ManagedAppState;
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.setup(|app| {
|
||||
tray::setup(app)?;
|
||||
Ok(())
|
||||
})
|
||||
.manage(ManagedAppState::default())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
ui_commands::get_app_snapshot,
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
use tauri::menu::{Menu, MenuItem};
|
||||
use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
|
||||
use tauri::{App, Manager};
|
||||
|
||||
pub fn setup(app: &mut App) -> tauri::Result<()> {
|
||||
let show = MenuItem::with_id(app, "show", "Mostrar app", true, None::<&str>)?;
|
||||
let record = MenuItem::with_id(app, "record", "Iniciar gravação", true, None::<&str>)?;
|
||||
let quit = MenuItem::with_id(app, "quit", "Sair", true, None::<&str>)?;
|
||||
let menu = Menu::with_items(app, &[&show, &record, &quit])?;
|
||||
|
||||
TrayIconBuilder::new()
|
||||
.tooltip("Transcript")
|
||||
.menu(&menu)
|
||||
.show_menu_on_left_click(true)
|
||||
.on_menu_event(|app, event| match event.id().as_ref() {
|
||||
"show" | "record" => show_main_window(app),
|
||||
"quit" => app.exit(0),
|
||||
_ => {}
|
||||
})
|
||||
.on_tray_icon_event(|tray, event| {
|
||||
if let TrayIconEvent::Click {
|
||||
button: MouseButton::Left,
|
||||
button_state: MouseButtonState::Up,
|
||||
..
|
||||
} = event
|
||||
{
|
||||
show_main_window(tray.app_handle());
|
||||
}
|
||||
})
|
||||
.build(app)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn show_main_window(app: &tauri::AppHandle) {
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
let _ = window.unminimize();
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"icon": ["icons/icon.ico"],
|
||||
"externalBin": []
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user