fix(native): correct PKEY_AppUserModel_ID import (D6 CI build)
Build Lotus Chat Desktop / prepare (push) Successful in 9s
Build Lotus Chat Desktop / build-linux (push) Successful in 25m18s
Build Lotus Chat Desktop / build-windows (push) Successful in 29m40s
Build Lotus Chat Desktop / update-manifest (push) Successful in 4s

Windows CI failed: PROPERTYKEY is not in Win32::UI::Shell::PropertiesSystem.
Use the ready-made PKEY_AppUserModel_ID constant from Win32::Storage::Enhanced
Storage (same module jumplist.rs uses for PKEY_Title, feature already enabled)
instead of hand-rolling the PROPERTYKEY — drops the GUID::from_u128 dependency.
Also simplify IPersistFile::Save's fremember arg (it's bool, not BOOL).

All windows-crate symbols now verified against windows-docs-rs (PKEY_AppUser
Model_ID / IPersistFile::Save / SetCurrentProcessExplicitAppUserModelID /
CreateToastNotifierWithId).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 10:54:14 -04:00
parent e65c5771e8
commit 8479d6e768
+9 -13
View File
@@ -24,14 +24,18 @@ pub const APP_USER_MODEL_ID: &str = "LotusGuild.LotusChat";
#[cfg(target_os = "windows")]
pub fn ensure_app_user_model_id(_app: &AppHandle) {
use std::os::windows::ffi::OsStrExt;
use windows::core::{Interface, GUID, HSTRING, PCWSTR};
use windows::core::{Interface, HSTRING, PCWSTR};
// PKEY_AppUserModel_ID lives in EnhancedStorage (same module as jumplist's
// PKEY_Title), NOT PropertiesSystem — use the ready-made constant rather than
// hand-rolling the PROPERTYKEY.
use windows::Win32::Storage::EnhancedStorage::PKEY_AppUserModel_ID;
use windows::Win32::System::Com::{
CoCreateInstance, CoInitializeEx, CoUninitialize, IPersistFile,
StructuredStorage::PROPVARIANT, CLSCTX_INPROC_SERVER, COINIT_APARTMENTTHREADED,
};
use windows::Win32::UI::Shell::{
PropertiesSystem::{IPropertyStore, PROPERTYKEY},
IShellLinkW, SetCurrentProcessExplicitAppUserModelID, ShellLink,
PropertiesSystem::IPropertyStore, IShellLinkW, SetCurrentProcessExplicitAppUserModelID,
ShellLink,
};
// 1. Advertise the AUMID for this process (must happen before any toast fires).
@@ -68,13 +72,6 @@ pub fn ensure_app_user_model_id(_app: &AppHandle) {
.chain(std::iter::once(0))
.collect();
// PKEY_AppUserModel_ID = {9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}, pid 5.
// Constructed inline so we don't depend on the const's crate module path.
const PKEY_APP_USER_MODEL_ID: PROPERTYKEY = PROPERTYKEY {
fmtid: GUID::from_u128(0x9F4C2855_9F79_4B39_A8D0_E1D42DE1D5F3),
pid: 5,
};
// STA apartment for the shell link objects, mirroring jumplist.rs. All COM
// interfaces are dropped before CoUninitialize.
let hr = unsafe { CoInitializeEx(None, COINIT_APARTMENTTHREADED) };
@@ -88,13 +85,12 @@ pub fn ensure_app_user_model_id(_app: &AppHandle) {
// like PKEY_Title in jumplist.rs).
let store: IPropertyStore = link.cast()?;
let value = PROPVARIANT::from(APP_USER_MODEL_ID);
store.SetValue(&PKEY_APP_USER_MODEL_ID, &value)?;
store.SetValue(&PKEY_AppUserModel_ID, &value)?;
store.Commit()?;
// Persist the .lnk to the Start-Menu Programs folder.
let persist: IPersistFile = link.cast()?;
// fremember is a Win32 BOOL (not bool); `.into()` uses From<bool>.
persist.Save(PCWSTR(lnk_wide.as_ptr()), true.into())?;
persist.Save(PCWSTR(lnk_wide.as_ptr()), true)?;
Ok(())
}
})();