From 8e7d167acefa25e80a015af7e21f611900dfa7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E5=8D=97?= <626058643@qq.com> Date: Thu, 4 Jun 2026 23:32:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=BB=E5=8A=A1=E6=A0=8F?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=20(#3457)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/Cargo.toml | 2 +- src-tauri/src/lib.rs | 18 ++++++++++++++++++ src-tauri/wix/per-user-main.wxs | 9 ++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index bb230c25e..a89dda485 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -89,7 +89,7 @@ webkit2gtk = { version = "2.0.1", features = ["v2_16"] } [target.'cfg(target_os = "windows")'.dependencies] winreg = "0.52" -windows-sys = { version = "0.61", features = ["Win32_Globalization"] } +windows-sys = { version = "0.61", features = ["Win32_Globalization", "Win32_UI_Shell"] } [target.'cfg(target_os = "macos")'.dependencies] objc2 = "0.5" diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 599ed5faa..e1901a532 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -69,6 +69,22 @@ use tauri::RunEvent; use tauri::{Emitter, Manager}; use tauri_plugin_window_state::{AppHandleExt, StateFlags}; +#[cfg(target_os = "windows")] +fn set_windows_app_user_model_id(app: &tauri::AppHandle) { + let app_id = app.config().identifier.clone(); + let wide_app_id: Vec = app_id.encode_utf16().chain(std::iter::once(0)).collect(); + + let result = unsafe { + windows_sys::Win32::UI::Shell::SetCurrentProcessExplicitAppUserModelID(wide_app_id.as_ptr()) + }; + + if result < 0 { + log::warn!("设置 Windows AppUserModelID 失败: 0x{result:08X}"); + } else { + log::debug!("Windows AppUserModelID 已设置为 {app_id}"); + } +} + fn redact_url_for_log(url_str: &str) -> String { match url::Url::parse(url_str) { Ok(url) => { @@ -288,6 +304,8 @@ pub fn run() { // 预先刷新 Store 覆盖配置,确保后续路径读取正确(日志/数据库等) app_store::refresh_app_config_dir_override(app.handle()); panic_hook::init_app_config_dir(crate::config::get_app_config_dir()); + #[cfg(target_os = "windows")] + set_windows_app_user_model_id(app.handle()); // 注册 Updater 插件(桌面端) #[cfg(desktop)] diff --git a/src-tauri/wix/per-user-main.wxs b/src-tauri/wix/per-user-main.wxs index fdf09a3ac..d0a48fbeb 100644 --- a/src-tauri/wix/per-user-main.wxs +++ b/src-tauri/wix/per-user-main.wxs @@ -110,7 +110,14 @@ - + + +