Skip to content

Commit 3353540

Browse files
authored
Code Quality: Potential fix for NullReferenceException in App.OnLaunched (#16072)
1 parent 0654d5d commit 3353540

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace Files.App.Data.Items
1919
/// </summary>
2020
public unsafe class WindowEx : Window
2121
{
22+
private bool _isInitialized;
2223
private readonly WNDPROC _oldWndProc;
2324
private readonly WNDPROC _newWndProc;
2425

@@ -98,8 +99,6 @@ public unsafe WindowEx(int minWidth = 400, int minHeight = 300)
9899
IsMaximizable = true;
99100
IsMinimizable = true;
100101

101-
RestoreWindowPlacementData();
102-
103102
_newWndProc = new(NewWindowProc);
104103
var pNewWndProc = Marshal.GetFunctionPointerForDelegate(_newWndProc);
105104
var pOldWndProc = PInvoke.SetWindowLongPtr(new(WindowHandle), WINDOW_LONG_PTR_INDEX.GWL_WNDPROC, pNewWndProc);
@@ -267,6 +266,12 @@ private LRESULT NewWindowProc(HWND param0, uint param1, WPARAM param2, LPARAM pa
267266
{
268267
switch (param1)
269268
{
269+
case 0x0018 /*WM_SHOWWINDOW*/ when param2 == (WPARAM)1 && !_isInitialized:
270+
{
271+
_isInitialized = true;
272+
RestoreWindowPlacementData();
273+
break;
274+
}
270275
case 0x0024: /*WM_GETMINMAXINFO*/
271276
{
272277
var dpi = PInvoke.GetDpiForWindow(new(param0));

0 commit comments

Comments
 (0)