最大化设置持久化 (#365)

This commit is contained in:
Poker 2024-03-08 21:39:52 +08:00 committed by GitHub
parent d701cfa906
commit f644064274
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 4 deletions

View File

@ -50,7 +50,7 @@ public static class WindowFactory
if (element.XamlRoot is null)
ThrowHelper.ArgumentNull(element.XamlRoot, $"{nameof(element.XamlRoot)} should not be null.");
return _forkedWindowsInternal.Find(window => element.XamlRoot == window.Content.XamlRoot)
return _forkedWindowsInternal.Find(window => element.XamlRoot == window.Content.XamlRoot)
?? ThrowHelper.ArgumentOutOfRange<UIElement, EnhancedWindow>(element, $"Specified {nameof(element)} is not existed in any of {nameof(ForkedWindows)}.");
}
@ -95,7 +95,7 @@ public static class WindowFactory
return window;
}
public static EnhancedWindow Init(this EnhancedWindow window, string title, SizeInt32 size = default)
public static EnhancedWindow Init(this EnhancedWindow window, string title, SizeInt32 size = default, bool isMaximized = false)
{
window.Initialize(new InitializeInfo
{
@ -105,6 +105,8 @@ public static class WindowFactory
IconPath = IconAbsolutePath,
Title = title
});
if (isMaximized)
window.AppWindow.Presenter.To<OverlappedPresenter>().Maximize();
window.FrameLoaded += (s, _) => s.To<FrameworkElement>().RequestedTheme = WindowSettings.Theme;
return window;
}

View File

@ -91,7 +91,7 @@ public partial class App
.WithLoaded((s, _) => s.To<Frame>().NavigateTo<LoginPage>(w))
.WithClosing((_, _) => AppInfo.SaveContext()) // TODO: 从运行打开应用的时候不会ExitApp就算是调用App.Current.Exit();
.WithSizeLimit(800, 360)
.Init(AppInfo.AppIdentifier, AppViewModel.AppSettings.WindowSize.ToSizeInt32())
.Init(AppInfo.AppIdentifier, AppViewModel.AppSettings.WindowSize.ToSizeInt32(), AppViewModel.AppSettings.IsMaximized)
.Activate();
RegisterUnhandledExceptionHandler();

View File

@ -200,7 +200,13 @@ public static partial class AppInfo
public static void SaveContext()
{
// Save the current resolution
App.AppViewModel.AppSettings.WindowSize = WindowFactory.RootWindow.AppWindow.Size.ToSize();
if (WindowFactory.RootWindow.AppWindow.Presenter is OverlappedPresenter { State: OverlappedPresenterState.Maximized })
App.AppViewModel.AppSettings.IsMaximized = true;
else
{
App.AppViewModel.AppSettings.IsMaximized = false;
App.AppViewModel.AppSettings.WindowSize = WindowFactory.RootWindow.AppWindow.Size.ToSize();
}
if (!App.AppViewModel.SignOutExit)
{
if (App.AppViewModel.MakoClient != null!)

View File

@ -248,6 +248,10 @@ public partial record AppSettings : IWindowSettings
[SyntheticSetting]
public Size WindowSize { get; set; } = WindowHelper.EstimatedWindowSize().ToSize();
[AttributeIgnore(typeof(SettingsViewModelAttribute<>))]
[SyntheticSetting]
public bool IsMaximized { get; set; } = false;
public MakoClientConfiguration ToMakoClientConfiguration()
{
return new MakoClientConfiguration(5000, !DisableDomainFronting, MirrorHost, CultureInfo.CurrentUICulture);