- Added `AppItem` struct to represent application details. - Implemented `collect_lnk_one_level` function to gather .lnk files from specified directories. - Created `get_apps` command to retrieve applications from the Taskbar and Start Menu. - Developed `launch_app` command to open applications. - Introduced `get_app_icon` command to fetch application icons in base64 format. - Added functionality to manage pinned applications with `get_pinned_apps` and `set_pinned_apps` commands. - Implemented system tray with toggle window functionality. - Created UI components for displaying application icons and tiles. - Developed hooks for managing application state, drag-and-drop reordering, and search functionality. - Styled components for a cohesive user interface.
55 lines
1.6 KiB
Rust
55 lines
1.6 KiB
Rust
use tauri::{
|
|
menu::{Menu, MenuItem},
|
|
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
|
|
AppHandle, Manager,
|
|
};
|
|
|
|
pub fn toggle_window(app_handle: &AppHandle) {
|
|
if let Some(window) = app_handle.get_webview_window("main") {
|
|
let is_visible = window.is_visible().unwrap_or(false);
|
|
if is_visible {
|
|
let _ = window.hide();
|
|
} else {
|
|
let _ = window.show();
|
|
let _ = window.set_focus();
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn setup_tray(app: &tauri::App) -> Result<(), Box<dyn std::error::Error>> {
|
|
let show_i = MenuItem::with_id(app, "show", "Показати/Сховати", true, None::<&str>)?;
|
|
let quit_i = MenuItem::with_id(app, "quit", "Вийти", true, None::<&str>)?;
|
|
let menu = Menu::with_items(app, &[&show_i, &quit_i])?;
|
|
|
|
let default_icon = app
|
|
.default_window_icon()
|
|
.ok_or("default window icon missing")?
|
|
.clone();
|
|
|
|
TrayIconBuilder::new()
|
|
.icon(default_icon)
|
|
.menu(&menu)
|
|
.show_menu_on_left_click(false)
|
|
.on_tray_icon_event(|tray, event| match event {
|
|
TrayIconEvent::Click {
|
|
button: MouseButton::Left,
|
|
button_state: MouseButtonState::Up,
|
|
..
|
|
} => {
|
|
let app_handle = tray.app_handle();
|
|
toggle_window(app_handle);
|
|
}
|
|
_ => {}
|
|
})
|
|
.on_menu_event(|app_handle, event| match event.id.as_ref() {
|
|
"quit" => std::process::exit(0),
|
|
"show" => {
|
|
toggle_window(app_handle);
|
|
}
|
|
_ => {}
|
|
})
|
|
.build(app)?;
|
|
|
|
Ok(())
|
|
}
|