feat: persist window location between launches

This commit is contained in:
Anna 2021-02-06 14:58:34 -05:00
parent 16a00a704e
commit 787bf93dbd
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
4 changed files with 16 additions and 0 deletions

View File

@ -11,6 +11,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using WpfWindowPlacement;
using XIVChatCommon.Message; using XIVChatCommon.Message;
using XIVChatCommon.Message.Server; using XIVChatCommon.Message.Server;
@ -46,6 +47,8 @@ namespace XIVChat_Desktop {
public ObservableCollection<Notification> Notifications { get; set; } = new ObservableCollection<Notification>(); public ObservableCollection<Notification> Notifications { get; set; } = new ObservableCollection<Notification>();
public WindowPlacement WindowPlacement { get; set; }
#region io #region io
private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings { private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings {

View File

@ -19,6 +19,8 @@
AllowsTransparency="True" AllowsTransparency="True"
Opacity="{Binding App.Config.Opacity}" Opacity="{Binding App.Config.Opacity}"
Icon="/Resources/logo.ico" Icon="/Resources/logo.ico"
SourceInitialized="MainWindow_OnSourceInitialized"
Closing="MainWindow_OnClosing"
d:DataContext="{d:DesignInstance local:MainWindow}"> d:DataContext="{d:DesignInstance local:MainWindow}">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>

View File

@ -8,6 +8,7 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using WpfWindowPlacement;
using XIVChatCommon.Message; using XIVChatCommon.Message;
using XIVChatCommon.Message.Server; using XIVChatCommon.Message.Server;
@ -403,5 +404,14 @@ namespace XIVChat_Desktop {
channel.ContextMenu!.PlacementTarget = channel; channel.ContextMenu!.PlacementTarget = channel;
channel.ContextMenu!.IsOpen = true; channel.ContextMenu!.IsOpen = true;
} }
private void MainWindow_OnSourceInitialized(object? sender, EventArgs e) {
this.SetPlacement(this.App.Config.WindowPlacement);
}
private void MainWindow_OnClosing(object sender, CancelEventArgs e) {
this.App.Config.WindowPlacement = this.GetPlacement();
this.App.Config.Save();
}
} }
} }

View File

@ -66,6 +66,7 @@
<PackageReference Include="Sentry" Version="3.0.3" /> <PackageReference Include="Sentry" Version="3.0.3" />
<PackageReference Include="Sodium.Core" Version="1.2.3" /> <PackageReference Include="Sodium.Core" Version="1.2.3" />
<PackageReference Include="System.Drawing.Common" Version="5.0.0" /> <PackageReference Include="System.Drawing.Common" Version="5.0.0" />
<PackageReference Include="WpfWindowPlacement" Version="3.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>