Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Quality: Bring back WinUIEx #16227

Merged
merged 7 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Files.App/Files.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
<PackageReference Include="TagLibSharp" Version="2.3.0" />
<PackageReference Include="Tulpep.ActiveDirectoryObjectPicker" Version="3.0.11" />
<PackageReference Include="WinUIEx" Version="2.3.4" />
<PackageReference Include="Vanara.Windows.Extensions" Version="4.0.1" />
<PackageReference Include="Vanara.Windows.Shell" Version="4.0.1" />
<PackageReference Include="Microsoft.Management.Infrastructure" Version="3.0.0" />
Expand Down
3 changes: 2 additions & 1 deletion src/Files.App/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<!-- Copyright (c) 2024 Files Community. Licensed under the MIT License. See the LICENSE. -->
<items:WindowEx
<winuiex:WindowEx
x:Class="Files.App.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:items="using:Files.App.Data.Items"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:winuiex="using:WinUIEx"
mc:Ignorable="d" />
17 changes: 12 additions & 5 deletions src/Files.App/MainWindow.xaml.cs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0x5bfa I think we need to add back the persistence id.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omg I missed that, let me make a PR for it shortly.

Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,30 @@

namespace Files.App
{
public sealed partial class MainWindow : WindowEx
public sealed partial class MainWindow : WinUIEx.WindowEx
{
private static MainWindow? _Instance;
public static MainWindow Instance => _Instance ??= new();

public MainWindow() : base(minWidth: 516, minHeight: 416)
public nint WindowHandle { get; }

public MainWindow()
{
InitializeComponent();

WindowHandle = WinUIEx.WindowExtensions.GetWindowHandle(this);
MinHeight = 416;
MinWidth = 516;
ExtendsContentIntoTitleBar = true;
Title = "Files";
AppWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
AppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
AppWindow.TitleBar.ButtonPressedBackgroundColor = Colors.Transparent;
AppWindow.TitleBar.ButtonHoverBackgroundColor = Colors.Transparent;
AppWindow.SetIcon(AppLifecycleHelper.AppIconPath);

if (AppLifecycleHelper.IsAutoHideTaskbarEnabled())
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
Win32PInvoke.SetPropW(WindowHandle, "NonRudeHWND", new IntPtr(1));
}

public void ShowSplashScreen()
Expand Down Expand Up @@ -188,9 +196,8 @@ public async Task InitializeApplicationAsync(object activatedEventArgs)
Win32Helper.BringToForegroundEx(new(WindowHandle));
}

if (Windows.Win32.PInvoke.IsIconic(new(WindowHandle)) &&
AppWindow.Presenter is OverlappedPresenter presenter)
presenter.Restore(); // Restore window if minimized
if (Windows.Win32.PInvoke.IsIconic(new(WindowHandle)))
WinUIEx.WindowExtensions.Restore(Instance); // Restore window if minimized
}

private Frame? EnsureWindowIsInitialized()
Expand Down
8 changes: 5 additions & 3 deletions src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static nint GetWindowHandle(Window w)
=> WinRT.Interop.WindowNative.GetWindowHandle(w);

private static TaskCompletionSource? PropertiesWindowsClosingTCS;
private static readonly BlockingCollection<WindowEx> WindowCache = [];
private static readonly BlockingCollection<WinUIEx.WindowEx> WindowCache = [];
yaira2 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Open properties window
Expand Down Expand Up @@ -103,13 +103,15 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan

if (!WindowCache.TryTake(out var propertiesWindow))
{
propertiesWindow = new(460, 550);
propertiesWindow = new();
propertiesWindow.Closed += PropertiesWindow_Closed;
}

var width = Convert.ToInt32(800 * App.AppModel.AppWindowDPI);
var height = Convert.ToInt32(500 * App.AppModel.AppWindowDPI);

propertiesWindow.MinWidth = 460;
propertiesWindow.MinHeight = 550;
propertiesWindow.AppWindow.Resize(new (width, height));
propertiesWindow.IsMinimizable = false;
propertiesWindow.IsMaximizable = false;
Expand Down Expand Up @@ -158,7 +160,7 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan
// So instead of destroying the Window object, cache it and reuse it as a workaround.
private static void PropertiesWindow_Closed(object sender, WindowEventArgs args)
{
if (!App.AppModel.IsMainWindowClosed && sender is WindowEx window)
if (!App.AppModel.IsMainWindowClosed && sender is WinUIEx.WindowEx window)
{
args.Handled = true;

Expand Down