Migrating to Windows App SDK (WinUI 3)
BestOwl opened this issue · 1 comments
TL;DR
We are planning to refactor and migrate from UWP to Windows App SDK desktop app
Current Architecture
Currently, the main UI is a UWP app, which causes some trouble to implement the messaging feature.
Project | Type | Description |
---|---|---|
MyPhone.TrayApp.XamlHost | C++ UWP Project | XAML island host |
MyPhone.TrayApp | C++ Win32 Project | Main app logic, system tray UI and UWP "broker". Enable the UWP app to call Win32 APIs and keeping the app running in the background. Use XAML island to make the system tray UI has the same look and feel as native UWP system apps. This project handles main app logic including Bluetooth HFP stuff. |
MyPhone | C# UWP Project | Main app UI |
PackageProject | Desktop Bridge Packaging Project | Generate MSIX app package |
Problem: UWP background restriction.
In order to receive message notification from MCE (mobile phone), the MNS server needs to keep running in the background and keep connected to the MCE. Being a UWP app makes it "impossible" to do that because a UWP app cannot run in the background for a long time. A common method to bypass this restriction is to put the server in a Win32 broker process (like MyPhone.TrayApp) so that it can run in the background indefinitely, and then pass the message content to the UWP UI. But passing a huge amount of data between two processes may cause both development overhead and runtime performance overhead because you need to handle Inter-Process Communication (IPC).
Why we chose UWP?
We want to use the WinUI library to match the look and feel with the system. Back to the time when this project was started, there are only two ways to use WinUI.
- UWP
- XAML Island (Attach UWP UI in a Win32 process)
Although we can use XAML Island at that time, some important dev tools are missing (such as XAML hot reload, XAML designer, etc.). Thus UWP was the primary choice.
New Architecture
With the release of Windows App SDK 1.0, the use of UWP has become meaningless.
- The primary use case of this app is to use it on a desktop or laptop PC. Who would try to use this app on a Windows Phone to make phone calls via another phone's cellular network?
- Being a desktop app simplifies everything. No need to use "broker" anymore; no complicated IPC handling. We can keep everything in one single process.
Therefore, we are planning to migrate this project from UWP to Windows App SDK.
Project | Type | Description |
---|---|---|
MyPhone | C# Windows App SDK Project | Main UI, tray icon, background server, and everything else, all in one process |
PackageProject | Desktop Bridge Packaging Project | Generate MSIX app package |
During the migration, I will also refactor view models using MVVM toolkit