migrate: v2 basically working

This commit is contained in:
Purp1e
2024-09-20 10:14:36 +08:00
parent 7229e79cd4
commit b12c6279d5
18 changed files with 16950 additions and 1259 deletions

2459
src-tauri/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -12,12 +12,23 @@ rust-version = "1.66"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "1.5", features = [] }
tauri-build = { version = "2.0.0-rc", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.8", features = ["api-all"] }
tauri = { version = "2.0.0-rc", features = [
"tray-icon"
] }
window-vibrancy = "0.5.2"
tauri-plugin-process = "2.0.0-rc"
tauri-plugin-fs = "2.0.0-rc"
tauri-plugin-dialog = "2.0.0-rc"
tauri-plugin-os = "2.0.0-rc"
tauri-plugin-clipboard-manager = "2.0.0-alpha.2"
tauri-plugin-shell = "2.0.0-rc"
tauri-plugin-http = "2.0.0-rc"
tauri-plugin-notification = "2.0.0-rc"
[features]
# by default Tauri runs in production mode
@@ -26,3 +37,6 @@ default = [ "custom-protocol" ]
# this feature is used used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ]
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-global-shortcut = "2.0.0-rc"

View File

@@ -0,0 +1,5 @@
{
"identifier": "desktop-capability",
"platforms": ["macOS", "windows", "linux"],
"permissions": ["global-shortcut:default"]
}

View File

@@ -0,0 +1,84 @@
{
"identifier": "migrated",
"description": "permissions that were migrated from v1",
"local": true,
"windows": ["main"],
"permissions": [
"core:default",
"fs:allow-read-file",
"fs:allow-write-file",
"fs:allow-read-dir",
"fs:allow-copy-file",
"fs:allow-mkdir",
"fs:allow-remove",
"fs:allow-remove",
"fs:allow-rename",
"fs:allow-exists",
"core:window:allow-create",
"core:window:allow-center",
"core:window:allow-request-user-attention",
"core:window:allow-set-resizable",
"core:window:allow-set-maximizable",
"core:window:allow-set-minimizable",
"core:window:allow-set-closable",
"core:window:allow-set-title",
"core:window:allow-maximize",
"core:window:allow-unmaximize",
"core:window:allow-minimize",
"core:window:allow-unminimize",
"core:window:allow-show",
"core:window:allow-hide",
"core:window:allow-close",
"core:window:allow-set-decorations",
"core:window:allow-set-always-on-top",
"core:window:allow-set-content-protected",
"core:window:allow-set-size",
"core:window:allow-set-min-size",
"core:window:allow-set-max-size",
"core:window:allow-set-position",
"core:window:allow-set-fullscreen",
"core:window:allow-set-focus",
"core:window:allow-set-icon",
"core:window:allow-set-skip-taskbar",
"core:window:allow-set-cursor-grab",
"core:window:allow-set-cursor-visible",
"core:window:allow-set-cursor-icon",
"core:window:allow-set-cursor-position",
"core:window:allow-set-ignore-cursor-events",
"core:window:allow-start-dragging",
"core:webview:allow-print",
"shell:allow-execute",
"shell:allow-open",
"dialog:allow-open",
"dialog:allow-save",
"dialog:allow-message",
"dialog:allow-ask",
"dialog:allow-confirm",
"http:default",
"notification:default",
"global-shortcut:allow-is-registered",
"global-shortcut:allow-register",
"global-shortcut:allow-register-all",
"global-shortcut:allow-unregister",
"global-shortcut:allow-unregister-all",
"os:allow-platform",
"os:allow-version",
"os:allow-os-type",
"os:allow-family",
"os:allow-arch",
"os:allow-exe-extension",
"os:allow-locale",
"os:allow-hostname",
"process:allow-restart",
"process:allow-exit",
"clipboard-manager:allow-read-text",
"clipboard-manager:allow-write-text",
"core:app:allow-app-show",
"core:app:allow-app-hide",
"process:default",
"fs:default",
"dialog:default",
"os:default",
"clipboard-manager:default"
]
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,93 @@
{
"desktop-capability": {
"identifier": "desktop-capability",
"description": "",
"local": true,
"permissions": ["global-shortcut:default"],
"platforms": ["macOS", "windows", "linux"]
},
"migrated": {
"identifier": "migrated",
"description": "permissions that were migrated from v1",
"local": true,
"windows": ["main"],
"permissions": [
"core:default",
"fs:allow-read-file",
"fs:allow-write-file",
"fs:allow-read-dir",
"fs:allow-copy-file",
"fs:allow-mkdir",
"fs:allow-remove",
"fs:allow-remove",
"fs:allow-rename",
"fs:allow-exists",
"core:window:allow-create",
"core:window:allow-center",
"core:window:allow-request-user-attention",
"core:window:allow-set-resizable",
"core:window:allow-set-maximizable",
"core:window:allow-set-minimizable",
"core:window:allow-set-closable",
"core:window:allow-set-title",
"core:window:allow-maximize",
"core:window:allow-unmaximize",
"core:window:allow-minimize",
"core:window:allow-unminimize",
"core:window:allow-show",
"core:window:allow-hide",
"core:window:allow-close",
"core:window:allow-set-decorations",
"core:window:allow-set-always-on-top",
"core:window:allow-set-content-protected",
"core:window:allow-set-size",
"core:window:allow-set-min-size",
"core:window:allow-set-max-size",
"core:window:allow-set-position",
"core:window:allow-set-fullscreen",
"core:window:allow-set-focus",
"core:window:allow-set-icon",
"core:window:allow-set-skip-taskbar",
"core:window:allow-set-cursor-grab",
"core:window:allow-set-cursor-visible",
"core:window:allow-set-cursor-icon",
"core:window:allow-set-cursor-position",
"core:window:allow-set-ignore-cursor-events",
"core:window:allow-start-dragging",
"core:webview:allow-print",
"shell:allow-execute",
"shell:allow-open",
"dialog:allow-open",
"dialog:allow-save",
"dialog:allow-message",
"dialog:allow-ask",
"dialog:allow-confirm",
"http:default",
"notification:default",
"global-shortcut:allow-is-registered",
"global-shortcut:allow-register",
"global-shortcut:allow-register-all",
"global-shortcut:allow-unregister",
"global-shortcut:allow-unregister-all",
"os:allow-platform",
"os:allow-version",
"os:allow-os-type",
"os:allow-family",
"os:allow-arch",
"os:allow-exe-extension",
"os:allow-locale",
"os:allow-hostname",
"process:allow-restart",
"process:allow-exit",
"clipboard-manager:allow-read-text",
"clipboard-manager:allow-write-text",
"core:app:allow-app-show",
"core:app:allow-app-hide",
"process:default",
"fs:default",
"dialog:default",
"os:default",
"clipboard-manager:default"
]
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -53,5 +53,5 @@ pub fn set_auto_login_user(user: &str) -> String {
#[tauri::command]
pub fn check_file_exists(file: &str) -> bool {
std::path::Path::new(&file).exists()
std::path::Path::new(&file).exists()
}

View File

@@ -2,26 +2,20 @@
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use tauri::Manager;
use tauri::Manager;
// 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;
use std::time::{SystemTime, UNIX_EPOCH};
// System Tray
#[cfg(desktop)]
mod tray;
// Local Modules
mod cmds;
mod steam;
@@ -39,109 +33,53 @@ fn on_button_clicked() -> String {
fn main() {
tauri::Builder::default()
.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()?;
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
.plugin(tauri_plugin_clipboard_manager::init())
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_os::init())
.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
#[cfg(all(desktop))]
{
let handle = app.handle();
tray::create_tray(handle)?;
}
// 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();
// Get Window
let window = app.get_webview_window("main").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();
// 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");
// Get Window
let window = app.get_webview_window("main").unwrap();
#[cfg(target_os = "windows")]
apply_mica(&window, Some(false))
.expect("Unsupported platform! 'apply_mica' is only supported on Windows");
// 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");
// apply_blur(&window, Some((18, 18, 18, 0)))
// .expect("Unsupported platform! 'apply_blur' is only supported on Windows");
#[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");
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,
on_button_clicked
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@@ -24,16 +24,16 @@ pub fn get_steam_path<'a>() -> Result<String, &'a str> {
}
pub fn get_cs_path<'a>(name: &str) -> Result<String, &'a str> {
if name != "csgo" || name != "cs2" {
return Err("invalid cs name");
}
if name != "csgo" || name != "cs2" {
return Err("invalid cs name");
}
#[cfg(target_os = "windows")]
if let Ok(cs_path) = get_exe_path(&(name.to_owned() + ".exe")) {
return Ok(cs_path);
}
#[cfg(target_os = "windows")]
if let Ok(cs_path) = get_exe_path(&(name.to_owned() + ".exe")) {
return Ok(cs_path);
}
Err("no cs path found")
Err("no cs path found")
}
#[cfg(test)]

104
src-tauri/src/tray.rs Normal file
View File

@@ -0,0 +1,104 @@
use tauri::{
menu::{Menu, MenuItem},
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
Manager, Runtime,
};
pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
let quit_i = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
let menu = Menu::with_items(app, &[&quit_i])?;
let _ = TrayIconBuilder::with_id("tray")
.icon(app.default_window_icon().unwrap().clone())
.menu(&menu)
.menu_on_left_click(false)
.on_menu_event(move |app, event| match event.id.as_ref() {
"quit" => {
app.exit(0);
}
// Add more events here
_ => {}
})
.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(())
}
// 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();

View File

@@ -3,56 +3,49 @@
"build": {
"beforeBuildCommand": "pnpm next-build",
"beforeDevCommand": "pnpm next-start",
"devPath": "http://localhost:3000",
"distDir": "../out"
"frontendDist": "../out",
"devUrl": "http://localhost:3000"
},
"package": {
"productName": "tauri-nextjs-template",
"version": "0.1.0"
},
"tauri": {
"allowlist": {
"all": true
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"targets": "all",
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"linux": {
"deb": {
"depends": []
},
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.tauri.dev",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null
},
"updater": {
"active": false
},
}
},
"productName": "tauri-nextjs-template",
"mainBinaryName": "tauri-nextjs-template",
"version": "0.1.0",
"identifier": "com.tauri.dev",
"plugins": {},
"app": {
"windows": [
{
"fullscreen": false,
@@ -68,6 +61,9 @@
"hiddenTitle": true,
"titleBarStyle": "Overlay"
}
]
],
"security": {
"csp": null
}
}
}