File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ webkit2gtk = { version = "2.0.1", features = ["v2_16"] }
8989
9090[target .'cfg(target_os = "windows")' .dependencies ]
9191winreg = " 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 ]
9595objc2 = " 0.5"
Original file line number Diff line number Diff line change @@ -69,6 +69,22 @@ use tauri::RunEvent;
6969use tauri:: { Emitter , Manager } ;
7070use 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+
7288fn 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) ]
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments