Skip to content
Permalink
Browse files

Only apply UI remembring for Windows and OSX

  • Loading branch information...
nopara73 committed Nov 12, 2018
1 parent 9758c93 commit 4d85ab52a72848fcb779027929b4eeef628b7b42
@@ -74,18 +74,12 @@ public static string TorLogsFile
public static TorProcessManager TorManager { get; private set; }

public static Config Config { get; private set; }
public static UiConfig UiConfig { get; private set; }

public static void InitializeConfig(Config config)
{
Config = Guard.NotNull(nameof(config), config);
}

public static void InitializeUiConfig(UiConfig uiConfig)
{
UiConfig = Guard.NotNull(nameof(uiConfig), uiConfig);
}

private static long _triedDesperateDequeuing = 0;

private static async Task TryDesperateDequeueAllCoinsAsync()
@@ -4,6 +4,7 @@
using System.Linq;
using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using AvalonStudio.Extensibility;
@@ -17,6 +18,8 @@ namespace WalletWasabi.Gui
{
public class MainWindow : MetroWindow
{
public UiConfig UiConfig { get; private set; }

public MainWindow()
{
InitializeComponent();
@@ -37,33 +40,51 @@ public MainWindow()
private void InitializeComponent()
{
Activated += OnActivated;
Initialized += MainWindow_Initialized;
Closing += MainWindow_ClosingAsync;
AvaloniaXamlLoader.Load(this);
}

private async void MainWindow_ClosingAsync(object sender, CancelEventArgs e)
#pragma warning disable IDE1006 // Naming Styles

private async void MainWindow_Initialized(object sender, EventArgs e)
#pragma warning restore IDE1006 // Naming Styles
{
UiConfig conf = Global.UiConfig;
conf.WindowState = WindowState;
conf.Width = Width;
conf.Height = Height;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
var uiConfigFilePath = Path.Combine(Global.DataDir, "UiConfig.json");
var uiConfig = new UiConfig(uiConfigFilePath);
await uiConfig.LoadOrCreateDefaultFileAsync();
Logging.Logger.LogInfo<UiConfig>("UiConfig is successfully initialized.");
UiConfig = uiConfig;

await conf.ToFileAsync();
MainWindowViewModel.Instance.Width = (double)uiConfig.Width;
MainWindowViewModel.Instance.Height = (double)uiConfig.Height;
MainWindowViewModel.Instance.WindowState = (WindowState)uiConfig.WindowState;
}
else
{
MainWindowViewModel.Instance.WindowState = WindowState.Maximized;
}
}

#pragma warning disable IDE1006 // Naming Styles
private async void MainWindow_ClosingAsync(object sender, CancelEventArgs e)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
UiConfig.WindowState = WindowState;
UiConfig.Width = Width;
UiConfig.Height = Height;

private async void OnActivated(object sender, EventArgs e)
#pragma warning restore IDE1006 // Naming Styles
await UiConfig.ToFileAsync();
Logging.Logger.LogInfo<UiConfig>("UiConfig is saved.");
}
}

private void OnActivated(object sender, EventArgs e)
{
Activated -= OnActivated;
DisplayWalletManager();
var uiConfigFilePath = Path.Combine(Global.DataDir, "UiConfig.json");
var uiConfig = new UiConfig(uiConfigFilePath);
await uiConfig.LoadOrCreateDefaultFileAsync();
Logging.Logger.LogInfo<UiConfig>("UiConfig is successfully initialized.");
Global.InitializeUiConfig(uiConfig);
MainWindowViewModel.Instance.RefreshUiFromConfig(Global.UiConfig);
}

private void DisplayWalletManager()
@@ -49,12 +49,6 @@ private static async Task Main(string[] args)

MainWindowViewModel.Instance.StatusBar = statusBar;

//UiConfig conf = Global.UiConfig;
//MainWindowViewModel.Instance..WindowState = (Avalonia.Controls.WindowState)conf.WindowState;
//MainWindowViewModel.Instance.Width = (double)conf.Width;
//MainWindowViewModel.Instance.Height = (double)conf.Height;
//MainWindowViewModel.Instance.Position = new Point((double)conf.Left, (double)conf.Top);

if (Global.IndexDownloader.Network != Network.Main)
{
MainWindowViewModel.Instance.Title += $" - {Global.IndexDownloader.Network}";
@@ -88,12 +88,5 @@ public bool CanClose
get { return _canClose; }
set { this.RaiseAndSetIfChanged(ref _canClose, value); }
}

public void RefreshUiFromConfig(UiConfig config)
{
Width = (double)config.Width;
Height = (double)config.Height;
WindowState = (WindowState)config.WindowState;
}
}
}

0 comments on commit 4d85ab5

Please sign in to comment.
You can’t perform that action at this time.