From c105ebb82e6f39ec8b3898abf81403242d4efc17 Mon Sep 17 00:00:00 2001 From: Tlntin Date: Sun, 11 Dec 2022 03:42:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9windows=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=EF=BC=8C=E4=BF=AE=E5=A4=8D=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E4=BD=8D=E7=BD=AE=E6=89=93=E5=BC=80=E9=97=AA?= =?UTF-8?q?=E9=80=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/Cargo.lock | 10 + src-tauri/Cargo.toml | 1 + src-tauri/assets/main.wxs | 310 ++++++++++++++++++++++++++++++ src-tauri/src/main.rs | 40 ++-- src-tauri/tauri.windows.conf.json | 3 +- 5 files changed, 336 insertions(+), 28 deletions(-) create mode 100644 src-tauri/assets/main.wxs diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 99c601e..3870bb4 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -42,6 +42,7 @@ checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" name = "app" version = "0.1.0" dependencies = [ + "home", "image", "serde", "serde_json", @@ -1105,6 +1106,15 @@ dependencies = [ "libc", ] +[[package]] +name = "home" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "747309b4b440c06d57b0b25f2aee03ee9b5e5397d288c60e21fc709bb98a7408" +dependencies = [ + "winapi", +] + [[package]] name = "html5ever" version = "0.25.2" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index c010fb1..be38701 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -19,6 +19,7 @@ serde_json = "1.0.88" serde = { version = "1.0.147", features = ["derive"] } tauri = { version = "1.2.1", features = [] } image = "0.24.5" +home = "0.5" tauri-utils = "1.2.1" webbrowser = "0.8.2" wry = "0.23.1" diff --git a/src-tauri/assets/main.wxs b/src-tauri/assets/main.wxs new file mode 100644 index 0000000..4b92bd7 --- /dev/null +++ b/src-tauri/assets/main.wxs @@ -0,0 +1,310 @@ + + + + + + + + + + + + + + + + + + + + {{#if allow_downgrades}} + + {{else}} + + {{/if}} + + + Installed AND NOT UPGRADINGPRODUCTCODE + + + + + {{#if banner_path}} + + {{/if}} + {{#if dialog_image_path}} + + {{/if}} + {{#if license}} + + {{/if}} + + + + + + + + + + + + + + + + + + + WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed + + + + {{#unless license}} + + 1 + 1 + {{/unless}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{#each binaries as |bin| ~}} + + + + {{/each~}} + {{#if enable_elevated_update_task}} + + + + + + + + + + {{/if}} + {{{resources}}} + + + + + + + + + + + + + + + + + + + + + {{#each merge_modules as |msm| ~}} + + + + + + + + {{/each~}} + + + + + + {{#each resource_file_ids as |resource_file_id| ~}} + + {{/each~}} + + {{#if enable_elevated_update_task}} + + + + {{/if}} + + + + + + + + + + + {{#each binaries as |bin| ~}} + + {{/each~}} + + + + + {{#each component_group_refs as |id| ~}} + + {{/each~}} + {{#each component_refs as |id| ~}} + + {{/each~}} + {{#each feature_group_refs as |id| ~}} + + {{/each~}} + {{#each feature_refs as |id| ~}} + + {{/each~}} + {{#each merge_refs as |id| ~}} + + {{/each~}} + + + {{#if install_webview}} + + + + + + + {{#if download_bootstrapper}} + + + + + + + {{/if}} + + + {{#if webview2_bootstrapper_path}} + + + + + + + + {{/if}} + + + {{#if webview2_installer_path}} + + + + + + + + {{/if}} + + {{/if}} + + {{#if enable_elevated_update_task}} + + + + + NOT(REMOVE) + + + + + + + (REMOVE = "ALL") AND NOT UPGRADINGPRODUCTCODE + + + {{/if}} + + + + diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 80bd9f9..83943aa 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -23,7 +23,7 @@ use wry::application::{ #[cfg(target_os = "windows")] use wry::application::window::Icon; -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "linux", target_os = "windows"))] use wry::webview::WebContext; fn main() -> wry::Result<()> { @@ -147,35 +147,21 @@ fn main() -> wry::Result<()> { .with_back_forward_navigation_gestures(true) .build()?; - #[cfg(target_os = "windows")] - let webview = WebViewBuilder::new(window)? - // .with_user_agent(user_agent_string) - // .with_accept_first_mouse(true) - .with_url(&url.to_string())? - .with_devtools(cfg!(feature = "devtools")) - .with_initialization_script(include_str!("pake.js")) - .with_ipc_handler(handler) - .build()?; - - // 自定义cookie文件夹,仅用于Linux - // Custom Cookie folder, only for Linux - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "linux", target_os = "windows"))] 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 home_dir = match home::home_dir() { + Some(path1) => path1, + None => panic!("Error, can't found you home dir!!"), }; - 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)); + #[cfg(target_os = "windows")] + let data_dir = home_dir.join("AppData").join("Roaming").join(package_name); + #[cfg(target_os = "linux")] + let data_dir = home_dir.join(".config").join(package_name); + if !data_dir.exists() { + std::fs::create_dir(&data_dir) + .unwrap_or_else(|_| panic!("can't create dir {}", data_dir.display())); } - let mut web_content = WebContext::new(Some(data_path)); + let mut web_content = WebContext::new(Some(data_dir)); WebViewBuilder::new(window)? // .with_user_agent(user_agent_string) .with_url(&url.to_string())? diff --git a/src-tauri/tauri.windows.conf.json b/src-tauri/tauri.windows.conf.json index 357f830..0c2eb5b 100644 --- a/src-tauri/tauri.windows.conf.json +++ b/src-tauri/tauri.windows.conf.json @@ -19,7 +19,8 @@ "digestAlgorithm": "sha256", "timestampUrl": "", "wix": { - "language": ["en-US"] + "language": ["en-US"], + "template": "assets/main.wxs" } } }