Skip to content

Commit 7927a95

Browse files
committed
feat: enhance titleBarOverlay to accept both a boolean and an object
1 parent 758e6a4 commit 7927a95

4 files changed

Lines changed: 61 additions & 2 deletions

File tree

src/ElectronNET.API/API/Entities/BrowserWindowOptions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
using ElectronNET.Converter;
2+
using Newtonsoft.Json;
23
using Newtonsoft.Json.Converters;
34
using System.ComponentModel;
45

@@ -219,7 +220,8 @@ public class BrowserWindowOptions
219220
/// When using a frameless window this can be used to indicate if the
220221
/// standard control buttons should be shown. Default is false.
221222
/// </summary>
222-
public bool TitleBarOverlay { get; set; }
223+
[JsonConverter(typeof(TitleBarOverlayConverter))]
224+
public TitleBarOverlay TitleBarOverlay { get; set; }
223225

224226
/// <summary>
225227
/// Shows the title in the tile bar in full screen mode on macOS for all
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace ElectronNET.API.Entities;
2+
3+
public class TitleBarOverlay
4+
{
5+
private readonly bool? _value;
6+
7+
private TitleBarOverlay(bool value) => _value = value;
8+
9+
public string Color { get; set; }
10+
11+
public double Height { get; set; }
12+
13+
public string SymbolColor { get; set; }
14+
15+
public static implicit operator bool?(TitleBarOverlay titleBarOverlay) => titleBarOverlay?._value;
16+
17+
public static implicit operator TitleBarOverlay(bool value) => new(value);
18+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using ElectronNET.API.Entities;
2+
using System;
3+
using System.Text.Json;
4+
using System.Text.Json.Serialization;
5+
6+
namespace ElectronNET.Converter;
7+
8+
public class TitleBarOverlayConverter : JsonConverter<TitleBarOverlay>
9+
{
10+
public override TitleBarOverlay Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
11+
{
12+
return reader.TokenType switch
13+
{
14+
JsonTokenType.True => true,
15+
JsonTokenType.False => false,
16+
JsonTokenType.StartObject => JsonSerializer.Deserialize<TitleBarOverlay>(ref reader, options),
17+
_ => throw new JsonException("Invalid value for TitleBarOverlay. Expected true or false."),
18+
};
19+
}
20+
21+
public override void Write(Utf8JsonWriter writer, TitleBarOverlay value, JsonSerializerOptions options)
22+
{
23+
if (value is null)
24+
{
25+
writer.WriteNullValue();
26+
return;
27+
}
28+
29+
var @bool = (bool?)value;
30+
if (@bool.HasValue)
31+
{
32+
writer.WriteBooleanValue(@bool.Value);
33+
}
34+
else
35+
{
36+
JsonSerializer.Serialize(writer, value, options);
37+
}
38+
}
39+
}
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)