mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
fix(config): restart and quit application or shutdown system can not remember user's behavior #5347, #5359, #5430
This commit is contained in:
@@ -200,6 +200,22 @@ impl Config {
|
|||||||
logging!(error, Type::Setup, "Config init verification failed: {}", e);
|
logging!(error, Type::Setup, "Config init verification failed: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 升级草稿为正式数据,并写入文件。避免用户行为丢失。
|
||||||
|
// 仅在应用退出、重启、关机监听事件启用
|
||||||
|
pub async fn apply_all_and_save_file() {
|
||||||
|
let clash = Self::clash().await;
|
||||||
|
clash.apply();
|
||||||
|
logging_error!(Type::Config, clash.data_arc().save_config().await);
|
||||||
|
|
||||||
|
let verge = Self::verge().await;
|
||||||
|
verge.apply();
|
||||||
|
logging_error!(Type::Config, verge.data_arc().save_file().await);
|
||||||
|
|
||||||
|
let profiles = Self::profiles().await;
|
||||||
|
profiles.apply();
|
||||||
|
logging_error!(Type::Config, profiles.data_arc().save_file().await);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ pub async fn restart_clash_core() {
|
|||||||
/// Restart the application
|
/// Restart the application
|
||||||
pub async fn restart_app() {
|
pub async fn restart_app() {
|
||||||
utils::server::shutdown_embedded_server();
|
utils::server::shutdown_embedded_server();
|
||||||
|
Config::apply_all_and_save_file().await;
|
||||||
if let Err(err) = resolve::resolve_reset_async().await {
|
if let Err(err) = resolve::resolve_reset_async().await {
|
||||||
handle::Handle::notice_message(
|
handle::Handle::notice_message(
|
||||||
"restart_app::error",
|
"restart_app::error",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use crate::module::lightweight;
|
|||||||
use crate::utils;
|
use crate::utils;
|
||||||
use crate::utils::window_manager::WindowManager;
|
use crate::utils::window_manager::WindowManager;
|
||||||
use clash_verge_logging::{Type, logging};
|
use clash_verge_logging::{Type, logging};
|
||||||
|
use tokio::time::{Duration, timeout};
|
||||||
|
|
||||||
/// Public API: open or close the dashboard
|
/// Public API: open or close the dashboard
|
||||||
pub async fn open_or_close_dashboard() {
|
pub async fn open_or_close_dashboard() {
|
||||||
@@ -20,6 +21,7 @@ async fn open_or_close_dashboard_internal() {
|
|||||||
pub async fn quit() {
|
pub async fn quit() {
|
||||||
logging!(debug, Type::System, "启动退出流程");
|
logging!(debug, Type::System, "启动退出流程");
|
||||||
utils::server::shutdown_embedded_server();
|
utils::server::shutdown_embedded_server();
|
||||||
|
Config::apply_all_and_save_file().await;
|
||||||
|
|
||||||
// 获取应用句柄并设置退出标志
|
// 获取应用句柄并设置退出标志
|
||||||
let app_handle = handle::Handle::app_handle();
|
let app_handle = handle::Handle::app_handle();
|
||||||
@@ -38,8 +40,6 @@ pub async fn quit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn clean_async() -> bool {
|
pub async fn clean_async() -> bool {
|
||||||
use tokio::time::{Duration, timeout};
|
|
||||||
|
|
||||||
logging!(info, Type::System, "开始执行异步清理操作...");
|
logging!(info, Type::System, "开始执行异步清理操作...");
|
||||||
|
|
||||||
// 1. 处理TUN模式
|
// 1. 处理TUN模式
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ pub(super) fn init_signal() {
|
|||||||
clash_verge_signal::register(
|
clash_verge_signal::register(
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
handle::Handle::app_handle(),
|
handle::Handle::app_handle(),
|
||||||
feat::clean_async,
|
feat::quit,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user