microsoft / microsoft/WindowsAppSDK

Clicking a notification from Shell_NotifyIcon opens a second instance of a packaged app

Open
#6,031 1 comment 0 reactions 0 assignees View on GitHub
area-Shell UX needs-triage
Dominant language
C++
Stars
4.7k
Forks
471
Avg merge
3d 13h
Merged PRs (30d)
28

Description

### Describe the bug

When clicking a notification that a MSIX-packaged app creates, it opens a second instance instead of behaving like unpackaged apps and bringing the app window in the foreground.

### Steps to reproduce the bug

1. Create a new C++ WinUI 3 app
2. Add the following to `MainWindow.xaml.h`:
```cpp
void InitializeComponent();
void Button_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);

private:
NOTIFYICONDATA m_icon;
```
3. Add the following to `MainWindow.xaml`:
```xaml

Send notification

```
4. Add the following to `MainWindow.xaml.cpp`:
```cpp
void winrt::App4::implementation::MainWindow::InitializeComponent()
{
MainWindowT::InitializeComponent();

HWND window{};
winrt::check_hresult(m_inner.as()->get_WindowHandle(&window));

m_icon = {
.cbSize = sizeof(m_icon),
.hWnd = window,
.uID = 45678908,
.uFlags = NIF_MESSAGE | NIF_TIP | NIF_SHOWTIP | NIF_ICON,
.uCallbackMessage = 0xbeef,
.hIcon = ExtractIcon(nullptr, L"shell32.dll", 130),
.szTip = L"test_app",
.uVersion = NOTIFYICON_VERSION_4
};

Shell_NotifyIcon(NIM_ADD, &m_icon);
Shell_NotifyIcon(NIM_SETVERSION, &m_icon);
}

void winrt::App4::implementation::MainWindow::Button_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
{
auto icon = m_icon;
icon.uFlags |= NIF_INFO;
icon.dwInfoFlags = NIIF_INFO;
wcscpy_s(icon.szInfo, L"test_app");
wcscpy_s(icon.szInfoTitle, L"test_app");

BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon);
}
```
5. Edit the project file for unpackaged and launch the app unpackaged
6. Click button and click notification. Observe no second instance is created.
7. Edit the project file for packaged and launch the app pckaged.
8. Click button and click notification. Observe a second instance of the app is created.

### Expected behavior

No second instance is created, even when the app is packaged. This was the behavior previously as well

### Screenshots

_No response_

### NuGet package version

Windows App SDK 1.8.3: 1.8.251106002

### Packaging type

Packaged (MSIX)

### Windows version

Insider Build (xxxxx)

### IDE

Visual Studio 2022

### Additional context

Windows 11 26200.7296

Full repro project here:
https://github.com/sylveon/ShellNotifyIcon-packaged

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked ShellNotifyIcon-packaged repro and compare the packaged and unpackaged runs using MainWindow.xaml.h, MainWindow.xaml, and MainWindow.xaml.cpp. Reproduce the notification click behavior under Windows App SDK 1.8.3, then trace the relevant packaged-app activation path. Done means clicking the Shell_NotifyIcon notification brings the existing window forward without creating a second instance.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.