Skip to content

Commit 4b77f98

Browse files
committed
Remember window size
Fixes #488
1 parent b931b3e commit 4b77f98

File tree

6 files changed

+94
-13
lines changed

6 files changed

+94
-13
lines changed

SimpleDnsCrypt/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@
9292
<setting name="ForwardingRulesFile" serializeAs="String">
9393
<value />
9494
</setting>
95+
<setting name="WindowWidth" serializeAs="String">
96+
<value>825</value>
97+
</setting>
98+
<setting name="WindowHeight" serializeAs="String">
99+
<value>875</value>
100+
</setting>
95101
</SimpleDnsCrypt.Properties.Settings>
96102
</userSettings>
97103
</configuration>

SimpleDnsCrypt/Properties/Settings.Designer.cs

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SimpleDnsCrypt/Properties/Settings.settings

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,11 @@
6868
<Setting Name="ForwardingRulesFile" Type="System.String" Scope="User">
6969
<Value Profile="(Default)" />
7070
</Setting>
71+
<Setting Name="WindowWidth" Type="System.Int32" Scope="User">
72+
<Value Profile="(Default)">825</Value>
73+
</Setting>
74+
<Setting Name="WindowHeight" Type="System.Int32" Scope="User">
75+
<Value Profile="(Default)">875</Value>
76+
</Setting>
7177
</Settings>
7278
</SettingsFile>

SimpleDnsCrypt/ViewModels/AboutViewModel.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,14 @@ namespace SimpleDnsCrypt.ViewModels
1616
[Export(typeof(AboutViewModel))]
1717
public class AboutViewModel : Screen
1818
{
19-
private readonly IWindowManager _windowManager;
20-
private readonly IEventAggregator _events;
2119
private string _windowTitle;
2220

2321
private BindableCollection<License> _licenses;
2422
private License _selectedLicense;
2523

26-
public AboutViewModel()
27-
{
28-
}
29-
3024
[ImportingConstructor]
31-
public AboutViewModel(IWindowManager windowManager, IEventAggregator events)
25+
public AboutViewModel()
3226
{
33-
_windowManager = windowManager;
34-
_events = events;
35-
_events.Subscribe(this);
3627
AddLicenses();
3728
SelectedLicense = _licenses[0];
3829
}

SimpleDnsCrypt/ViewModels/MainViewModel.cs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public class MainViewModel : Screen, INotifyDataErrorInfo
6060
private bool _isSavingConfiguration;
6161
private bool _isUninstallingService;
6262
private bool _isWorkingOnService;
63+
private int _windowWidth;
64+
private int _windowHeight;
6365

6466
private ObservableCollection<Language> _languages;
6567

@@ -85,6 +87,8 @@ public MainViewModel(IWindowManager windowManager, IEventAggregator events)
8587
_windowManager = windowManager;
8688
_events = events;
8789
_events.Subscribe(this);
90+
_windowWidth = Properties.Settings.Default.WindowWidth;
91+
_windowHeight= Properties.Settings.Default.WindowHeight;
8892
_windowTitle =
8993
$"{Global.ApplicationName} {VersionHelper.PublishVersion} {VersionHelper.PublishBuild} [dnscrypt-proxy {DnsCryptProxyManager.GetVersion()}]";
9094
SelectedTab = Tabs.MainTab;
@@ -95,6 +99,7 @@ public MainViewModel(IWindowManager windowManager, IEventAggregator events)
9599
{
96100
WindowTitle = LocalizationEx.GetUiString("settings", Thread.CurrentThread.CurrentCulture)
97101
};
102+
98103
_settingsViewModel.PropertyChanged += SettingsViewModelOnPropertyChanged;
99104
_listenAddressesViewModel = new ListenAddressesViewModel();
100105
_fallbackResolversViewModel = new FallbackResolversViewModel();
@@ -390,6 +395,26 @@ public BindableCollection<AvailableResolver> Resolvers
390395
}
391396
}
392397

398+
/// <summary>
399+
/// Closing the main window.
400+
/// </summary>
401+
/// <param name="cancelEventArgs"></param>
402+
public void OnClose(CancelEventArgs cancelEventArgs)
403+
{
404+
try
405+
{
406+
Properties.Settings.Default.WindowWidth = WindowWidth;
407+
Properties.Settings.Default.WindowHeight = WindowHeight;
408+
Properties.Settings.Default.Save();
409+
}
410+
catch (Exception exception)
411+
{
412+
Log.Error(exception);
413+
}
414+
}
415+
416+
417+
393418
/// <summary>
394419
/// The title of the window.
395420
/// </summary>
@@ -403,6 +428,32 @@ public string WindowTitle
403428
}
404429
}
405430

431+
/// <summary>
432+
/// The width of the main window.
433+
/// </summary>
434+
public int WindowWidth
435+
{
436+
get => _windowWidth;
437+
set
438+
{
439+
_windowWidth = value;
440+
NotifyOfPropertyChange(() => WindowWidth);
441+
}
442+
}
443+
444+
/// <summary>
445+
/// The height of the main window.
446+
/// </summary>
447+
public int WindowHeight
448+
{
449+
get => _windowHeight;
450+
set
451+
{
452+
_windowHeight = value;
453+
NotifyOfPropertyChange(() => WindowHeight);
454+
}
455+
}
456+
406457
/// <summary>
407458
/// Show or hide the filtered network cards.
408459
/// </summary>
@@ -609,7 +660,7 @@ public void TabControl_SelectionChanged(SelectionChangedEventArgs selectionChang
609660

610661
public void About()
611662
{
612-
var win = new AboutViewModel(_windowManager, _events)
663+
var win = new AboutViewModel()
613664
{
614665
WindowTitle = LocalizationEx.GetUiString("about", Thread.CurrentThread.CurrentCulture)
615666
};

SimpleDnsCrypt/Windows/BaseWindow.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
xmlns:cal="http://www.caliburnproject.org"
77
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
88
xmlns:converters="clr-namespace:SimpleDnsCrypt.Converters"
9-
Title="{Binding WindowTitle}" MinWidth="810" Width="825" MinHeight="360"
9+
cal:Message.Attach="[Event Closing] = [Action OnClose($eventArgs)]"
10+
Title="{Binding WindowTitle}" MinWidth="810" MinHeight="360"
11+
Width="{Binding WindowWidth, Mode=TwoWay}"
12+
Height="{Binding WindowHeight, Mode=TwoWay}"
1013
SizeToContent="WidthAndHeight"
1114
GlowBrush="{DynamicResource AccentColorBrush}"
1215
Icon="../Images/simplednscrypt.ico" ShowIconOnTitleBar="False"

0 commit comments

Comments
 (0)