mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 05:23:44 +08:00
feat: use tauri-plugin-persisted-scope
This commit is contained in:
parent
794783ab4e
commit
f4238b1fb9
26
src-tauri/Cargo.lock
generated
26
src-tauri/Cargo.lock
generated
@ -556,6 +556,15 @@ version = "0.22.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bincode"
|
||||||
|
version = "1.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bit_field"
|
name = "bit_field"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
@ -1010,6 +1019,7 @@ dependencies = [
|
|||||||
"tauri-plugin-fs",
|
"tauri-plugin-fs",
|
||||||
"tauri-plugin-global-shortcut",
|
"tauri-plugin-global-shortcut",
|
||||||
"tauri-plugin-notification",
|
"tauri-plugin-notification",
|
||||||
|
"tauri-plugin-persisted-scope",
|
||||||
"tauri-plugin-process",
|
"tauri-plugin-process",
|
||||||
"tauri-plugin-shell",
|
"tauri-plugin-shell",
|
||||||
"tauri-plugin-updater",
|
"tauri-plugin-updater",
|
||||||
@ -6542,6 +6552,22 @@ dependencies = [
|
|||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tauri-plugin-persisted-scope"
|
||||||
|
version = "2.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae4f33cca1496783c6115c14c9b282f928683920babeeae5c52df8ca3628001b"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"bincode",
|
||||||
|
"log",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"tauri",
|
||||||
|
"tauri-plugin-fs",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-plugin-process"
|
name = "tauri-plugin-process"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
|
@ -54,6 +54,7 @@ tauri-plugin-clipboard-manager = "2.0.1"
|
|||||||
tauri-plugin-deep-link = "2.0.1"
|
tauri-plugin-deep-link = "2.0.1"
|
||||||
tauri-plugin-devtools = "2.0.0-rc"
|
tauri-plugin-devtools = "2.0.0-rc"
|
||||||
url = "2.5.2"
|
url = "2.5.2"
|
||||||
|
tauri-plugin-persisted-scope = "2.0.3"
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
runas = "=1.2.0"
|
runas = "=1.2.0"
|
||||||
deelevate = "0.2.0"
|
deelevate = "0.2.0"
|
||||||
|
@ -122,14 +122,6 @@ pub struct IVerge {
|
|||||||
/// 0: 不清理; 1: 7天; 2: 30天; 3: 90天
|
/// 0: 不清理; 1: 7天; 2: 30天; 3: 90天
|
||||||
pub auto_log_clean: Option<i32>,
|
pub auto_log_clean: Option<i32>,
|
||||||
|
|
||||||
/// window size and position
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub window_size_position: Option<Vec<f64>>,
|
|
||||||
|
|
||||||
/// window size and position
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub window_is_maximized: Option<bool>,
|
|
||||||
|
|
||||||
/// 是否启用随机端口
|
/// 是否启用随机端口
|
||||||
pub enable_random_port: Option<bool>,
|
pub enable_random_port: Option<bool>,
|
||||||
|
|
||||||
@ -312,8 +304,6 @@ impl IVerge {
|
|||||||
patch!(proxy_layout_column);
|
patch!(proxy_layout_column);
|
||||||
patch!(test_list);
|
patch!(test_list);
|
||||||
patch!(auto_log_clean);
|
patch!(auto_log_clean);
|
||||||
patch!(window_size_position);
|
|
||||||
patch!(window_is_maximized);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 在初始化前尝试拿到单例端口的值
|
/// 在初始化前尝试拿到单例端口的值
|
||||||
|
@ -41,6 +41,7 @@ pub fn run() {
|
|||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
.plugin(tauri_plugin_shell::init())
|
.plugin(tauri_plugin_shell::init())
|
||||||
.plugin(tauri_plugin_deep_link::init())
|
.plugin(tauri_plugin_deep_link::init())
|
||||||
|
.plugin(tauri_plugin_persisted_scope::init())
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
@ -143,7 +144,6 @@ pub fn run() {
|
|||||||
match event {
|
match event {
|
||||||
tauri::WindowEvent::CloseRequested { api, .. } => {
|
tauri::WindowEvent::CloseRequested { api, .. } => {
|
||||||
println!("closing window...");
|
println!("closing window...");
|
||||||
let _ = resolve::save_window_size_position(true);
|
|
||||||
api.prevent_close();
|
api.prevent_close();
|
||||||
let window = core::handle::Handle::global().get_window().unwrap();
|
let window = core::handle::Handle::global().get_window().unwrap();
|
||||||
log_err!(window.hide());
|
log_err!(window.hide());
|
||||||
|
@ -126,7 +126,7 @@ pub fn create_window() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut builder = tauri::WebviewWindowBuilder::new(
|
let builder = tauri::WebviewWindowBuilder::new(
|
||||||
&app_handle,
|
&app_handle,
|
||||||
"main".to_string(),
|
"main".to_string(),
|
||||||
tauri::WebviewUrl::App("index.html".into()),
|
tauri::WebviewUrl::App("index.html".into()),
|
||||||
@ -136,110 +136,29 @@ pub fn create_window() {
|
|||||||
.fullscreen(false)
|
.fullscreen(false)
|
||||||
.min_inner_size(600.0, 520.0);
|
.min_inner_size(600.0, 520.0);
|
||||||
|
|
||||||
match Config::verge().latest().window_size_position.clone() {
|
|
||||||
Some(size_pos) if size_pos.len() == 4 => {
|
|
||||||
let size = (size_pos[0], size_pos[1]);
|
|
||||||
let pos = (size_pos[2], size_pos[3]);
|
|
||||||
let w = size.0.clamp(600.0, f64::INFINITY);
|
|
||||||
let h = size.1.clamp(520.0, f64::INFINITY);
|
|
||||||
builder = builder.inner_size(w, h).position(pos.0, pos.1);
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
{
|
|
||||||
builder = builder.inner_size(800.0, 636.0).center();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
{
|
|
||||||
builder = builder.inner_size(800.0, 642.0).center();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
{
|
|
||||||
builder = builder.inner_size(800.0, 642.0).center();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let window = builder
|
let window = builder
|
||||||
.decorations(false)
|
.decorations(false)
|
||||||
.additional_browser_args("--enable-features=msWebView2EnableDraggableRegions --disable-features=OverscrollHistoryNavigation,msExperimentalScrolling")
|
.additional_browser_args("--enable-features=msWebView2EnableDraggableRegions --disable-features=OverscrollHistoryNavigation,msExperimentalScrolling")
|
||||||
.transparent(true)
|
.transparent(true)
|
||||||
|
.inner_size(800.0, 636.0)
|
||||||
.visible(false)
|
.visible(false)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
let window = builder
|
let _ = builder
|
||||||
.decorations(true)
|
.decorations(true)
|
||||||
.hidden_title(true)
|
.hidden_title(true)
|
||||||
.title_bar_style(tauri::TitleBarStyle::Overlay)
|
.title_bar_style(tauri::TitleBarStyle::Overlay)
|
||||||
|
.inner_size(800.0, 642.0)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
let window = builder.decorations(false).transparent(true).build();
|
let _ = builder
|
||||||
|
.decorations(false)
|
||||||
match window {
|
.transparent(true)
|
||||||
Ok(win) => {
|
.inner_size(800.0, 642.0)
|
||||||
let is_maximized = Config::verge()
|
.build();
|
||||||
.latest()
|
|
||||||
.window_is_maximized
|
|
||||||
.unwrap_or(false);
|
|
||||||
log::trace!(target:"app", "try to calculate the monitor size");
|
|
||||||
let center = (|| -> Result<bool> {
|
|
||||||
let mut center = false;
|
|
||||||
let monitor = win.current_monitor()?.ok_or(anyhow::anyhow!(""))?;
|
|
||||||
let size = monitor.size();
|
|
||||||
let pos = win.outer_position()?;
|
|
||||||
|
|
||||||
if pos.x < -400
|
|
||||||
|| pos.x > (size.width - 200) as i32
|
|
||||||
|| pos.y < -200
|
|
||||||
|| pos.y > (size.height - 200) as i32
|
|
||||||
{
|
|
||||||
center = true;
|
|
||||||
}
|
|
||||||
Ok(center)
|
|
||||||
})();
|
|
||||||
if center.unwrap_or(true) {
|
|
||||||
trace_err!(win.center(), "set win center");
|
|
||||||
}
|
|
||||||
|
|
||||||
// #[cfg(not(target_os = "linux"))]
|
|
||||||
// trace_err!(set_shadow(&win, true), "set win shadow");
|
|
||||||
if is_maximized {
|
|
||||||
trace_err!(win.maximize(), "set win maximize");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(_) => {
|
|
||||||
log::error!("failed to create window");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// save window size and position
|
|
||||||
pub fn save_window_size_position(save_to_file: bool) -> Result<()> {
|
|
||||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
|
||||||
let verge = Config::verge();
|
|
||||||
let mut verge = verge.latest();
|
|
||||||
|
|
||||||
if save_to_file {
|
|
||||||
verge.save_file()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let win = app_handle
|
|
||||||
.get_webview_window("main")
|
|
||||||
.ok_or(anyhow::anyhow!("failed to get window"))?;
|
|
||||||
|
|
||||||
let scale = win.scale_factor()?;
|
|
||||||
let size = win.inner_size()?;
|
|
||||||
let size = size.to_logical::<f64>(scale);
|
|
||||||
let pos = win.outer_position()?;
|
|
||||||
let pos = pos.to_logical::<f64>(scale);
|
|
||||||
let is_maximized = win.is_maximized()?;
|
|
||||||
verge.window_is_maximized = Some(is_maximized);
|
|
||||||
if !is_maximized && size.width >= 600.0 && size.height >= 520.0 {
|
|
||||||
verge.window_size_position = Some(vec![size.width, size.height, pos.x, pos.y]);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn resolve_scheme(param: String) -> Result<()> {
|
pub async fn resolve_scheme(param: String) -> Result<()> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user