From 4fcaf3fb59befa91450d6873a095407053cdf512 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Tue, 6 Dec 2022 23:33:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9Linux=E4=B8=8B=E5=8C=85?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E9=9A=8F=E7=9D=80=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=8A=A8=E6=80=81=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/main.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 17c63f6..db1c8ca 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -79,6 +79,12 @@ fn main() -> wry::Result<()> { #[cfg(target_os = "macos")] menu_bar_menu.add_submenu("App", true, first_menu); + #[cfg(target_os = "linux")] + let (package_name, windows_config) = get_windows_config(); + + #[cfg(target_os = "linux")] + let package_name = package_name.expect("can't get package name in config file"); + #[cfg(target_os = "linux")] let WindowConfig { url, @@ -87,7 +93,7 @@ fn main() -> wry::Result<()> { resizable, fullscreen, .. - } = get_windows_config().unwrap_or_default(); + } = windows_config.unwrap_or_default(); #[cfg(target_os = "windows")] let WindowConfig { url, @@ -185,11 +191,12 @@ fn main() -> wry::Result<()> { // 自定义cookie文件夹,仅用于Linux // Custom Cookie folder, only for Linux #[cfg(target_os = "linux")] - let data_path = - std::path::PathBuf::from(concat!("/home/", env!("USER"), "/.config/com-tw93-weread/")); + let config_path = format!("/home/{}/.config/{}", env!("USER"), package_name); + #[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)?; + std::fs::create_dir(&data_path).expect(&format!("can't create dir {}", &config_path)); } #[cfg(target_os = "linux")] let mut web_content = WebContext::new(Some(data_path)); @@ -236,11 +243,14 @@ fn main() -> wry::Result<()> { }); } -fn get_windows_config() -> Option { +fn get_windows_config() -> (Option,Option) { let config_file = include_str!("../tauri.conf.json"); let config: Config = serde_json::from_str(config_file).expect("failed to parse windows config"); - config.tauri.windows.first().cloned() + ( + config.package.product_name.clone(), + config.tauri.windows.first().cloned() + ) } #[cfg(target_os = "windows")]