refactor: pake-cli support tauri 2.x beta
This commit is contained in:
13
src-tauri/Cargo.lock
generated
13
src-tauri/Cargo.lock
generated
@@ -3552,9 +3552,9 @@ checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f"
|
||||
|
||||
[[package]]
|
||||
name = "tauri"
|
||||
version = "2.0.0-beta.24"
|
||||
version = "2.0.0-beta.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3eab508aad4ae86e23865e294b20a7bb89bd7afea523897b7478329b841d4295"
|
||||
checksum = "4339c67eb7700fe4a80ad6507e3b9af0b4159959f3d74aae48feed298baf4cbf"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
@@ -3568,6 +3568,7 @@ dependencies = [
|
||||
"gtk",
|
||||
"heck 0.5.0",
|
||||
"http",
|
||||
"image 0.24.9",
|
||||
"jni",
|
||||
"libc",
|
||||
"log",
|
||||
@@ -3781,9 +3782,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-runtime"
|
||||
version = "2.0.0-beta.20"
|
||||
version = "2.0.0-beta.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe978df03966febbebc608931dc2cf26ef94df70855a18b05f07134cf474de09"
|
||||
checksum = "189510033be50f6fde35cfa50b50c7ab4e0ced0c867ae0f643b4907b8385bbe5"
|
||||
dependencies = [
|
||||
"dpi",
|
||||
"gtk",
|
||||
@@ -3800,9 +3801,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-runtime-wry"
|
||||
version = "2.0.0-beta.20"
|
||||
version = "2.0.0-beta.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11e4d568f61095f507b3fc4254dfbfff3b20de2a1d66167ffca3f6d90b14db8f"
|
||||
checksum = "6938bd63b6658e7b08f0fe2151390148ee5a8ccdba100d4dff961d2c8734d9a9"
|
||||
dependencies = [
|
||||
"cocoa",
|
||||
"gtk",
|
||||
|
||||
@@ -21,7 +21,7 @@ tauri-build = { version = "2.0.0-beta", features = [] }
|
||||
[dependencies]
|
||||
serde_json = "1.0.116"
|
||||
serde = { version = "1.0.200", features = ["derive"] }
|
||||
tauri = { version = "2.0.0-beta", features = ["tray-icon"] }
|
||||
tauri = { version = "2.0.0-beta.25", features = ["tray-icon", "image-ico", "image-png"] }
|
||||
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||
tauri-plugin-oauth = { git = "https://github.com/FabianLars/tauri-plugin-oauth", branch = "v2" }
|
||||
tauri-plugin-clipboard-manager = "2.1.0-beta.6"
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1921,6 +1921,13 @@
|
||||
"window:allow-set-size"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:allow-set-size-constraints -> Enables the set_size_constraints command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"window:allow-set-size-constraints"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:allow-set-skip-taskbar -> Enables the set_skip_taskbar command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
@@ -2369,6 +2376,13 @@
|
||||
"window:deny-set-size"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:deny-set-size-constraints -> Denies the set_size_constraints command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"window:deny-set-size-constraints"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:deny-set-skip-taskbar -> Denies the set_skip_taskbar command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
|
||||
@@ -1921,6 +1921,13 @@
|
||||
"window:allow-set-size"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:allow-set-size-constraints -> Enables the set_size_constraints command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"window:allow-set-size-constraints"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:allow-set-skip-taskbar -> Enables the set_skip_taskbar command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
@@ -2369,6 +2376,13 @@
|
||||
"window:deny-set-size"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:deny-set-size-constraints -> Denies the set_size_constraints command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"window:deny-set-size-constraints"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:deny-set-skip-taskbar -> Denies the set_skip_taskbar command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
src-tauri/icons/xiaoyuzhou.icns
Normal file
BIN
src-tauri/icons/xiaoyuzhou.icns
Normal file
Binary file not shown.
@@ -51,6 +51,7 @@ pub struct PakeConfig {
|
||||
pub windows: Vec<WindowConfig>,
|
||||
pub user_agent: UserAgent,
|
||||
pub system_tray: FunctionON,
|
||||
pub system_tray_path: String,
|
||||
}
|
||||
|
||||
impl PakeConfig {
|
||||
|
||||
@@ -1,16 +1,44 @@
|
||||
use tauri::{
|
||||
menu::{MenuBuilder, MenuItemBuilder}, tray::TrayIconBuilder, AppHandle, Manager
|
||||
image::Image, include_image, menu::{ContextMenu, MenuBuilder, MenuItemBuilder}, tray::{MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent}, AppHandle, Config, Manager
|
||||
};
|
||||
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
|
||||
|
||||
pub fn set_system_tray(app: &AppHandle) -> tauri::Result<()> {
|
||||
use super::config::PakeConfig;
|
||||
|
||||
pub fn set_system_tray(app: &AppHandle, pake_config: &PakeConfig) -> tauri::Result<()> {
|
||||
let hide_app = MenuItemBuilder::with_id("hide_app", "Hide").build(app)?;
|
||||
let show_app = MenuItemBuilder::with_id("show_app", "Show").build(app)?;
|
||||
let quit = MenuItemBuilder::with_id("quit", "Quit").build(app)?;
|
||||
let menu = MenuBuilder::new(app).items(&[&hide_app, &show_app, &quit]).build()?;
|
||||
|
||||
TrayIconBuilder::new()
|
||||
app.app_handle().remove_tray_by_id("pake-tray");
|
||||
let tray = TrayIconBuilder::new()
|
||||
.icon(Image::from_path(pake_config.system_tray_path.as_str())?)
|
||||
.menu(&menu)
|
||||
.on_tray_icon_event(move |tray, event| {
|
||||
if let TrayIconEvent::Click {
|
||||
button: MouseButton::Left,
|
||||
button_state: MouseButtonState::Up,
|
||||
..
|
||||
} = event {
|
||||
println!("click");
|
||||
|
||||
let app = tray.app_handle();
|
||||
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
if let Some(webview_window) = app.get_webview_window("pake") {
|
||||
let _ = webview_window.show();
|
||||
let _ = webview_window.set_focus();
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
tauri::AppHandle::show(&app.app_handle()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
.on_menu_event(move |app, event| match event.id().as_ref() {
|
||||
"hide_app" => {
|
||||
app.get_webview_window("pake").unwrap().minimize().unwrap();
|
||||
@@ -26,5 +54,6 @@ pub fn set_system_tray(app: &AppHandle) -> tauri::Result<()> {
|
||||
})
|
||||
.build(app)?;
|
||||
|
||||
tray.set_icon_as_template(false)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use tauri::{App, WebviewUrl, WebviewWindow, WebviewWindowBuilder};
|
||||
#[cfg(target_os = "macos")]
|
||||
use tauri::TitleBarStyle;
|
||||
|
||||
pub fn get_window(app: &mut App, config: PakeConfig, _data_dir: PathBuf) -> WebviewWindow {
|
||||
pub fn get_window(app: &mut App, config: &PakeConfig, _data_dir: PathBuf) -> WebviewWindow {
|
||||
let window_config = config
|
||||
.windows
|
||||
.first()
|
||||
|
||||
6
src-tauri/src/inject/custom.js
vendored
6
src-tauri/src/inject/custom.js
vendored
@@ -1,6 +0,0 @@
|
||||
/*
|
||||
* This file serves as a collection point for external JS and CSS dependencies.
|
||||
* It amalgamates these external resources for easier injection into the application.
|
||||
* Additionally, you can directly include any script files in this file
|
||||
* that you wish to attach to the application.
|
||||
*/
|
||||
|
||||
@@ -8,14 +8,14 @@ use app::{invoke, menu::set_system_tray, window};
|
||||
use invoke::{download_file, download_file_by_binary};
|
||||
use tauri::Manager;
|
||||
use tauri_plugin_window_state::Builder as windowStatePlugin;
|
||||
use tauri_plugin_global_shortcut::Shortcut;
|
||||
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
|
||||
use util::{get_data_dir, get_pake_config};
|
||||
use window::get_window;
|
||||
|
||||
pub fn run_app() {
|
||||
let (pake_config, tauri_config) = get_pake_config();
|
||||
|
||||
let mut tauri_app = tauri::Builder::default();
|
||||
let tauri_app = tauri::Builder::default();
|
||||
|
||||
let show_system_tray = pake_config.show_system_tray();
|
||||
|
||||
@@ -31,24 +31,26 @@ pub fn run_app() {
|
||||
download_file_by_binary
|
||||
])
|
||||
.setup(move |app| {
|
||||
let data_dir = get_data_dir(&app.app_handle(), tauri_config);
|
||||
let data_dir = get_data_dir(&app.app_handle(), tauri_config.clone());
|
||||
|
||||
let _window = get_window(app, pake_config, data_dir);
|
||||
let _window = get_window(app, &pake_config, data_dir);
|
||||
// Prevent initial shaking
|
||||
_window.show().unwrap();
|
||||
|
||||
if show_system_tray {
|
||||
let _ = set_system_tray(&app.app_handle());
|
||||
let _ = set_system_tray(&app.app_handle(), &pake_config);
|
||||
} else {
|
||||
app.app_handle().remove_tray_by_id("pake-tray");
|
||||
}
|
||||
|
||||
if !activation_shortcut.is_empty() {
|
||||
let app_handle = app.app_handle().clone();
|
||||
let shortcut_hotkey = Shortcut::from_str(&activation_shortcut.as_str()).unwrap();
|
||||
|
||||
app_handle
|
||||
.plugin(
|
||||
tauri_plugin_global_shortcut::Builder::new()
|
||||
.with_shortcut(activation_shortcut.as_str())
|
||||
?.with_handler(move |app, event, _shortcut| {
|
||||
let shortcut_hotkey = Shortcut::from_str(&activation_shortcut.as_str()).unwrap();
|
||||
.with_handler(move |app, event, _shortcut| {
|
||||
|
||||
if shortcut_hotkey.eq(event) {
|
||||
let window = app.get_webview_window("pake").unwrap();
|
||||
@@ -63,6 +65,8 @@ pub fn run_app() {
|
||||
}
|
||||
).build())
|
||||
.expect("Error registering global evoke shortcuts!");
|
||||
|
||||
app.global_shortcut().register(shortcut_hotkey)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
},
|
||||
"trayIcon": {
|
||||
"iconPath": "png/icon_512.png",
|
||||
"iconAsTemplate": false
|
||||
"iconAsTemplate": false,
|
||||
"id": "pake-tray"
|
||||
},
|
||||
"withGlobalTauri": true
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
{
|
||||
"tauri": {
|
||||
"identifier": "com.pake.weread",
|
||||
|
||||
"bundle": {
|
||||
"icon": ["png/weread_512.png"],
|
||||
"identifier": "com.pake.weread",
|
||||
"active": true,
|
||||
"category": "DeveloperTool",
|
||||
"copyright": "",
|
||||
"deb": {
|
||||
"depends": ["curl", "wget"],
|
||||
"files": { "/usr/share/applications/com-pake-weread.desktop": "assets/com-pake-weread.desktop" }
|
||||
"linux": {
|
||||
"deb": {
|
||||
"depends": ["curl", "wget"],
|
||||
"files": { "/usr/share/applications/com-pake-weread.desktop": "assets/com-pake-weread.desktop" }
|
||||
}
|
||||
},
|
||||
"externalBin": [],
|
||||
"longDescription": "",
|
||||
@@ -16,5 +18,4 @@
|
||||
"shortDescription": "",
|
||||
"targets": ["deb", "appimage"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
{
|
||||
"tauri": {
|
||||
"bundle": {
|
||||
"icon": ["png/weread_256.ico", "png/weread_32.ico"],
|
||||
"identifier": "com.pake.weread",
|
||||
"active": true,
|
||||
"category": "DeveloperTool",
|
||||
"copyright": "",
|
||||
"externalBin": [],
|
||||
"longDescription": "",
|
||||
"resources": ["png/weread_32.ico"],
|
||||
"shortDescription": "",
|
||||
"targets": ["msi"],
|
||||
"windows": {
|
||||
"certificateThumbprint": null,
|
||||
"digestAlgorithm": "sha256",
|
||||
"timestampUrl": "",
|
||||
"wix": {
|
||||
"language": ["en-US"],
|
||||
"template": "assets/main.wxs"
|
||||
}
|
||||
"identifier": "com.pake.weread",
|
||||
"bundle": {
|
||||
"icon": ["png/weread_256.ico", "png/weread_32.ico"],
|
||||
"active": true,
|
||||
"category": "DeveloperTool",
|
||||
"copyright": "",
|
||||
"externalBin": [],
|
||||
"longDescription": "",
|
||||
"resources": ["png/weread_32.ico"],
|
||||
"shortDescription": "",
|
||||
"targets": ["msi"],
|
||||
"windows": {
|
||||
"certificateThumbprint": null,
|
||||
"digestAlgorithm": "sha256",
|
||||
"timestampUrl": "",
|
||||
"wix": {
|
||||
"language": ["en-US"],
|
||||
"template": "assets/main.wxs"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user