2024-09-20 02:28:25 +08:00
|
|
|
#![cfg_attr(
|
|
|
|
|
all(not(debug_assertions), target_os = "windows"),
|
|
|
|
|
windows_subsystem = "windows"
|
|
|
|
|
)]
|
2024-09-20 09:52:13 +08:00
|
|
|
use tauri::Manager;
|
2024-09-20 02:28:25 +08:00
|
|
|
|
2024-09-20 09:52:13 +08:00
|
|
|
// Window Vibrancy
|
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
|
use window_vibrancy::apply_mica;
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
use window_vibrancy::{apply_vibrancy, NSVisualEffectMaterial};
|
|
|
|
|
|
|
|
|
|
// System Tray
|
|
|
|
|
use tauri::{
|
|
|
|
|
menu::{MenuBuilder, MenuItemBuilder},
|
|
|
|
|
tray::{ClickType, TrayIconBuilder},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Auto Start
|
|
|
|
|
use tauri_plugin_autostart::MacosLauncher;
|
|
|
|
|
|
|
|
|
|
// use tauri_plugin_autostart::ManagerExt;
|
2024-09-20 02:28:25 +08:00
|
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
|
|
|
|
|
2024-09-20 09:52:13 +08:00
|
|
|
// Local Modules
|
|
|
|
|
mod cmds;
|
|
|
|
|
mod steam;
|
|
|
|
|
mod tool;
|
|
|
|
|
|
2024-09-20 02:28:25 +08:00
|
|
|
#[tauri::command]
|
|
|
|
|
fn on_button_clicked() -> String {
|
|
|
|
|
let start = SystemTime::now();
|
|
|
|
|
let since_the_epoch = start
|
|
|
|
|
.duration_since(UNIX_EPOCH)
|
|
|
|
|
.expect("Time went backwards")
|
|
|
|
|
.as_millis();
|
|
|
|
|
format!("on_button_clicked called from Rust! (timestamp: {since_the_epoch}ms)")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
tauri::Builder::default()
|
2024-09-20 09:52:13 +08:00
|
|
|
.plugin(tauri_plugin_fs::init())
|
|
|
|
|
.plugin(tauri_plugin_os::init())
|
|
|
|
|
.plugin(tauri_plugin_autostart::init(
|
|
|
|
|
MacosLauncher::LaunchAgent,
|
|
|
|
|
Some(vec![]),
|
|
|
|
|
))
|
|
|
|
|
.plugin(tauri_plugin_process::init())
|
|
|
|
|
.plugin(tauri_plugin_dialog::init())
|
|
|
|
|
.plugin(tauri_plugin_store::Builder::default().build())
|
|
|
|
|
// .plugin(tauri_plugin_updater::Builder::new().build())
|
|
|
|
|
.invoke_handler(tauri::generate_handler![on_button_clicked])
|
|
|
|
|
.setup(|app| {
|
|
|
|
|
// Tray Menu
|
|
|
|
|
// let quit = CustomMenuItem::new("quit".to_string(), "Quit");
|
|
|
|
|
// let hide = CustomMenuItem::new("hide".to_string(), "Hide");
|
|
|
|
|
// let tray_menu = SystemTrayMenu::new() // insert the menu items here
|
|
|
|
|
// .add_item(hide)
|
|
|
|
|
// .add_item(quit);
|
|
|
|
|
// .add_native_item(SystemTrayMenuItem::Separator)
|
|
|
|
|
let toggle = MenuItemBuilder::with_id("toggle", "Toggle").build(app)?;
|
|
|
|
|
let menu = MenuBuilder::new(app).items(&[&toggle]).build()?;
|
|
|
|
|
|
|
|
|
|
// Setup Tray
|
|
|
|
|
// let tray = tauri::tray::TrayIconBuilder::with_id("my-tray").build(app)?;
|
|
|
|
|
let _ = TrayIconBuilder::new()
|
|
|
|
|
.menu(&menu)
|
|
|
|
|
.on_menu_event(move |_, event| {
|
|
|
|
|
match event.id().as_ref() {
|
|
|
|
|
"toggle" => {
|
|
|
|
|
println!("toggle clicked");
|
|
|
|
|
}
|
|
|
|
|
_ => (),
|
|
|
|
|
}
|
|
|
|
|
// match event {
|
|
|
|
|
// SystemTrayEvent::LeftClick { position: _, size: _, .. } => {
|
|
|
|
|
// let window = app.get_window("main").unwrap();
|
|
|
|
|
// window.show().unwrap();
|
|
|
|
|
// window.set_focus().unwrap();
|
|
|
|
|
|
|
|
|
|
// // thread::sleep(Duration::from_millis(100));
|
|
|
|
|
// // window.set_always_on_top(false).unwrap();
|
|
|
|
|
// println!("system tray received a left click");
|
|
|
|
|
// }
|
|
|
|
|
// SystemTrayEvent::RightClick { position: _, size: _, .. } => {
|
|
|
|
|
// // let window = app.get_window("main").unwrap();
|
|
|
|
|
// // window.hide().unwrap();
|
|
|
|
|
// println!("system tray received a right click");
|
|
|
|
|
// }
|
|
|
|
|
// SystemTrayEvent::DoubleClick { position: _, size: _, .. } => {
|
|
|
|
|
// println!("system tray received a double click");
|
|
|
|
|
// }
|
|
|
|
|
// SystemTrayEvent::MenuItemClick { id, .. } =>
|
|
|
|
|
// match id.as_str() {
|
|
|
|
|
// "quit" => {
|
|
|
|
|
// std::process::exit(0);
|
|
|
|
|
// }
|
|
|
|
|
// "hide" => {
|
|
|
|
|
// let window = app.get_window("main").unwrap();
|
|
|
|
|
// window.hide().unwrap();
|
|
|
|
|
// }
|
|
|
|
|
// _ => {}
|
|
|
|
|
// }
|
|
|
|
|
// _ => {}
|
|
|
|
|
// }
|
|
|
|
|
})
|
|
|
|
|
.on_tray_icon_event(|tray, event| {
|
|
|
|
|
if event.click_type == ClickType::Left {
|
|
|
|
|
let app = tray.app_handle();
|
|
|
|
|
if let Some(webview_window) = app.get_webview_window("main") {
|
|
|
|
|
let _ = webview_window.show();
|
|
|
|
|
let _ = webview_window.set_focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.build(app)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
// Get Window
|
|
|
|
|
let window = app.get_webview_window("main").unwrap();
|
|
|
|
|
|
|
|
|
|
// Vibrant Window
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
|
apply_vibrancy(&window, NSVisualEffectMaterial::HudWindow, None, Some(10.0))
|
|
|
|
|
.expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
|
apply_mica(&window, Some(false))
|
|
|
|
|
.expect("Unsupported platform! 'apply_mica' is only supported on Windows");
|
|
|
|
|
|
|
|
|
|
// apply_blur(&window, Some((18, 18, 18, 0)))
|
|
|
|
|
// .expect("Unsupported platform! 'apply_blur' is only supported on Windows");
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
})
|
|
|
|
|
.invoke_handler(tauri::generate_handler![
|
|
|
|
|
cmds::greet,
|
|
|
|
|
cmds::launch_game,
|
|
|
|
|
cmds::kill_game,
|
|
|
|
|
cmds::kill_steam,
|
|
|
|
|
cmds::get_steam_path,
|
|
|
|
|
cmds::set_auto_login_user,
|
|
|
|
|
cmds::check_file_exists
|
|
|
|
|
])
|
|
|
|
|
.run(tauri::generate_context!())
|
|
|
|
|
.expect("error while running tauri application");
|
2024-09-20 02:28:25 +08:00
|
|
|
}
|