From afd5ec3f094fcb299d1d7c7f4bc552cb4accc8df Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Wed, 18 Nov 2026 18:18:07 +0800 Subject: [PATCH] fix(windows): register the notification shortcut identity --- packaging/windows/README.md | 5 +++ packaging/windows/machine-install.ps1 | 53 +++++++++++++++++++++++++++ scripts/test-windows-installer.ps1 | 7 +++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/packaging/windows/README.md b/packaging/windows/README.md index 519a0d3..f96b1a4 100644 --- a/packaging/windows/README.md +++ b/packaging/windows/README.md @@ -59,6 +59,11 @@ from the Start menu after completion. User configuration and licensing state are retained during upgrades and uninstall. Authenticode setup is separate; WinSparkle must still verify the installer payload signature before handoff. +The Start menu shortcut registers `System.AppUserModel.ID` as `com.yuezk.gpgui`, +matching the GUI and native toast sender. Windows uses the shortcut's name and +executable icon to identify GP Connect in Notification Center. Its identity is +part of the shortcut, so the existing shortcut rollback and uninstall own its cleanup. + Manual launches show an Install/Cancel confirmation page (Update/Cancel when GP Connect is already installed). The update feed supplies `/UPDATE` through WinSparkle's `sparkle:installerArguments` to skip that page after the user has diff --git a/packaging/windows/machine-install.ps1 b/packaging/windows/machine-install.ps1 index cee5a99..2e2ba32 100644 --- a/packaging/windows/machine-install.ps1 +++ b/packaging/windows/machine-install.ps1 @@ -144,6 +144,58 @@ function Set-MachineState { } finally { $registry.Dispose() } } +function Set-ShortcutAppUserModelId([string]$Path, [string]$ApplicationId) { + if (-not ('GPConnect.Installer.ShortcutIdentity' -as [type])) { + Add-Type @' +using System; +using System.Runtime.InteropServices; + +namespace GPConnect.Installer { + public static class ShortcutIdentity { + [StructLayout(LayoutKind.Sequential)] + private struct PropertyKey { public Guid Format; public uint Id; } + + // PROPVARIANT is 24 bytes in both supported 64-bit architectures. + [StructLayout(LayoutKind.Explicit, Size = 24)] + private struct PropVariant { + [FieldOffset(0)] public ushort Type; + [FieldOffset(8)] public IntPtr Value; + } + + [ComImport, Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + private interface IPropertyStore { + void GetCount(out uint count); + void GetAt(uint index, out PropertyKey key); + void GetValue(ref PropertyKey key, out PropVariant value); + void SetValue(ref PropertyKey key, ref PropVariant value); + void Commit(); + } + + [DllImport("shell32.dll", CharSet = CharSet.Unicode, PreserveSig = false)] + private static extern void SHGetPropertyStoreFromParsingName( + string path, IntPtr context, uint flags, ref Guid iid, out IPropertyStore store); + + public static void Set(string path, string applicationId) { + var iid = typeof(IPropertyStore).GUID; + IPropertyStore store; + SHGetPropertyStoreFromParsingName(path, IntPtr.Zero, 2, ref iid, out store); // GPS_READWRITE + var value = new PropVariant { Type = 31, Value = Marshal.StringToCoTaskMemUni(applicationId) }; // VT_LPWSTR + try { + var key = new PropertyKey { Format = new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), Id = 5 }; + store.SetValue(ref key, ref value); // PKEY_AppUserModel_ID + store.Commit(); + } finally { + Marshal.FreeCoTaskMem(value.Value); + Marshal.ReleaseComObject(store); + } + } + } +} +'@ + } + [GPConnect.Installer.ShortcutIdentity]::Set($Path, $ApplicationId) +} + function Set-InstallationMetadata([string]$InstalledVersion) { $shell = New-Object -ComObject WScript.Shell $shortcut = $shell.CreateShortcut($shortcutPath) @@ -152,6 +204,7 @@ function Set-InstallationMetadata([string]$InstalledVersion) { $shortcut.Description = 'A GUI client for GlobalProtect VPN' $shortcut.IconLocation = (Join-Path $destination 'gpgui.exe') + ',0' $shortcut.Save() + Set-ShortcutAppUserModelId $shortcutPath 'com.yuezk.gpgui' if (Test-Path -LiteralPath (Join-Path $destination 'uninstall.exe')) { New-Item -Path $uninstallKey -Force | Out-Null $values = @{ diff --git a/scripts/test-windows-installer.ps1 b/scripts/test-windows-installer.ps1 index c50f7fd..60f1955 100644 --- a/scripts/test-windows-installer.ps1 +++ b/scripts/test-windows-installer.ps1 @@ -24,6 +24,12 @@ $service = Get-CimInstance Win32_Service -Filter "Name='GPConnect'" if ($service.State -ne 'Running' -or $service.StartMode -ne 'Auto' -or $service.StartName -ne 'LocalSystem') { throw 'The service did not start automatically as LocalSystem.' } +$shortcut = Join-Path $env:ProgramData 'Microsoft\Windows\Start Menu\Programs\GP Connect.lnk' +$shell = New-Object -ComObject Shell.Application +$link = $shell.Namespace((Split-Path $shortcut)).ParseName((Split-Path $shortcut -Leaf)) +if (!$link -or $link.ExtendedProperty('System.AppUserModel.ID') -ne 'com.yuezk.gpgui') { + throw 'The Start menu shortcut does not register the notification application identity.' +} foreach ($name in @('gpgui.exe', 'gpauth.exe')) { $process = Start-Process (Join-Path $destination $name) -ArgumentList '--version' -PassThru -Wait if ($process.ExitCode -ne 0) { throw "The installed $name cannot start." } @@ -44,7 +50,6 @@ if ($process.ExitCode -ne 0) { throw 'The uninstaller failed.' } if ((Get-Service GPConnect -ErrorAction SilentlyContinue) -or (Test-Path $destination) -or (Test-Path ($destination + '.previous'))) { throw 'The uninstaller left service registration or runtime files.' } -$shortcut = Join-Path $env:ProgramData 'Microsoft\Windows\Start Menu\Programs\GP Connect.lnk' if ((Test-Path $shortcut) -or (Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\GPConnect')) { throw 'The uninstaller left its shortcut or registration.' }