From 4974b1c489473c8cbbbe3943b0b2f6ad6bd25da0 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Sat, 10 Dec 2022 19:28:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E7=AE=80Linux=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/main.rs | 52 ++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 8c71c30..bcb451c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -169,35 +169,31 @@ fn main() -> wry::Result<()> { // 自定义cookie文件夹,仅用于Linux // Custom Cookie folder, only for Linux #[cfg(target_os = "linux")] - let user = std::env::var_os("USER"); - #[cfg(target_os = "linux")] - let config_path = match user { - Some(v) => format!( - "/home/{}/.config/{}", - v.into_string().unwrap(), - package_name, - ), - None => panic!("can't found any user"), + let webview = { + let user = std::env::var_os("USER"); + let config_path = match user { + Some(v) => format!( + "/home/{}/.config/{}", + v.into_string().unwrap(), + package_name, + ), + None => panic!("can't found any user"), + }; + let data_path = std::path::PathBuf::from(&config_path); + if !std::path::Path::new(&data_path).exists() { + std::fs::create_dir(&data_path) + .unwrap_or_else(|_| panic!("can't create dir {}", &config_path)); + } + let mut web_content = WebContext::new(Some(data_path)); + WebViewBuilder::new(window)? + // .with_user_agent(user_agent_string) + .with_url(&url.to_string())? + .with_devtools(cfg!(feature = "devtools")) + .with_initialization_script(include_str!("pake.js")) + .with_ipc_handler(handler) + .with_web_context(&mut web_content) + .build()? }; - #[cfg(target_os = "linux")] - let data_path = std::path::PathBuf::from(&config_path); - #[cfg(target_os = "linux")] - if !std::path::Path::new(&data_path).exists() { - std::fs::create_dir(&data_path) - .unwrap_or_else(|_| panic!("can't create dir {}", &config_path)); - } - #[cfg(target_os = "linux")] - let mut web_content = WebContext::new(Some(data_path)); - #[cfg(target_os = "linux")] - let webview = WebViewBuilder::new(window)? - // .with_user_agent(user_agent_string) - .with_url(&url.to_string())? - .with_devtools(cfg!(feature = "devtools")) - .with_initialization_script(include_str!("pake.js")) - .with_ipc_handler(handler) - .with_web_context(&mut web_content) - .build()?; - #[cfg(feature = "devtools")] { webview.open_devtools();