[feat] start hidden + hidden on close + basic tray function
This commit is contained in:
@@ -4,12 +4,14 @@
|
||||
)]
|
||||
|
||||
use tauri::Manager;
|
||||
use tauri_plugin_deep_link::DeepLinkExt;
|
||||
use tauri_plugin_autostart::MacosLauncher;
|
||||
use tauri_plugin_cli::CliExt;
|
||||
use tauri_plugin_deep_link::DeepLinkExt;
|
||||
use tauri_plugin_store::StoreExt;
|
||||
|
||||
// Window Vibrancy
|
||||
#[cfg(target_os = "windows")]
|
||||
use window_vibrancy::apply_mica;
|
||||
use window_vibrancy::apply_acrylic;
|
||||
#[cfg(target_os = "macos")]
|
||||
use window_vibrancy::{apply_vibrancy, NSVisualEffectMaterial};
|
||||
|
||||
@@ -50,7 +52,10 @@ fn main() {
|
||||
.plugin(tauri_plugin_store::Builder::new().build())
|
||||
.plugin(tauri_plugin_theme::init(ctx.config_mut()))
|
||||
.plugin(tauri_plugin_notification::init())
|
||||
.plugin(tauri_plugin_autostart::init(MacosLauncher::LaunchAgent, Some(vec![]) /* arbitrary number of args to pass to your app */))
|
||||
.plugin(tauri_plugin_autostart::init(
|
||||
MacosLauncher::LaunchAgent,
|
||||
Some(vec!["hidden"]), /* arbitrary number of args to pass to your app */
|
||||
))
|
||||
.plugin(tauri_plugin_http::init())
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
|
||||
@@ -60,9 +65,29 @@ fn main() {
|
||||
.plugin(tauri_plugin_process::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_system_info::init())
|
||||
.plugin(tauri_plugin_cli::init())
|
||||
// .plugin(tauri_plugin_store::Builder::default().build())
|
||||
// .plugin(tauri_plugin_updater::Builder::new().build())
|
||||
.setup(|app| {
|
||||
// Get Window
|
||||
let window = app.get_webview_window("main").unwrap();
|
||||
|
||||
let store = app.store("cstb.json")?;
|
||||
// 获取boolean类型的hidden值,Err时设置为False
|
||||
let hidden: bool = store.get("hidden").and_then(|v| v.as_bool()).unwrap_or(false);
|
||||
|
||||
// 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_acrylic(&window, None)
|
||||
.expect("Unsupported platform! 'apply_acrylic' is only supported on Windows");
|
||||
|
||||
// apply_blur(&window, Some((18, 18, 18, 0)))
|
||||
// .expect("Unsupported platform! 'apply_blur' is only supported on Windows");
|
||||
|
||||
// Deep Link
|
||||
#[cfg(desktop)]
|
||||
app.deep_link().register("cstb")?;
|
||||
@@ -74,20 +99,22 @@ fn main() {
|
||||
tray::create_tray(handle)?;
|
||||
}
|
||||
|
||||
// Get Window
|
||||
let window = app.get_webview_window("main").unwrap();
|
||||
// CLI
|
||||
match app.cli().matches() {
|
||||
// `matches` here is a Struct with { args, subcommand }.
|
||||
// `args` is `HashMap<String, ArgData>` where `ArgData` is a struct with { value, occurrences }.
|
||||
// `subcommand` is `Option<Box<SubcommandMatches>>` where `SubcommandMatches` is a struct with { name, matches }.
|
||||
Ok(matches) => {
|
||||
println!("{:?}", matches);
|
||||
if matches.args.contains_key("hidden") && matches.args["hidden"].value == true && hidden {
|
||||
window.hide().unwrap();
|
||||
} else {
|
||||
window.show().unwrap();
|
||||
}
|
||||
}
|
||||
Err(_) => {}
|
||||
}
|
||||
|
||||
// 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![
|
||||
@@ -100,7 +127,7 @@ fn main() {
|
||||
cmds::open_path,
|
||||
cmds::get_powerplan,
|
||||
cmds::set_powerplan,
|
||||
cmds::get_steam_users,
|
||||
cmds::get_steam_users,
|
||||
cmds::set_auto_login_user,
|
||||
cmds::check_path,
|
||||
on_button_clicked
|
||||
|
||||
Reference in New Issue
Block a user