Skip to content
Permalink
Browse files

Use converter, so to make sure never open with minimized state.

  • Loading branch information...
nopara73 committed Nov 12, 2018
1 parent d735740 commit 9758c93dbb0e9cd416a2b5fb7522fdf6a50c2723
Showing with 55 additions and 0 deletions.
  1. +52 −0 WalletWasabi.Gui/Converters/WindowStateAfterSartJsonConverter.cs
  2. +3 −0 WalletWasabi.Gui/UiConfig.cs
@@ -0,0 +1,52 @@
using Avalonia.Controls;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace WalletWasabi.Gui.Converters
{
public class WindowStateAfterSartJsonConverter : JsonConverter
{
/// <inheritdoc />
public override bool CanConvert(Type objectType)
{
return objectType == typeof(WindowState);
}

/// <inheritdoc />
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
try
{
// If minimized, then go with Maximized, because at start it shouldn't run with minimized.
if (reader.Value == null)
{
return WindowState.Maximized;
}

string windowStateString = ((string)reader.Value).Trim();
if (WindowState.Normal.ToString().Equals(windowStateString, StringComparison.OrdinalIgnoreCase)
|| "normal".Equals(windowStateString, StringComparison.OrdinalIgnoreCase)
|| "norm".Equals(windowStateString, StringComparison.OrdinalIgnoreCase))
{
return WindowState.Normal;
}
else
{
return WindowState.Maximized;
}
}
catch
{
return WindowState.Maximized;
}
}

/// <inheritdoc />
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteValue(((WindowState)value).ToString());
}
}
}
@@ -5,8 +5,10 @@
using System.IO;
using System.Text;
using System.Threading.Tasks;
using WalletWasabi.Gui.Converters;
using WalletWasabi.Helpers;
using WalletWasabi.Interfaces;
using WalletWasabi.JsonConverters;

namespace WalletWasabi.Gui
{
@@ -17,6 +19,7 @@ public class UiConfig : IConfig
public string FilePath { get; private set; }

[JsonProperty(PropertyName = "WindowState")]
[JsonConverter(typeof(WindowStateAfterSartJsonConverter))]
public WindowState? WindowState { get; internal set; }

[JsonProperty(PropertyName = "Height")]

0 comments on commit 9758c93

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