Skip to content

A Swiss Army knife for developers.

Added Mica effect support to WASDK

Etienne Baudoux4d3f8aee6541
diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props
index 5d30b2e8b..842801004 100644
--- a/src/Directory.Packages.props
+++ b/src/Directory.Packages.props
@@ -31,6 +31,7 @@
<PackageVersion Include="Microsoft.UI.Xaml" Version="2.8.1" />
<PackageVersion Include="Microsoft.Web.WebView2" Version="$(WebView2Version)" />
<PackageVersion Include="Microsoft.Windows.Compatibility" Version="$(DotNetVersion)" />
+ <PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.2.188-beta" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="$(MicrosoftWindowsSDKBuildToolsVersion)" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.2.230118.102" />
<PackageVersion Include="Moq" Version="4.18.2" />
diff --git a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/Platform.cs b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/Platform.cs
index 42086a4e7..07cedc750 100644
--- a/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/Platform.cs
+++ b/src/app/dev/DevToys.Api/Tool/Metadata/Attributes/Platform.cs
@@ -3,7 +3,7 @@
public enum Platform
{
Windows,
- MacOS,
+ MacCatalyst,
Linux,
WASM
}
diff --git a/src/app/dev/DevToys.MonacoEditor/CodeEditor/CodeEditorPresenter.MacOS.cs b/src/app/dev/DevToys.MonacoEditor/CodeEditor/CodeEditorPresenter.MacCatalyst.cs
similarity index 100%
rename from src/app/dev/DevToys.MonacoEditor/CodeEditor/CodeEditorPresenter.MacOS.cs
rename to src/app/dev/DevToys.MonacoEditor/CodeEditor/CodeEditorPresenter.MacCatalyst.cs
diff --git a/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs b/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs
index 22b23e551..d19c795e8 100644
--- a/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs
+++ b/src/app/dev/DevToys.Tools/Sample/SampleToolFactory.cs
@@ -13,7 +13,7 @@ namespace DevToys.Tools.Sample;
ResourceManagerBaseName = "DevToys.Tools.Sample.Sample")]
[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
[TargetPlatform(Platform.Linux)]
-[TargetPlatform(Platform.MacOS)]
+[TargetPlatform(Platform.MacCatalyst)]
internal sealed class SampleCommandLineTool : ICommandLineTool
{
[CommandLineOption(
@@ -49,7 +49,7 @@ internal sealed class SampleCommandLineTool : ICommandLineTool
SearchKeywordsResourceName = nameof(Sample.CommandDescription))]
[TargetPlatform(Platform.Windows)] // Optional. Not putting any attribute means every platforms are supported.
[TargetPlatform(Platform.Linux)]
-[TargetPlatform(Platform.MacOS)]
+[TargetPlatform(Platform.MacCatalyst)]
[TargetPlatform(Platform.WASM)]
internal sealed class SampleGuiTool : IGuiTool
{
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/BackdropPage.cs b/src/app/dev/DevToys.UI.Framework/Controls/BackdropPage.cs
new file mode 100644
index 000000000..7c7104e04
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/BackdropPage.cs
@@ -0,0 +1,135 @@
+using Microsoft.UI.Xaml;
+using Microsoft.UI.Xaml.Controls;
+using Windows.Foundation;
+#if HAS_UNO
+using Windows.UI.Core;
+using WindowActivatedEventArgs = Microsoft.UI.Xaml.WindowActivatedEventArgs;
+#endif
+
+namespace DevToys.UI.Framework.Controls;
+
+public abstract class BackdropPage : Page
+{
+ internal BackdropWindow Window { get; }
+
+ /// <summary>
+ /// Gets or sets the position of the window when first shown.
+ /// </summary>
+ public WindowStartupLocation WindowStartupLocation
+ {
+ get => Window.WindowStartupLocation;
+ set => Window.WindowStartupLocation = value;
+ }
+
+ /// <summary>
+ /// Raised when the <see cref="Window.Visible"/> property has changed.
+ /// </summary>
+ public event TypedEventHandler<BackdropWindow, EventArgs>? VisibilityChanged;
+
+ /// <summary>
+ /// Raised when the window opened.
+ /// </summary>
+ public event TypedEventHandler<BackdropWindow, EventArgs>? Shown;
+
+ /// <summary>
+ /// Raised when the window is closing.
+ /// </summary>
+ public event TypedEventHandler<BackdropWindow, EventArgs>? Closing;
+
+ /// <summary>
+ /// Raised when the window got activated.
+ /// </summary>
+ public event TypedEventHandler<BackdropWindow, WindowActivatedEventArgs>? Activated;
+
+ protected BackdropPage(BackdropWindow window)
+ {
+ Guard.IsNotNull(window);
+ Window = window;
+#if HAS_UNO
+ Window.Window.Content = this;
+ Window.Window.Activated += Window_Activated;
+ Window.Window.VisibilityChanged += Window_VisibilityChanged;
+ Window.Window.Closed += Window_Closed;
+#else
+ Window.Content = this;
+ Window.Activated += Window_Activated;
+ Window.VisibilityChanged += Window_VisibilityChanged;
+ Window.Closed += Window_Closed;
+#endif
+ Window.Closing += Window_Closing;
+ Window.Shown += Window_Shown;
+ }
+
+ /// <summary>
+ /// Changes the size of the window.
+ /// </summary>
+ public void Resize(int width, int height)
+ => Window.Resize(width, height);
+
+ /// <summary>
+ /// Changes the window location on the screen.
+ /// </summary>
+ public void Move(int x, int y)
+ => Window.Move(x, y);
+
+ /// <summary>
+ /// Opens a window and returns without waiting for the newly opened window to close.
+ /// </summary>
+ public void Show()
+ => Window.Show();
+
+ /// <summary>
+ /// Attempts to activate the application window by bringing it to the foreground and setting the input focus to it.
+ /// </summary>
+ public void Activate()
+ {
+#if HAS_UNO
+ Window.Window.Activate();
+#else
+ Window.Activate();
+#endif
+ }
+
+#if HAS_UNO
+ private void Window_Closed(object sender, CoreWindowEventArgs args)
+#else
+ private void Window_Closed(object sender, WindowEventArgs args)
+#endif
+ {
+#if HAS_UNO
+ Window.Window.Activated -= Window_Activated;
+ Window.Window.VisibilityChanged -= Window_VisibilityChanged;
+ Window.Window.Closed -= Window_Closed;
+#else
+ Window.Activated -= Window_Activated;
+ Window.VisibilityChanged -= Window_VisibilityChanged;
+ Window.Closed -= Window_Closed;
+#endif
+ Window.Closing -= Window_Closing;
+ Window.Shown -= Window_Shown;
+ }
+
+#if HAS_UNO
+ private void Window_VisibilityChanged(object sender, VisibilityChangedEventArgs args)
+#else
+ private void Window_VisibilityChanged(object sender, WindowVisibilityChangedEventArgs args)
+#endif
+ {
+ VisibilityChanged?.Invoke(Window, EventArgs.Empty);
+ }
+
+ private void Window_Shown(BackdropWindow sender, EventArgs args)
+ {
+ Shown?.Invoke(Window, args);
+ }
+
+ private void Window_Closing(BackdropWindow sender, EventArgs args)
+ {
+ Closing?.Invoke(Window, args);
+ }
+
+ private void Window_Activated(object sender, Microsoft.UI.Xaml.WindowActivatedEventArgs args)
+ {
+ Activated?.Invoke(Window, args);
+ }
+}
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.MacCatalyst.cs b/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.MacCatalyst.cs
new file mode 100644
index 000000000..5ff8125e7
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.MacCatalyst.cs
@@ -0,0 +1,56 @@
+#if __MACCATALYST__
+using Microsoft.UI.Xaml;
+
+namespace DevToys.UI.Framework.Controls;
+
+public sealed partial class BackdropWindow
+{
+ public BackdropWindow(Window window)
+ {
+ Guard.IsNotNull(window);
+ Window = window;
+ }
+
+ internal Window Window { get; }
+
+ public partial void Resize(int width, int height)
+ {
+ throw new NotImplementedException(); // TODO.
+ }
+
+ public partial void Move(int x, int y)
+ {
+ throw new NotImplementedException(); // TODO.
+ }
+
+ public partial void Show()
+ {
+ throw new NotImplementedException(); // TODO.
+
+ Window.Activate();
+ Shown?.Invoke(this, EventArgs.Empty);
+ }
+
+ private void SetStartupWindowLocation()
+ {
+ throw new NotImplementedException(); // TODO
+ switch (WindowStartupLocation)
+ {
+ case WindowStartupLocation.CenterOwner:
+ // TODO
+ throw new NotImplementedException();
+
+ case WindowStartupLocation.CenterScreen:
+ // TODO
+ throw new NotImplementedException();
+
+ case WindowStartupLocation.Manual:
+ // Let the OS decide for us.
+ break;
+
+ default:
+ throw new NotSupportedException();
+ }
+ }
+}
+#endif
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.Wasm.cs b/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.Wasm.cs
new file mode 100644
index 000000000..8a01ddc27
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.Wasm.cs
@@ -0,0 +1,32 @@
+#if __WASM__
+using Microsoft.UI.Xaml;
+
+namespace DevToys.UI.Framework.Controls;
+
+public sealed partial class BackdropWindow
+{
+ public BackdropWindow(Window window)
+ {
+ Guard.IsNotNull(window);
+ Window = window;
+ }
+
+ internal Window Window { get; }
+
+ public partial void Resize(int width, int height)
+ {
+ // Has no effect in WASM.
+ }
+
+ public partial void Move(int x, int y)
+ {
+ // Has no effect in WASM.
+ }
+
+ public partial void Show()
+ {
+ Window.Activate();
+ Shown?.Invoke(this, EventArgs.Empty);
+ }
+}
+#endif
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.Windows.cs b/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.Windows.cs
new file mode 100644
index 000000000..42a1a2f68
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.Windows.cs
@@ -0,0 +1,240 @@
+#if __WINDOWS__
+using System.Runtime.InteropServices;
+using DevToys.UI.Framework.Threading;
+using Microsoft.UI;
+using Microsoft.UI.Composition.SystemBackdrops;
+using Microsoft.UI.Dispatching;
+using Microsoft.UI.Windowing;
+using Microsoft.UI.Xaml;
+using Windows.Graphics;
+using WinRT;
+using WinRT.Interop;
+using Windows.Win32.Graphics.Gdi;
+using Windows.Win32.UI.Shell.Common;
+using static Windows.Win32.PInvoke;
+
+namespace DevToys.UI.Framework.Controls;
+
+public sealed partial class BackdropWindow : Window
+{
+ private readonly WindowsSystemDispatcherQueueHelper _wsdqHelper;
+ private MicaController? _micaController;
+ private SystemBackdropConfiguration? _configurationSource;
+
+ public BackdropWindow()
+ {
+ _wsdqHelper = new WindowsSystemDispatcherQueueHelper();
+ _wsdqHelper.EnsureWindowsSystemDispatcherQueueController();
+
+ AppWindow = GetAppWindow();
+ }
+
+ internal AppWindow AppWindow { get; }
+
+ public partial void Resize(int width, int height)
+ {
+ PointInt32 currentWindowPosition = AppWindow.Position;
+
+ // In WinUI 3, we need to scale the window size to the monitor.
+ // No need to do it for the monitor size and location like in WPF though.
+ HMONITOR monitorHandle = MonitorFromPoint(new System.Drawing.Point(currentWindowPosition.X, currentWindowPosition.Y), MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
+ GetScaleFactorForMonitor(monitorHandle, out DEVICE_SCALE_FACTOR scale);
+ double scaleFactor = (int)scale / 100.0;
+ AppWindow.Resize(new SizeInt32((int)(width * scaleFactor), (int)(height * scaleFactor)));
+ }
+
+ public partial void Move(int x, int y)
+ {
+ PointInt32 position = new(x, y);
+ AppWindow.Move(position);
+ }
+
+ public partial void Show()
+ {
+ DispatcherQueue.ThrowIfNotOnUIThread();
+
+ SetStartupWindowLocation();
+ SetBackdrop();
+
+ AppWindow.Closing += Window_Closing;
+ base.Activate();
+
+ Shown?.Invoke(this, EventArgs.Empty);
+ }
+
+ private AppWindow GetAppWindow()
+ {
+ IntPtr windowHandle = GetWindowHandle();
+ WindowId windowId = Win32Interop.GetWindowIdFromWindow(windowHandle);
+ return AppWindow.GetFromWindowId(windowId);
+ }
+
+ private IntPtr GetWindowHandle()
+ {
+ return WindowNative.GetWindowHandle(this);
+ }
+
+ private void SetStartupWindowLocation()
+ {
+ switch (WindowStartupLocation)
+ {
+ case WindowStartupLocation.CenterOwner:
+ // TODO
+ throw new NotImplementedException();
+
+ case WindowStartupLocation.CenterScreen:
+ var displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest);
+ if (displayArea is not null)
+ {
+ PointInt32 centeredPosition = AppWindow.Position;
+
+ centeredPosition.X = (displayArea.WorkArea.Width - AppWindow.Size.Width) / 2;
+ centeredPosition.Y = (displayArea.WorkArea.Height - AppWindow.Size.Height) / 2;
+ Move(centeredPosition.X, centeredPosition.Y);
+ }
+ break;
+
+ case WindowStartupLocation.Manual:
+ // Let the OS decide for us.
+ break;
+
+ default:
+ throw new NotSupportedException();
+ }
+ }
+
+ private void SetBackdrop()
+ {
+ if (_micaController != null)
+ {
+ _micaController.Dispose();
+ _micaController = null;
+ }
+
+ Activated -= Window_Activated;
+
+ ((FrameworkElement)Content).ActualThemeChanged -= Window_ThemeChanged;
+ _configurationSource = null;
+
+ TrySetMicaBackdrop();
+ }
+
+ private bool TrySetMicaBackdrop()
+ {
+ if (MicaController.IsSupported())
+ {
+ // Hooking up the policy object
+ _configurationSource = new SystemBackdropConfiguration();
+ Activated += Window_Activated;
+ ((FrameworkElement)Content).ActualThemeChanged += Window_ThemeChanged;
+
+ _micaController = new MicaController
+ {
+ Kind = MicaKind.Base
+ };
+
+ // Initial configuration state.
+ _configurationSource.IsInputActive = true;
+ SetConfigurationSourceTheme();
+
+ // Enable the system backdrop.
+ // Note: Be sure to have "using WinRT;" to support the Window.As<...>() call.
+ _micaController.AddSystemBackdropTarget(this.As<Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>());
+ _micaController.SetSystemBackdropConfiguration(_configurationSource);
+ return true; // succeeded
+ }
+
+ return false; // Mica is not supported on this system
+ }
+
+ private void SetConfigurationSourceTheme()
+ {
+ if (_configurationSource is not null)
+ {
+ switch (((FrameworkElement)Content).ActualTheme)
+ {
+ case ElementTheme.Dark:
+ _configurationSource.Theme = SystemBackdropTheme.Dark;
+ break;
+
+ case ElementTheme.Light:
+ _configurationSource.Theme = SystemBackdropTheme.Light;
+ break;
+
+ case ElementTheme.Default:
+ _configurationSource.Theme = SystemBackdropTheme.Default;
+ break;
+ }
+ }
+ }
+
+ private void Window_Activated(object sender, WindowActivatedEventArgs args)
+ {
+ if (_configurationSource is not null)
+ {
+ _configurationSource.IsInputActive = args.WindowActivationState != WindowActivationState.Deactivated;
+ }
+ }
+
+ private void Window_ThemeChanged(FrameworkElement sender, object args)
+ {
+ if (_configurationSource != null)
+ {
+ SetConfigurationSourceTheme();
+ }
+ }
+
+ private void Window_Closing(AppWindow sender, AppWindowClosingEventArgs args)
+ {
+ Closing?.Invoke(this, EventArgs.Empty);
+
+ // Make sure any Mica controller is disposed so it doesn't try to
+ // use this hidden window.
+ if (_micaController != null)
+ {
+ _micaController.Dispose();
+ _micaController = null;
+ }
+
+ AppWindow.Closing -= Window_Closing;
+ Activated -= Window_Activated;
+
+ _configurationSource = null;
+ }
+
+ private class WindowsSystemDispatcherQueueHelper
+ {
+ [StructLayout(LayoutKind.Sequential)]
+ private struct DispatcherQueueOptions
+ {
+ internal int _dwSize;
+ internal int _threadType;
+ internal int _apartmentType;
+ }
+
+ [DllImport("CoreMessaging.dll")]
+ private static extern int CreateDispatcherQueueController([In] DispatcherQueueOptions options, [In, Out, MarshalAs(UnmanagedType.IUnknown)] ref object dispatcherQueueController);
+
+ private object? _dispatcherQueueController = null;
+
+ public void EnsureWindowsSystemDispatcherQueueController()
+ {
+ if (Windows.System.DispatcherQueue.GetForCurrentThread() != null)
+ {
+ // one already exists, so we'll just use it.
+ return;
+ }
+
+ if (_dispatcherQueueController == null)
+ {
+ DispatcherQueueOptions options;
+ options._dwSize = Marshal.SizeOf(typeof(DispatcherQueueOptions));
+ options._threadType = 2; // DQTYPE_THREAD_CURRENT
+ options._apartmentType = 2; // DQTAT_COM_STA
+
+ _ = CreateDispatcherQueueController(options, ref _dispatcherQueueController!);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.cs b/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.cs
new file mode 100644
index 000000000..8ea2de63f
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/BackdropWindow.cs
@@ -0,0 +1,36 @@
+using Windows.Foundation;
+
+namespace DevToys.UI.Framework.Controls;
+
+public sealed partial class BackdropWindow
+{
+ /// <summary>
+ /// Gets or sets the position of the window when first shown.
+ /// </summary>
+ public WindowStartupLocation WindowStartupLocation { get; set; }
+
+ /// <summary>
+ /// Raised when the window opened.
+ /// </summary>
+ public event TypedEventHandler<BackdropWindow, EventArgs>? Shown;
+
+ /// <summary>
+ /// Raised when the window is closing.
+ /// </summary>
+ public event TypedEventHandler<BackdropWindow, EventArgs>? Closing;
+
+ /// <summary>
+ /// Changes the size of the window.
+ /// </summary>
+ public partial void Resize(int width, int height);
+
+ /// <summary>
+ /// Changes the window location on the screen.
+ /// </summary>
+ public partial void Move(int x, int y);
+
+ /// <summary>
+ /// Opens a window and returns without waiting for the newly opened window to close.
+ /// </summary>
+ public partial void Show();
+}
diff --git a/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/DefaultWindowLocation.cs b/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/DefaultWindowLocation.cs
new file mode 100644
index 000000000..e53f1e3d1
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/Controls/BackdropWindow/DefaultWindowLocation.cs
@@ -0,0 +1,22 @@
+namespace DevToys.UI.Framework.Controls;
+
+/// <summary>
+/// Specifies the position that a <see cref="BackdropWindow"/> will be shown in when it is first opened. Used by the <see cref="BackdropWindow.WindowStartupLocation"/> property.
+/// </summary>
+public enum WindowStartupLocation
+{
+ /// <summary>
+ /// The startup location of a <see cref="BackdropWindow"/> is the center of the <see cref="BackdropWindow"/> that owns it.
+ /// </summary>
+ CenterOwner,
+
+ /// <summary>
+ /// The startup location of a <see cref="BackdropWindow"/> is the center of the screen that contains the mouse cursor.
+ /// </summary>
+ CenterScreen,
+
+ /// <summary>
+ /// The startup location of a <see cref="BackdropWindow"/> is set from code, or defers to the default OS location.
+ /// </summary>
+ Manual
+}
diff --git a/src/app/dev/DevToys.UI.Framework/DevToys.UI.Framework.csproj b/src/app/dev/DevToys.UI.Framework/DevToys.UI.Framework.csproj
index f5435c13b..215fc943a 100644
--- a/src/app/dev/DevToys.UI.Framework/DevToys.UI.Framework.csproj
+++ b/src/app/dev/DevToys.UI.Framework/DevToys.UI.Framework.csproj
@@ -60,6 +60,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" />
+ <PackageReference Include="Microsoft.Windows.CsWin32" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
</ItemGroup>
</When>
diff --git a/src/app/dev/DevToys.UI.Framework/NativeMethods.json b/src/app/dev/DevToys.UI.Framework/NativeMethods.json
new file mode 100644
index 000000000..6f2235652
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/NativeMethods.json
@@ -0,0 +1,5 @@
+{
+ "$schema": "https://aka.ms/CsWin32.schema.json",
+ "emitSingleFile": false,
+ "allowMarshaling": false
+}
\ No newline at end of file
diff --git a/src/app/dev/DevToys.UI.Framework/NativeMethods.txt b/src/app/dev/DevToys.UI.Framework/NativeMethods.txt
new file mode 100644
index 000000000..49923e09c
--- /dev/null
+++ b/src/app/dev/DevToys.UI.Framework/NativeMethods.txt
@@ -0,0 +1,2 @@
+MonitorFromPoint
+GetScaleFactorForMonitor
\ No newline at end of file
diff --git a/src/app/dev/DevToys.UI/Views/MainPage.xaml b/src/app/dev/DevToys.UI/Views/MainWindow.xaml
similarity index 90%
rename from src/app/dev/DevToys.UI/Views/MainPage.xaml
rename to src/app/dev/DevToys.UI/Views/MainWindow.xaml
index 9a6567448..2dcad1be3 100644
--- a/src/app/dev/DevToys.UI/Views/MainPage.xaml
+++ b/src/app/dev/DevToys.UI/Views/MainWindow.xaml
@@ -1,16 +1,16 @@
-<Page
- x:Class="DevToys.UI.Views.MainPage"
+<controls:BackdropPage
+ x:Class="DevToys.UI.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:controls="using:DevToys.UI.Framework.Controls"
xmlns:monaco="using:DevToys.MonacoEditor"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:wasm="http://uno.ui/wasm"
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:not_win="http://uno.ui/not_win"
- mc:Ignorable="d wasm not_win"
- NavigationCacheMode="Enabled">
+ mc:Ignorable="d wasm not_win">
<Grid Background="Transparent">
<Grid.BackgroundTransition>
@@ -50,4 +50,4 @@
Grid.Row="2"
Grid.Column="0"/>
</Grid>
-</Page>
+</controls:BackdropPage>
diff --git a/src/app/dev/DevToys.UI/Views/MainPage.xaml.cs b/src/app/dev/DevToys.UI/Views/MainWindow.xaml.cs
similarity index 64%
rename from src/app/dev/DevToys.UI/Views/MainPage.xaml.cs
rename to src/app/dev/DevToys.UI/Views/MainWindow.xaml.cs
index 2bf45ad0e..3c251ccda 100644
--- a/src/app/dev/DevToys.UI/Views/MainPage.xaml.cs
+++ b/src/app/dev/DevToys.UI/Views/MainWindow.xaml.cs
@@ -1,21 +1,22 @@
-using Microsoft.UI.Xaml.Controls;
-
-// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
+using DevToys.UI.Framework.Controls;
namespace DevToys.UI.Views;
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
-public sealed partial class MainPage : Page
+public sealed partial class MainWindow : BackdropPage
{
private const string CompactOverlayStateName = "CompactOverlay";
private const string NavigationViewExpandedStateName = "NavigationViewExpanded";
private const string NavigationViewCompactStateName = "NavigationViewCompact";
private const string NavigationViewMinimalStateName = "NavigationViewMinimal";
- public MainPage()
+ public MainWindow(BackdropWindow backdropWindow)
+ : base(backdropWindow)
{
this.InitializeComponent();
+ this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
+ this.Resize(1200, 800);
}
}
diff --git a/src/app/dev/platforms/desktop/DevToys.CLI/Program.cs b/src/app/dev/platforms/desktop/DevToys.CLI/Program.cs
index 41709d3b6..e1f33d8b1 100644
--- a/src/app/dev/platforms/desktop/DevToys.CLI/Program.cs
+++ b/src/app/dev/platforms/desktop/DevToys.CLI/Program.cs
@@ -110,7 +110,7 @@ internal class Program
Platform currentPlatform;
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
- currentPlatform = Platform.MacOS;
+ currentPlatform = Platform.MacCatalyst;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
diff --git a/src/app/dev/shared/App.xaml.cs b/src/app/dev/shared/App.xaml.cs
index a18fcd27c..48b33e52a 100644
--- a/src/app/dev/shared/App.xaml.cs
+++ b/src/app/dev/shared/App.xaml.cs
@@ -3,15 +3,13 @@ using DevToys.Api.Core.Threading;
using DevToys.Core.Mef;
using DevToys.Core.Settings;
using DevToys.UI;
+using DevToys.UI.Framework.Controls;
using DevToys.UI.Views;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml;
-using Microsoft.UI.Xaml.Controls;
-using Microsoft.UI.Xaml.Navigation;
using Uno.Extensions;
using Uno.Logging;
using Windows.ApplicationModel;
-using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Core;
using LaunchActivatedEventArgs = Microsoft.UI.Xaml.LaunchActivatedEventArgs;
using UnhandledExceptionEventArgs = Microsoft.UI.Xaml.UnhandledExceptionEventArgs;
@@ -29,7 +27,7 @@ public sealed partial class App : Application
private readonly Task<IMefProvider> _mefProvider;
private readonly AsyncLazy<ISettingsProvider> _settingsProvider;
- private Window? _window;
+ private MainWindow? _mainWindow;
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
@@ -76,68 +74,33 @@ public sealed partial class App : Application
?? LanguageManager.Instance.AvailableLanguages[0];
LanguageManager.Instance.SetCurrentCulture(languageDefinition);
-#if NET6_0_OR_GREATER && WINDOWS && !HAS_UNO
- _window = new Window();
- _window.Activate();
+#if __WINDOWS__
+ // On Windows 10 version 1607 or later, this code signals that this app wants to participate in prelaunch
+ CoreApplication.EnablePrelaunch(true);
+#endif
+
+#if __WINDOWS__
+ _mainWindow = new MainWindow(new BackdropWindow());
+ _mainWindow.Show();
#elif __MACCATALYST__
// Important! Keep the full name `Microsoft.UI.Xaml.Window.Current` otherwise the Mac app won't build.
// See https://blog.mzikmund.com/2020/04/resolving-uno-platform-uiwindow-does-not-contain-a-definition-for-current-issue/
- _window = Microsoft.UI.Xaml.Window.Current;
+ _mainWindow = new MainWindow(new BackdropWindow(Microsoft.UI.Xaml.Window.Current));
#else
- _window = Window.Current;
+ _mainWindow = new MainWindow(new BackdropWindow(Window.Current));
#endif
Windows.ApplicationModel.Activation.LaunchActivatedEventArgs uwpArgs = args.UWPLaunchActivatedEventArgs;
- // Do not repeat app initialization when the Window already has content,
- // just ensure that the window is active
- if (_window.Content is not Frame rootFrame)
- {
- // Create a Frame to act as the navigation context and navigate to the first page
- rootFrame = new Frame();
-
- rootFrame.NavigationFailed += OnNavigationFailed;
-
- if (uwpArgs.PreviousExecutionState == ApplicationExecutionState.Terminated)
- {
- // TODO: Load state from previously suspended application
- }
-
- // Place the frame in the current Window
- _window.Content = rootFrame;
- }
-
-#if __WINDOWS__
- // On Windows 10 version 1607 or later, this code signals that this app wants to participate in prelaunch
- CoreApplication.EnablePrelaunch(true);
-#endif
-
#if !(NET6_0_OR_GREATER && WINDOWS)
if (uwpArgs.PrelaunchActivated == false)
#endif
{
- if (rootFrame.Content == null)
- {
- // When the navigation stack isn't restored navigate to the first page,
- // configuring the new page by passing required information as a navigation
- // parameter
- rootFrame.Navigate(typeof(MainPage), args.Arguments);
- }
// Ensure the current window is active
- _window.Activate();
+ _mainWindow.Activate();
}
}
- /// <summary>
- /// Invoked when Navigation to a certain page fails
- /// </summary>
- /// <param name="sender">The Frame which failed navigation</param>
- /// <param name="e">Details about the navigation failure</param>
- private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
- {
- throw new InvalidOperationException($"Failed to load {e.SourcePageType.FullName}: {e.Exception}");
- }
-
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
diff --git a/src/build/Build.cs b/src/build/Build.cs
index 01390f84a..1c36ec388 100644
--- a/src/build/Build.cs
+++ b/src/build/Build.cs
@@ -62,7 +62,7 @@ class Build : NukeBuild
return;
}
- if (PlatformTargets.Contains(PlatformTarget.MacOS) && !OperatingSystem.IsMacOS())
+ if (PlatformTargets.Contains(PlatformTarget.MacCatalyst) && !OperatingSystem.IsMacOS())
{
Assert.Fail("To build macOS app, you need to run on macOS Ventura 13.1 or later.");
return;
@@ -166,7 +166,7 @@ class Build : NukeBuild
}
}
- if (PlatformTargets!.Contains(PlatformTarget.MacOS))
+ if (PlatformTargets!.Contains(PlatformTarget.MacCatalyst))
{
// DevToys Uno Mac Catalyst and MAUI Blazor
Project[] projects = {
diff --git a/src/build/PlatformTarget.cs b/src/build/PlatformTarget.cs
index 0ddd0cc4e..26d83fe7d 100644
--- a/src/build/PlatformTarget.cs
+++ b/src/build/PlatformTarget.cs
@@ -1,7 +1,7 @@
enum PlatformTarget
{
Windows,
- MacOS,
+ MacCatalyst,
CLI,
Wasm
}