Skip to content

Commit 8e7d167

Browse files
修复任务栏图标 (#3457)
1 parent dadefde commit 8e7d167

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ webkit2gtk = { version = "2.0.1", features = ["v2_16"] }
8989

9090
[target.'cfg(target_os = "windows")'.dependencies]
9191
winreg = "0.52"
92-
windows-sys = { version = "0.61", features = ["Win32_Globalization"] }
92+
windows-sys = { version = "0.61", features = ["Win32_Globalization", "Win32_UI_Shell"] }
9393

9494
[target.'cfg(target_os = "macos")'.dependencies]
9595
objc2 = "0.5"

src-tauri/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ use tauri::RunEvent;
6969
use tauri::{Emitter, Manager};
7070
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
7171

72+
#[cfg(target_os = "windows")]
73+
fn set_windows_app_user_model_id(app: &tauri::AppHandle) {
74+
let app_id = app.config().identifier.clone();
75+
let wide_app_id: Vec<u16> = app_id.encode_utf16().chain(std::iter::once(0)).collect();
76+
77+
let result = unsafe {
78+
windows_sys::Win32::UI::Shell::SetCurrentProcessExplicitAppUserModelID(wide_app_id.as_ptr())
79+
};
80+
81+
if result < 0 {
82+
log::warn!("设置 Windows AppUserModelID 失败: 0x{result:08X}");
83+
} else {
84+
log::debug!("Windows AppUserModelID 已设置为 {app_id}");
85+
}
86+
}
87+
7288
fn redact_url_for_log(url_str: &str) -> String {
7389
match url::Url::parse(url_str) {
7490
Ok(url) => {
@@ -288,6 +304,8 @@ pub fn run() {
288304
// 预先刷新 Store 覆盖配置,确保后续路径读取正确(日志/数据库等)
289305
app_store::refresh_app_config_dir_override(app.handle());
290306
panic_hook::init_app_config_dir(crate::config::get_app_config_dir());
307+
#[cfg(target_os = "windows")]
308+
set_windows_app_user_model_id(app.handle());
291309

292310
// 注册 Updater 插件(桌面端)
293311
#[cfg(desktop)]

src-tauri/wix/per-user-main.wxs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@
110110
<Directory Id="TARGETDIR" Name="SourceDir">
111111
<Directory Id="DesktopFolder" Name="Desktop">
112112
<Component Id="ApplicationShortcutDesktop" Guid="*">
113-
<Shortcut Id="ApplicationDesktopShortcut" Name="{{product_name}}" Description="Runs {{product_name}}" Target="[!Path]" WorkingDirectory="INSTALLDIR" />
113+
<Shortcut Id="ApplicationDesktopShortcut"
114+
Name="{{product_name}}"
115+
Description="Runs {{product_name}}"
116+
Target="[!Path]"
117+
Icon="ProductIcon"
118+
WorkingDirectory="INSTALLDIR">
119+
<ShortcutProperty Key="System.AppUserModel.ID" Value="{{bundle_id}}"/>
120+
</Shortcut>
114121
<RemoveFolder Id="DesktopFolder" On="uninstall" />
115122
<RegistryValue Root="HKCU" Key="Software\\{{manufacturer}}\\{{product_name}}" Name="Desktop Shortcut" Type="integer" Value="1" KeyPath="yes" />
116123
</Component>

0 commit comments

Comments
 (0)