44bed99bb4
- 实现浅灰色玻璃拟态悬浮球,带机器人头图标 - 支持点击展开对话框,淡入淡出动画 - 支持窗口拖拽,区分点击和拖拽操作 - macOS 透明窗口支持 (macOSPrivateApi) - 悬浮球 hover 放大效果,不溢出窗口 - 添加系统托盘 Toggle Quick Ask 菜单
84 lines
2.8 KiB
Rust
84 lines
2.8 KiB
Rust
use tauri::{
|
|
menu::{Menu, MenuItem},
|
|
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
|
|
Manager, Runtime,
|
|
};
|
|
|
|
mod commands;
|
|
|
|
pub fn run() {
|
|
tauri::Builder::default()
|
|
.plugin(tauri_plugin_shell::init())
|
|
.plugin(tauri_plugin_fs::init())
|
|
.plugin(tauri_plugin_dialog::init())
|
|
.plugin(tauri_plugin_http::init())
|
|
.setup(|app| {
|
|
setup_tray(app)?;
|
|
Ok(())
|
|
})
|
|
.invoke_handler(tauri::generate_handler![
|
|
commands::get_app_info,
|
|
commands::open_directory_dialog,
|
|
commands::read_local_file,
|
|
commands::list_directory,
|
|
commands::toggle_floating_window,
|
|
commands::show_floating_window,
|
|
commands::hide_floating_window,
|
|
commands::show_main_window,
|
|
commands::set_floating_window_size,
|
|
])
|
|
.run(tauri::generate_context!())
|
|
.expect("error while running tauri application");
|
|
}
|
|
|
|
fn setup_tray<R: Runtime>(app: &tauri::App<R>) -> Result<(), Box<dyn std::error::Error>> {
|
|
let show_item = MenuItem::with_id(app, "show", "Show Main Window", true, None::<&str>)?;
|
|
let floating_item = MenuItem::with_id(app, "floating", "Toggle Quick Ask", true, None::<&str>)?;
|
|
let quit_item = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
|
|
|
|
let menu = Menu::with_items(app, &[&show_item, &floating_item, &quit_item])?;
|
|
|
|
let _tray = TrayIconBuilder::new()
|
|
.menu(&menu)
|
|
.show_menu_on_left_click(false)
|
|
.on_menu_event(|app, event| match event.id.as_ref() {
|
|
"show" => {
|
|
if let Some(window) = app.get_webview_window("main") {
|
|
let _ = window.show();
|
|
let _ = window.set_focus();
|
|
}
|
|
}
|
|
"floating" => {
|
|
if let Some(window) = app.get_webview_window("floating") {
|
|
if window.is_visible().unwrap_or(false) {
|
|
let _ = window.hide();
|
|
} else {
|
|
let _ = window.show();
|
|
let _ = window.set_focus();
|
|
}
|
|
}
|
|
}
|
|
"quit" => {
|
|
app.exit(0);
|
|
}
|
|
_ => {}
|
|
})
|
|
.on_tray_icon_event(|tray, event| {
|
|
if let TrayIconEvent::Click {
|
|
button: MouseButton::Left,
|
|
button_state: MouseButtonState::Up,
|
|
..
|
|
} = event
|
|
{
|
|
let app = tray.app_handle();
|
|
if let Some(window) = app.get_webview_window("main") {
|
|
let _ = window.show();
|
|
let _ = window.set_focus();
|
|
}
|
|
}
|
|
})
|
|
.build(app)?;
|
|
|
|
Ok(())
|
|
}
|