2025-09-18 10:22:43 +08:00
|
|
|
use tauri::WebviewWindow;
|
2025-08-29 23:51:09 +08:00
|
|
|
|
|
|
|
|
use crate::{
|
2025-10-18 20:25:31 +08:00
|
|
|
config::Config,
|
2025-08-29 23:51:09 +08:00
|
|
|
core::handle,
|
2025-10-08 12:32:40 +08:00
|
|
|
logging_error,
|
2025-08-29 23:51:09 +08:00
|
|
|
utils::{
|
|
|
|
|
logging::Type,
|
2025-09-18 10:22:43 +08:00
|
|
|
resolve::window_script::{INITIAL_LOADING_OVERLAY, WINDOW_INITIAL_SCRIPT},
|
2025-08-29 23:51:09 +08:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 定义默认窗口尺寸常量
|
|
|
|
|
const DEFAULT_WIDTH: f64 = 940.0;
|
|
|
|
|
const DEFAULT_HEIGHT: f64 = 700.0;
|
|
|
|
|
|
|
|
|
|
const MINIMAL_WIDTH: f64 = 520.0;
|
|
|
|
|
const MINIMAL_HEIGHT: f64 = 520.0;
|
|
|
|
|
|
|
|
|
|
/// 构建新的 WebView 窗口
|
2025-10-18 20:25:31 +08:00
|
|
|
pub async fn build_new_window() -> Result<WebviewWindow, String> {
|
2025-10-08 12:32:40 +08:00
|
|
|
let app_handle = handle::Handle::app_handle();
|
2025-08-29 23:51:09 +08:00
|
|
|
|
2025-11-01 20:03:56 +08:00
|
|
|
let config = Config::verge().await;
|
Refactor configuration access to use latest_arc() instead of latest_ref()
- Updated multiple instances in the codebase to replace calls to latest_ref() with latest_arc() for improved performance and memory management.
- This change affects various modules including validate, enhance, feat (backup, clash, config, profile, proxy, window), utils (draft, i18n, init, network, resolve, server).
- Ensured that all references to configuration data are now using the new arc-based approach to enhance concurrency and reduce cloning overhead.
refactor: update imports to explicitly include ClashInfo and Config in command files
2025-11-03 05:41:53 +08:00
|
|
|
let latest = config.latest_arc();
|
2025-11-01 20:03:56 +08:00
|
|
|
let start_page = latest.start_page.as_deref().unwrap_or("/");
|
|
|
|
|
|
2025-09-18 10:22:43 +08:00
|
|
|
match tauri::WebviewWindowBuilder::new(
|
2025-10-08 12:32:40 +08:00
|
|
|
app_handle,
|
2025-08-29 23:51:09 +08:00
|
|
|
"main", /* the unique window label */
|
2025-11-01 20:03:56 +08:00
|
|
|
tauri::WebviewUrl::App(start_page.into()),
|
2025-08-29 23:51:09 +08:00
|
|
|
)
|
|
|
|
|
.title("Clash Verge")
|
|
|
|
|
.center()
|
2025-10-08 20:23:26 +08:00
|
|
|
// Using WindowManager::prefer_system_titlebar to control if show system built-in titlebar
|
|
|
|
|
// .decorations(true)
|
2025-08-29 23:51:09 +08:00
|
|
|
.fullscreen(false)
|
|
|
|
|
.inner_size(DEFAULT_WIDTH, DEFAULT_HEIGHT)
|
|
|
|
|
.min_inner_size(MINIMAL_WIDTH, MINIMAL_HEIGHT)
|
|
|
|
|
.visible(true) // 立即显示窗口,避免用户等待
|
|
|
|
|
.initialization_script(WINDOW_INITIAL_SCRIPT)
|
|
|
|
|
.build()
|
2025-09-18 10:22:43 +08:00
|
|
|
{
|
2025-08-29 23:51:09 +08:00
|
|
|
Ok(window) => {
|
Refactor logging macros to remove print control parameter
- Updated logging macros to eliminate the boolean parameter for print control, simplifying the logging calls throughout the codebase.
- Adjusted all logging calls in various modules (lib.rs, lightweight.rs, help.rs, init.rs, logging.rs, resolve/mod.rs, resolve/scheme.rs, resolve/ui.rs, resolve/window.rs, server.rs, singleton.rs, window_manager.rs) to reflect the new macro structure.
- Ensured consistent logging behavior across the application by standardizing the logging format.
2025-10-10 13:05:01 +08:00
|
|
|
logging_error!(Type::Window, window.eval(INITIAL_LOADING_OVERLAY));
|
2025-09-18 10:22:43 +08:00
|
|
|
Ok(window)
|
2025-08-29 23:51:09 +08:00
|
|
|
}
|
2025-09-18 10:22:43 +08:00
|
|
|
Err(e) => Err(e.to_string()),
|
|
|
|
|
}
|
2025-08-29 23:51:09 +08:00
|
|
|
}
|