Skip to content

Commit 7203d04

Browse files
committed
Init
1 parent 23c58be commit 7203d04

File tree

18 files changed

+441
-344
lines changed

18 files changed

+441
-344
lines changed

.github/NOTICE.md

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -199,35 +199,6 @@ The above copyright notice and this permission notice shall be included in all c
199199
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
200200
```
201201

202-
## INI File Parser
203-
204-
**Source**: [https://github.com/rickyah/ini-parser](https://github.com/rickyah/ini-parser)
205-
206-
### License
207-
208-
```
209-
The MIT License (MIT)
210-
211-
Copyright (c) 2008 Ricardo Amores Hernández
212-
213-
Permission is hereby granted, free of charge, to any person obtaining a copy of
214-
this software and associated documentation files (the "Software"), to deal in
215-
the Software without restriction, including without limitation the rights to
216-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
217-
the Software, and to permit persons to whom the Software is furnished to do so,
218-
subject to the following conditions:
219-
220-
The above copyright notice and this permission notice shall be included in all
221-
copies or substantial portions of the Software.
222-
223-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
224-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
225-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
226-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
227-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
228-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
229-
```
230-
231202
## SevenZipSharp
232203

233204
**Source**: [https://github.com/files-community/SevenZipSharp](https://github.com/files-community/SevenZipSharp)
@@ -645,36 +616,6 @@ A "contributor" is any person that distributes its contribution under this licen
645616
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
646617
```
647618

648-
## WinUIEx
649-
650-
**Source**: [https://github.com/dotMorten/WinUIEx](https://github.com/dotMorten/WinUIEx)
651-
652-
### License
653-
654-
```
655-
MIT License
656-
657-
Copyright (c) 2021 Morten Nielsen
658-
659-
Permission is hereby granted, free of charge, to any person obtaining a copy
660-
of this software and associated documentation files (the "Software"), to deal
661-
in the Software without restriction, including without limitation the rights
662-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
663-
copies of the Software, and to permit persons to whom the Software is
664-
furnished to do so, subject to the following conditions:
665-
666-
The above copyright notice and this permission notice shall be included in all
667-
copies or substantial portions of the Software.
668-
669-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
670-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
671-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
672-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
673-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
674-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
675-
SOFTWARE.
676-
```
677-
678619
## libgit2sharp
679620

680621
**Source**: [https://github.com/libgit2/libgit2sharp](https://github.com/libgit2/libgit2sharp)
@@ -732,4 +673,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
732673
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
733674
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
734675
DEALINGS IN THE SOFTWARE.
735-
```
676+
```

src/Files.App/App.xaml.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Files.App
1818
/// </summary>
1919
public partial class App : Application
2020
{
21-
private static SystemTrayIcon? SystemTrayIcon { get; set; }
21+
public static SystemTrayIcon? SystemTrayIcon { get; private set; }
2222

2323
public static TaskCompletionSource? SplashScreenLoadingTCS { get; private set; }
2424
public static string? OutputPath { get; set; }
@@ -132,14 +132,18 @@ async Task ActivateAsync()
132132
SplashScreenLoadingTCS = null;
133133

134134
// Create a system tray icon
135-
SystemTrayIcon = new SystemTrayIcon().Show();
135+
SystemTrayIcon = new SystemTrayIcon();
136+
if (userSettingsService.GeneralSettingsService.ShowSystemTrayIcon)
137+
SystemTrayIcon.Show();
136138

137139
_ = MainWindow.Instance.InitializeApplicationAsync(appActivationArguments.Data);
138140
}
139141
else
140142
{
141143
// Create a system tray icon
142-
SystemTrayIcon = new SystemTrayIcon().Show();
144+
SystemTrayIcon = new SystemTrayIcon();
145+
if (userSettingsService.GeneralSettingsService.ShowSystemTrayIcon)
146+
SystemTrayIcon.Show();
143147

144148
// Sleep current instance
145149
Program.Pool = new(0, 1, $"Files-{AppLifecycleHelper.AppEnvironment}-Instance");

src/Files.App/Data/Contexts/Window/WindowContext.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ public WindowContext()
2525
IsRunningAsAdmin = WindowsSecurityService.IsAppElevated();
2626
CanDragAndDrop = WindowsSecurityService.CanDragAndDrop();
2727

28-
MainWindow.Instance.PresenterChanged += Window_PresenterChanged;
28+
MainWindow.Instance.AppWindow.Changed += AppWindow_Changed;
2929
}
3030

31-
private void Window_PresenterChanged(object? sender, AppWindowPresenter e)
31+
private void AppWindow_Changed(AppWindow sender, AppWindowChangedEventArgs args)
3232
{
33-
SetProperty(
34-
ref isCompactOverlay,
35-
e.Kind is AppWindowPresenterKind.CompactOverlay,
36-
nameof(IsCompactOverlay));
33+
if (args.DidPresenterChange)
34+
{
35+
SetProperty(
36+
ref isCompactOverlay,
37+
sender.Presenter.Kind is AppWindowPresenterKind.CompactOverlay,
38+
nameof(IsCompactOverlay));
39+
}
3740
}
3841
}
3942
}

src/Files.App/Data/Contracts/IGeneralSettingsService.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,5 +254,25 @@ public interface IGeneralSettingsService : IBaseSettingsService, INotifyProperty
254254
/// Gets or sets a value indicating the default arrangement for Dual Pane.
255255
/// </summary>
256256
ShellPaneArrangement ShellPaneArrangementOption { get; set; }
257+
258+
/// <summary>
259+
/// Gets or sets the min width of <see cref="MainWindow"/>.
260+
/// </summary>
261+
int MainWindowWidth { get; set; }
262+
263+
/// <summary>
264+
/// Gets or sets the min width of <see cref="MainWindow"/>.
265+
/// </summary>
266+
int MainWindowHeight { get; set; }
267+
268+
/// <summary>
269+
/// Gets or sets X position of <see cref="MainWindow"/>.
270+
/// </summary>
271+
int MainWindowPositionX { get; set; }
272+
273+
/// <summary>
274+
/// Gets or sets Y position of <see cref="MainWindow"/>.
275+
/// </summary>
276+
int MainWindowPositionY { get; set; }
257277
}
258278
}

src/Files.App/Data/Items/WindowEx.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
using Microsoft.UI.Windowing;
5+
using Microsoft.UI.Xaml;
6+
using System.Runtime.InteropServices;
7+
using Windows.Win32;
8+
using Windows.Win32.Foundation;
9+
using Windows.Win32.UI.WindowsAndMessaging;
10+
11+
namespace Files.App.Data.Items
12+
{
13+
public unsafe class WindowEx : Window
14+
{
15+
private readonly WNDPROC _oldWndProc;
16+
private readonly WNDPROC _newWndProc;
17+
18+
public nint WindowHandle { get; }
19+
20+
public int MinWidth { get; set; }
21+
public int MinHeight { get; set; }
22+
23+
private bool _IsMaximizable = true;
24+
public bool IsMaximizable
25+
{
26+
get => _IsMaximizable;
27+
set
28+
{
29+
_IsMaximizable = value;
30+
UpdateOverlappedPresenter((c) => c.IsMaximizable = value);
31+
32+
if (value)
33+
{
34+
// NOTE:
35+
// Indicates to the Shell that the window should not be treated as full-screen.
36+
// WORKAROUND:
37+
// https://github.com/microsoft/microsoft-ui-xaml/issues/8431
38+
// Not to mess up the taskbar when being full-screen mode.
39+
// This property should only be set if the "Automatically hide the taskbar" in Windows 11,
40+
// or "Automatically hide the taskbar in desktop mode" in Windows 10 is enabled.
41+
// Setting this property when the setting is disabled will result in the taskbar overlapping the application.
42+
if (AppLifecycleHelper.IsAutoHideTaskbarEnabled())
43+
Win32PInvoke.SetPropW(WindowHandle, "NonRudeHWND", new IntPtr(1));
44+
}
45+
}
46+
}
47+
48+
private bool _IsMinimizable = true;
49+
public bool IsMinimizable
50+
{
51+
get => _IsMinimizable;
52+
set
53+
{
54+
_IsMaximizable = value;
55+
UpdateOverlappedPresenter((c) => c.IsMinimizable = value);
56+
}
57+
}
58+
59+
public unsafe WindowEx(int minWidth = 400, int minHeight = 300)
60+
{
61+
WindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this);
62+
MinWidth = minWidth;
63+
MinHeight = minHeight;
64+
65+
_newWndProc = new(NewWindowProc);
66+
var pNewWndProc = Marshal.GetFunctionPointerForDelegate(_newWndProc);
67+
var pOldWndProc = PInvoke.SetWindowLongPtr(new(WindowHandle), WINDOW_LONG_PTR_INDEX.GWL_WNDPROC, pNewWndProc);
68+
_oldWndProc = Marshal.GetDelegateForFunctionPointer<WNDPROC>(pOldWndProc);
69+
}
70+
71+
private void UpdateOverlappedPresenter(Action<OverlappedPresenter> action)
72+
{
73+
if (AppWindow.Presenter is OverlappedPresenter overlapped)
74+
action(overlapped);
75+
else
76+
throw new NotSupportedException($"'{AppWindow.Presenter.Kind}' presenter is not supported.");
77+
}
78+
79+
private LRESULT NewWindowProc(HWND param0, uint param1, WPARAM param2, LPARAM param3)
80+
{
81+
switch (param1)
82+
{
83+
case 0x0024: /*WM_GETMINMAXINFO*/
84+
{
85+
var dpi = PInvoke.GetDpiForWindow(new(param0));
86+
float scalingFactor = (float)dpi / 96;
87+
88+
var minMaxInfo = Marshal.PtrToStructure<MINMAXINFO>(param3);
89+
minMaxInfo.ptMinTrackSize.X = (int)(MinWidth * scalingFactor);
90+
minMaxInfo.ptMinTrackSize.Y = (int)(MinHeight * scalingFactor);
91+
Marshal.StructureToPtr(minMaxInfo, param3, true);
92+
break;
93+
}
94+
}
95+
96+
return PInvoke.CallWindowProc(_oldWndProc, param0, param1, param2, param3);
97+
}
98+
}
99+
}

src/Files.App/Data/Models/PinnedFoldersManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ public async Task<LocationItem> CreateLocationItemFromPathAsync(string path)
9393
ShowEmptyRecycleBin = string.Equals(path, Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.OrdinalIgnoreCase)
9494
};
9595
locationItem.IsDefaultLocation = false;
96-
locationItem.Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\'));
96+
locationItem.Text = res?.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\'));
9797

9898
if (res)
9999
{
100100
locationItem.IsInvalid = false;
101-
if (res && res.Result is not null)
101+
if (res.Result is not null)
102102
{
103103
var result = await FileThumbnailHelper.GetIconAsync(
104104
res.Result.Path,
@@ -117,7 +117,7 @@ public async Task<LocationItem> CreateLocationItemFromPathAsync(string path)
117117
{
118118
locationItem.Icon = await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() => UIHelpers.GetSidebarIconResource(Constants.ImageRes.Folder));
119119
locationItem.IsInvalid = true;
120-
Debug.WriteLine($"Pinned item was invalid {res.ErrorCode}, item: {path}");
120+
Debug.WriteLine($"Pinned item was invalid {res?.ErrorCode}, item: {path}");
121121
}
122122

123123
return locationItem;

src/Files.App/Files.App.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
8686
<PackageReference Include="TagLibSharp" Version="2.3.0" />
8787
<PackageReference Include="Tulpep.ActiveDirectoryObjectPicker" Version="3.0.11" />
88-
<PackageReference Include="WinUIEx" Version="2.3.4" />
8988
<PackageReference Include="Vanara.Windows.Extensions" Version="4.0.1" />
9089
<PackageReference Include="Vanara.Windows.Shell" Version="4.0.1" />
9190
<PackageReference Include="Microsoft.Management.Infrastructure" Version="3.0.0" />

0 commit comments

Comments
 (0)