fix: create window correctly

This commit is contained in:
GyDi 2022-10-11 00:57:34 +08:00
parent f2bd6f1fce
commit 41b19f69de
No known key found for this signature in database
GPG Key ID: 58B15242BA8277A6
3 changed files with 19 additions and 75 deletions

View File

@ -19,18 +19,12 @@ use tauri::{
}; };
fn main() -> std::io::Result<()> { fn main() -> std::io::Result<()> {
let mut context = tauri::generate_context!(); {
let verge = Verge::new();
let verge = Verge::new(); if server::check_singleton(verge.app_singleton_port).is_err() {
println!("app exists");
if server::check_singleton(verge.app_singleton_port).is_err() { return Ok(());
println!("app exists");
return Ok(());
}
for win in context.config_mut().tauri.windows.iter_mut() {
if verge.enable_silent_start.unwrap_or(false) {
win.visible = false;
} }
} }
@ -147,7 +141,7 @@ fn main() -> std::io::Result<()> {
#[allow(unused_mut)] #[allow(unused_mut)]
let mut app = builder let mut app = builder
.build(context) .build(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]

View File

@ -6,20 +6,24 @@ pub fn resolve_setup(app: &App) {
// init app config // init app config
init::init_app(app.package_info()); init::init_app(app.package_info());
{ let silent_start = {
let global = Data::global(); let global = Data::global();
let verge = global.verge.lock(); let verge = global.verge.lock();
let singleton = verge.app_singleton_port.clone(); let singleton = verge.app_singleton_port.clone();
// setup a simple http server for singleton // setup a simple http server for singleton
server::embed_server(&app.handle(), singleton); server::embed_server(&app.handle(), singleton);
}
verge.enable_silent_start.clone().unwrap_or(false)
};
// core should be initialized after init_app fix #122 // core should be initialized after init_app fix #122
let core = Core::global(); let core = Core::global();
core.init(app.app_handle()); core.init(app.app_handle());
resolve_window(app); if !silent_start || cfg!(target_os = "macos") {
create_window(&app.app_handle());
}
} }
/// reset system proxy /// reset system proxy
@ -33,39 +37,6 @@ pub fn resolve_reset() {
crate::log_if_err!(service.stop()); crate::log_if_err!(service.stop());
} }
/// customize the window theme
fn resolve_window(app: &App) {
let window = app.get_window("main").unwrap();
#[cfg(target_os = "windows")]
{
use crate::utils::winhelp;
use window_shadows::set_shadow;
use window_vibrancy::apply_blur;
let _ = window.set_decorations(false);
let _ = set_shadow(&window, true);
// todo
// win11 disable this feature temporarily due to lag
if !winhelp::is_win11() {
let _ = apply_blur(&window, None);
}
}
#[cfg(target_os = "macos")]
{
use tauri::LogicalSize;
use tauri::Size::Logical;
let _ = window.set_decorations(true);
let _ = window.set_size(Logical(LogicalSize {
width: 800.0,
height: 620.0,
}));
}
}
/// create main window /// create main window
pub fn create_window(app_handle: &AppHandle) { pub fn create_window(app_handle: &AppHandle) {
if let Some(window) = app_handle.get_window("main") { if let Some(window) = app_handle.get_window("main") {
@ -120,7 +91,7 @@ pub fn create_window(app_handle: &AppHandle) {
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
crate::log_if_err!(builder.decorations(true).inner_size(800.0, 620.0).build()); crate::log_if_err!(builder.decorations(true).inner_size(800.0, 642.0).build());
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
crate::log_if_err!(builder crate::log_if_err!(builder

View File

@ -25,13 +25,8 @@
"icons/icon-new.icns", "icons/icon-new.icns",
"icons/icon.ico" "icons/icon.ico"
], ],
"resources": [ "resources": ["resources"],
"resources" "externalBin": ["sidecar/clash", "sidecar/clash-meta"],
],
"externalBin": [
"sidecar/clash",
"sidecar/clash-meta"
],
"copyright": "© 2022 zzzgydi All Rights Reserved", "copyright": "© 2022 zzzgydi All Rights Reserved",
"category": "DeveloperTool", "category": "DeveloperTool",
"shortDescription": "A Clash GUI based on tauri.", "shortDescription": "A Clash GUI based on tauri.",
@ -51,10 +46,7 @@
"digestAlgorithm": "sha256", "digestAlgorithm": "sha256",
"timestampUrl": "", "timestampUrl": "",
"wix": { "wix": {
"language": [ "language": ["zh-CN", "en-US"]
"zh-CN",
"en-US"
]
} }
} }
}, },
@ -81,22 +73,9 @@
"all": true "all": true
} }
}, },
"windows": [ "windows": [],
{
"title": "Clash Verge",
"width": 800,
"height": 636,
"center": true,
"resizable": true,
"fullscreen": false,
"decorations": false,
"transparent": true,
"minWidth": 600,
"minHeight": 520
}
],
"security": { "security": {
"csp": "script-src 'unsafe-eval' 'self'; default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; img-src data: 'self';" "csp": "script-src 'unsafe-eval' 'self'; default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; img-src data: 'self';"
} }
} }
} }