Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Remember the main window's place only while it is on screen

KnifeLemon0c05c538c3eb
diff --git a/src/Filee.App/Services/WindowService.cs b/src/Filee.App/Services/WindowService.cs
index 9548a42c..1259d8ed 100644
--- a/src/Filee.App/Services/WindowService.cs
+++ b/src/Filee.App/Services/WindowService.cs
@@ -43,7 +43,12 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services, Mem
if (page is null)
model.Navigate(placement.Page);
}
- main.Closing += (_, _) => _mainPlacement = MainWindowPlacement.Of(main, model, _mainPlacement);
+ main.Closing += (_, _) =>
+ {
+ // While it is still on screen: the release closes it hidden, when its position may no longer be known.
+ if (main.IsVisible)
+ _mainPlacement = MainWindowPlacement.Of(main, model, _mainPlacement);
+ };
main.Closed += (_, _) =>
{
if (_main == main)
diff --git a/tests/Filee.App.Tests/MainWindowReleaseTests.cs b/tests/Filee.App.Tests/MainWindowReleaseTests.cs
index 51126fab..3c56e99e 100644
--- a/tests/Filee.App.Tests/MainWindowReleaseTests.cs
+++ b/tests/Filee.App.Tests/MainWindowReleaseTests.cs
@@ -36,8 +36,8 @@ public class MainWindowReleaseTests
var second = windows.Main!;
Assert.True(second.IsVisible);
Assert.Equal("watch", ((MainWindowViewModel)second.DataContext!).SelectedItem.Key);
- Assert.Equal(new PixelPoint(140, 90), second.Position);
Assert.Equal(new Size(900, 640), second.ClientSize);
+ Assert.Equal(new PixelPoint(140, 90), second.Position);
// Nothing holds the closed window, its view model or its page any more.
for (var i = 0; i < 3; i++)
@@ -50,27 +50,15 @@ public class MainWindowReleaseTests
Assert.False(model.TryGetTarget(out _), "view model");
Assert.False(page.TryGetTarget(out _), "page");
+ // Shown again before the posted release ran (e.g. the tray's Open right after closing): it stays open.
+ // In this test, not one of its own: the window service is shared, and tests may run while another pumps.
second.Close();
- Pump();
- Assert.Null(windows.Main);
- }
-
- [AvaloniaFact]
- public void A_window_shown_again_before_it_was_released_stays_open()
- {
- TestServices.EnsureInitialized("en");
- var windows = AppHost.Get<WindowService>();
windows.ShowMain();
Pump();
- var main = windows.Main!;
-
- main.Close();
- windows.ShowMain(); // e.g. the tray's Open, handled before the posted release
- Pump();
- Assert.Same(main, windows.Main);
- Assert.True(main.IsVisible);
+ Assert.Same(second, windows.Main);
+ Assert.True(second.IsVisible);
- main.Close();
+ second.Close();
Pump();
Assert.Null(windows.Main);
}
@@ -86,6 +74,7 @@ public class MainWindowReleaseTests
main.Width = 900;
main.Height = 640;
Pump();
+ Assert.Equal(new PixelPoint(140, 90), main.Position);
var model = (MainWindowViewModel)main.DataContext!;
var page = model.CurrentPage;