Skip to content

Commit 070fa38

Browse files
committed
Update to WinAppSDK 2.0, refactor tray icon, and docs
- Upgraded to Microsoft.WindowsAppSDK 2.0.x and related packages - Introduced NotifyIconXamlHostWindow for tray icon management - Refactored NotifyIconContextMenu to Flyout, removed icon logic - Updated App.xaml.cpp to use new tray icon host window - Added WindowHelper::ShowMainWindow for window activation - Added protocol, file association, and toast activation to manifests - Added stub modules CapturedException.ixx and ExceptionHandling.ixx - Updated README with platform, tech stack, and credits - Minor IDL formatting and consistency improvements
1 parent ea910fe commit 070fa38

22 files changed

Lines changed: 655 additions & 374 deletions

OpenNet/App.xaml.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "pch.h"
22
#include "App.xaml.h"
33
#include "MainWindow.xaml.h"
4-
#include "UI/Shell/NotifyIconContextMenu.xaml.h"
4+
#include "UI/Shell/NotifyIconXamlHostWindow.xaml.h"
55
#include "UI/Xaml/View/Dialog/CloseToTrayDialog.h"
66
#include "Helpers/WindowHelper.h"
77
#include "Helpers/ThemeHelper.h"
@@ -266,7 +266,7 @@ namespace winrt::OpenNet::implementation
266266
::OpenNet::Helpers::ThemeHelper::UpdateThemeForWindow(window);
267267

268268
// Create and show system tray icon (assign to static member, not a local)
269-
trayIcon = OpenNet::UI::Shell::NotifyIconContextMenu();
269+
trayIcon = OpenNet::UI::Shell::NotifyIconXamlHostWindow();
270270
trayIcon.Show();
271271

272272
// Register window closing event - close strategy (hide to tray / ask / exit)

OpenNet/App.xaml.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace winrt::OpenNet::implementation
1818
static void HandleActivation(winrt::Microsoft::Windows::AppLifecycle::AppActivationArguments const&);
1919

2020
static inline winrt::Microsoft::UI::Xaml::Window window{ nullptr };
21-
static inline winrt::OpenNet::UI::Shell::NotifyIconContextMenu trayIcon{ nullptr };
21+
static inline winrt::OpenNet::UI::Shell::NotifyIconXamlHostWindow trayIcon{ nullptr };
2222
// Set to true before calling Application::Exit() so the Closing handler
2323
// does not cancel the close and hide the window to tray.
2424
static inline bool s_isExiting{ false };

OpenNet/Core/AppRuntime.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ namespace OpenNet::Core
1515

1616
winrt::hstring AppRuntime::GetDisplayName()
1717
{
18+
#ifdef _DEBUG
19+
return L"OpenNet Dev";
20+
#else
1821
return L"OpenNet";
22+
#endif // _DEBUG
23+
1924
}
2025

2126
winrt::hstring AppRuntime::InitializeDeviceId()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export module CapturedException;
2+
3+
export void MyFunc();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export module ExceptionHandling;
2+
3+
export void MyFunc();

OpenNet/Helpers/WindowHelper.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@ namespace OpenNet::Helpers::WinUIWindowHelper
117117
}
118118
}
119119

120+
void WindowHelper::ShowMainWindow()
121+
{
122+
auto& window = winrt::OpenNet::implementation::App::window;
123+
if (window)
124+
{
125+
window.AppWindow().Show();
126+
127+
HWND hwnd = ::OpenNet::Helpers::WinUIWindowHelper::WindowHelper::GetWindowHandleFromWindow(window);
128+
if (hwnd)
129+
{
130+
if (IsIconic(hwnd))
131+
{
132+
ShowWindow(hwnd, SW_RESTORE);
133+
}
134+
SetForegroundWindow(hwnd);
135+
SetFocus(hwnd);
136+
}
137+
}
138+
}
139+
120140
void WindowHelper::SetWindowMinSize(Window const& window, double const& width, double const& height)
121141
{
122142
auto windowContent = window.Content().try_as<FrameworkElement>();

OpenNet/Helpers/WindowHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ namespace OpenNet::Helpers::WinUIWindowHelper
7878
static std::vector<winrt::Microsoft::UI::Xaml::Window> const& ActiveWindows();
7979
static winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Storage::StorageFolder>
8080
GetAppLocalFolderAsync();
81+
static void ShowMainWindow();
8182
private:
8283
static inline std::vector<winrt::Microsoft::UI::Xaml::Window> m_activeWindows;
8384
};

OpenNet/OpenNet.vcxproj

Lines changed: 91 additions & 56 deletions
Large diffs are not rendered by default.

OpenNet/OpenNet.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
<Page Include="UI\Xaml\View\Pages\SettingsPages\FontCustomizePage.xaml" />
123123
<Page Include="UI\Xaml\View\Windows\ExceptionWindow.xaml" />
124124
<Page Include="UI\Xaml\View\InfoBarView.xaml" />
125+
<Page Include="UI\Shell\NotifyIconXamlHostWindow.xaml" />
125126
</ItemGroup>
126127
<ItemGroup>
127128
<Midl Include="MainWindow.idl" />
@@ -433,6 +434,8 @@
433434
</ClCompile>
434435
<ClCompile Include="Core\AppRuntime.cpp" />
435436
<ClCompile Include="Web\WebView2\WebView2Version.cpp" />
437+
<ClCompile Include="Core\ExceptionService\ExceptionHandling.ixx" />
438+
<ClCompile Include="Core\ExceptionService\CapturedException.ixx" />
436439
</ItemGroup>
437440
<ItemGroup>
438441
<ClInclude Include="pch.h" />

OpenNet/Package.Dev.appxmanifest

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
<Package
44
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
5+
xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10"
6+
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
57
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
68
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
79
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
@@ -49,6 +51,31 @@
4951
<uap:Rotation Preference="landscapeFlipped"/>
5052
<uap:Rotation Preference="portraitFlipped"/></uap:InitialRotationPreference>
5153
</uap:VisualElements>
54+
<Extensions>
55+
<desktop:Extension Category="windows.toastNotificationActivation">
56+
<desktop:ToastNotificationActivation ToastActivatorCLSID="3C5E5C23-405B-45E9-97B6-F1105EED59F6"/>
57+
</desktop:Extension>
58+
<com:Extension Category="windows.comServer">
59+
<com:ComServer>
60+
<com:ExeServer Executable="OpenNet.exe" Arguments="----AppNotificationActivated:" DisplayName="OpenNet Toast Activator">
61+
<com:Class Id="3C5E5C23-405B-45E9-97B6-F1105EED59F6" DisplayName="OpenNet Toast Activator"/>
62+
</com:ExeServer>
63+
</com:ComServer>
64+
</com:Extension>
65+
<uap:Extension Category="windows.protocol">
66+
<uap:Protocol Name="opennet">
67+
<uap:DisplayName>OpenNet Dev</uap:DisplayName>
68+
</uap:Protocol>
69+
</uap:Extension>
70+
<uap:Extension Category="windows.fileTypeAssociation">
71+
<uap:FileTypeAssociation Name="torrent">
72+
<uap:SupportedFileTypes>
73+
<uap:FileType ContentType="application/x-bittorrent">.torrent</uap:FileType>
74+
</uap:SupportedFileTypes>
75+
<uap:DisplayName>OpenNet Dev - a bittorrnt client</uap:DisplayName>
76+
</uap:FileTypeAssociation>
77+
</uap:Extension>
78+
</Extensions>
5279
</Application>
5380
</Applications>
5481

0 commit comments

Comments
 (0)