The system tray icon will register repeatedly if the app is updated (because the exe path changes due to the version field in the path)
Describe the bug
The system tray icon will register repeatedly if the app is updated (because the exe path changes due to the version field in the path). Also the registered icon registry content will not get cleaned up after uninstall. Because there is no standard msix packaged way to do such a thing, which all things are managed by the system msix installer. Even if you keep the icon's GUID is the same, the icon information's exe path is different because it contains version information, which is like 'C:\Program Files\WindowsApps\E8B6E2B3-D2A0-4435-A81D-2A16AAF405C8_1.19.0.0_x64__k3erpsn8bwzzy' . And I also think you should note that the GUID is also shouldn't use Path calculation, because the program directory installed in the Windows App directory is mandatory to include version information.
Steps to reproduce the bug
register: https://github.com/SnapHutaoRemasteringProject/Snap.Hutao.Remastered.Native/blob/c2592b2f4361f392337224db853263dfb03b249f/src/Snap.Hutao.Remastered.Native/HutaoNativeRegistryNotification.cpp#L98-L172 usage: https://github.com/SnapHutaoRemasteringProject/Snap.Hutao.Remastered/blob/410d900f4ddf6e7738ee2c3d0cc8fa483e6b2741/src/Snap.Hutao.Remastered/Snap.Hutao.Remastered/UI/Shell/NotifyIconController.cs#L56-L98
Expected behavior
You'll find many the same content in the registry and settings. This causes the inconsistently behavior of the icon.
Screenshots
NuGet package version
1.8.260317003
Packaging type
Packaged (MSIX)
Windows version
Insider Build (xxxxx)
IDE
No response
Additional context
No response
Is your Issue there's no Windows or WinAppSDK API to register an MSIX-savvy System Tray Icon.
This is an enhancement request for such an API?
As a poor workaround you could define your packaged app with windows.appExecutionAlias and specify that for the ExecutablePath in the registry i.e. bar.exe, not c:\foo\bar.exe. I don't know if the System Tray Icon plumbing requires checks for absolute filename and will fail if not.
More importantly, I say poor because activation should find the alias but registered as a relative filename potentially leaves the door open to mischief and security attacks. An MSIX-aware way to register a System Tray Icon is better e.g.
<Package>
<Applications>
<Application....>
<Extensions>
<Extension Category="windows.systemTrayIcon">
...
Thank you for your answer!
Is your Issue there's no Windows or WinAppSDK API to register an MSIX-savvy System Tray Icon. This is an enhancement request for such an API?
My answer is yes for this question. And I'm prety sure that the system tray icon register will check the absolute exe path inner and make the ExecutablePath (some are absolute paths, I'm not prety sure...), which I can't control it trough standard API and will cause inconsistent behavior with different version of msix packaged app path such as "Hidden icon menu setting" and icon's relative position with other tray icons. So that the appExecutionAlias that you mentioned will not work.
But update the registry iconsetting's ExecutablePath after software update's first run did resolve the problem. https://github.com/SnapHutaoRemasteringProject/Snap.Hutao.Remastered/blob/84b15edf59787785435cae791aea5286fc344a0a/src/Snap.Hutao.Remastered/Snap.Hutao.Remastered/UI/Shell/NotifyIconController.cs#L219-L319
If there is a enhancement of such an API is great.
Found a reference here: https://learn.microsoft.com/windows/win32/api/shellapi/ns-shellapi-notifyicondataa#troubleshooting
its been more than fucking 5 years and this is still not fixed.