Skip to content
Permalink
Browse files

[skip ci] Add sync functions to UiConfig

  • Loading branch information...
nopara73 committed Nov 12, 2018
1 parent 5d98c4f commit a67fc5661eff1f71ce9f28d3c2654a117dfc19fe
Showing with 43 additions and 1 deletion.
  1. +1 −1 WalletWasabi.Gui/Program.cs
  2. +42 −0 WalletWasabi.Gui/UiConfig.cs
@@ -25,7 +25,7 @@ private static async Task Main(string[] args)

var uiConfigFilePath = Path.Combine(Global.DataDir, "UiConfig.json");
var uiConfig = new UiConfig(uiConfigFilePath);
await uiConfig.LoadOrCreateDefaultFileAsync();
uiConfig.LoadOrCreateDefaultFile();
Logger.LogInfo<UiConfig>("UiConfig is successfully initialized.");
Global.InitializeUiConfigs(uiConfig);

@@ -52,6 +52,17 @@ public async Task ToFileAsync()
Encoding.UTF8);
}

/// <inheritdoc />
public void ToFile()
{
AssertFilePathSet();

string jsonString = JsonConvert.SerializeObject(this, Formatting.Indented);
File.WriteAllText(FilePath,
jsonString,
Encoding.UTF8);
}

/// <inheritdoc />
public async Task LoadOrCreateDefaultFileAsync()
{
@@ -73,6 +84,27 @@ public async Task LoadOrCreateDefaultFileAsync()
await ToFileAsync();
}

/// <inheritdoc />
public void LoadOrCreateDefaultFile()
{
AssertFilePathSet();

WindowState = Avalonia.Controls.WindowState.Maximized;
Height = 530;
Width = 1100;

if (!File.Exists(FilePath))
{
Logging.Logger.LogInfo<Config>($"{nameof(Config)} file did not exist. Created at path: `{FilePath}`.");
}
else
{
LoadFile();
}

ToFile();
}

public async Task LoadFileAsync()
{
string jsonString = await File.ReadAllTextAsync(FilePath, Encoding.UTF8);
@@ -83,6 +115,16 @@ public async Task LoadFileAsync()
Width = config.Width ?? Width;
}

public void LoadFile()
{
string jsonString = File.ReadAllText(FilePath, Encoding.UTF8);
var config = JsonConvert.DeserializeObject<UiConfig>(jsonString);

WindowState = config.WindowState ?? WindowState;
Height = config.Height ?? Height;
Width = config.Width ?? Width;
}

/// <inheritdoc />
public async Task<bool> CheckFileChangeAsync()
{

0 comments on commit a67fc56

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