fix(native): correct PKEY_AppUserModel_ID import (D6 CI build)
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:
@@ -24,14 +24,18 @@ pub const APP_USER_MODEL_ID: &str = "LotusGuild.LotusChat";
|
|||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub fn ensure_app_user_model_id(_app: &AppHandle) {
|
pub fn ensure_app_user_model_id(_app: &AppHandle) {
|
||||||
use std::os::windows::ffi::OsStrExt;
|
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::{
|
use windows::Win32::System::Com::{
|
||||||
CoCreateInstance, CoInitializeEx, CoUninitialize, IPersistFile,
|
CoCreateInstance, CoInitializeEx, CoUninitialize, IPersistFile,
|
||||||
StructuredStorage::PROPVARIANT, CLSCTX_INPROC_SERVER, COINIT_APARTMENTTHREADED,
|
StructuredStorage::PROPVARIANT, CLSCTX_INPROC_SERVER, COINIT_APARTMENTTHREADED,
|
||||||
};
|
};
|
||||||
use windows::Win32::UI::Shell::{
|
use windows::Win32::UI::Shell::{
|
||||||
PropertiesSystem::{IPropertyStore, PROPERTYKEY},
|
PropertiesSystem::IPropertyStore, IShellLinkW, SetCurrentProcessExplicitAppUserModelID,
|
||||||
IShellLinkW, SetCurrentProcessExplicitAppUserModelID, ShellLink,
|
ShellLink,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 1. Advertise the AUMID for this process (must happen before any toast fires).
|
// 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))
|
.chain(std::iter::once(0))
|
||||||
.collect();
|
.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
|
// STA apartment for the shell link objects, mirroring jumplist.rs. All COM
|
||||||
// interfaces are dropped before CoUninitialize.
|
// interfaces are dropped before CoUninitialize.
|
||||||
let hr = unsafe { CoInitializeEx(None, COINIT_APARTMENTTHREADED) };
|
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).
|
// like PKEY_Title in jumplist.rs).
|
||||||
let store: IPropertyStore = link.cast()?;
|
let store: IPropertyStore = link.cast()?;
|
||||||
let value = PROPVARIANT::from(APP_USER_MODEL_ID);
|
let value = PROPVARIANT::from(APP_USER_MODEL_ID);
|
||||||
store.SetValue(&PKEY_APP_USER_MODEL_ID, &value)?;
|
store.SetValue(&PKEY_AppUserModel_ID, &value)?;
|
||||||
store.Commit()?;
|
store.Commit()?;
|
||||||
|
|
||||||
// Persist the .lnk to the Start-Menu Programs folder.
|
// Persist the .lnk to the Start-Menu Programs folder.
|
||||||
let persist: IPersistFile = link.cast()?;
|
let persist: IPersistFile = link.cast()?;
|
||||||
// fremember is a Win32 BOOL (not bool); `.into()` uses From<bool>.
|
persist.Save(PCWSTR(lnk_wide.as_ptr()), true)?;
|
||||||
persist.Save(PCWSTR(lnk_wide.as_ptr()), true.into())?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user