mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-09-22 15:04:47 +00:00
feat: enhance titleBarOverlay to accept both a boolean and an object
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using ElectronNET.Converter;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System.ComponentModel;
|
||||
|
||||
@@ -219,7 +220,8 @@ namespace ElectronNET.API.Entities
|
||||
/// When using a frameless window this can be used to indicate if the
|
||||
/// standard control buttons should be shown. Default is false.
|
||||
/// </summary>
|
||||
public bool TitleBarOverlay { get; set; }
|
||||
[JsonConverter(typeof(TitleBarOverlayConverter))]
|
||||
public TitleBarOverlay TitleBarOverlay { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Shows the title in the tile bar in full screen mode on macOS for all
|
||||
|
||||
18
src/ElectronNET.API/API/Entities/TitleBarOverlay.cs
Normal file
18
src/ElectronNET.API/API/Entities/TitleBarOverlay.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace ElectronNET.API.Entities;
|
||||
|
||||
public class TitleBarOverlay
|
||||
{
|
||||
private readonly bool? _value;
|
||||
|
||||
private TitleBarOverlay(bool value) => _value = value;
|
||||
|
||||
public string Color { get; set; }
|
||||
|
||||
public double Height { get; set; }
|
||||
|
||||
public string SymbolColor { get; set; }
|
||||
|
||||
public static implicit operator bool?(TitleBarOverlay titleBarOverlay) => titleBarOverlay?._value;
|
||||
|
||||
public static implicit operator TitleBarOverlay(bool value) => new(value);
|
||||
}
|
||||
39
src/ElectronNET.API/Converter/TitleBarOverlayConverter.cs
Normal file
39
src/ElectronNET.API/Converter/TitleBarOverlayConverter.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using ElectronNET.API.Entities;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ElectronNET.Converter;
|
||||
|
||||
public class TitleBarOverlayConverter : JsonConverter<TitleBarOverlay>
|
||||
{
|
||||
public override TitleBarOverlay Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
return reader.TokenType switch
|
||||
{
|
||||
JsonTokenType.True => true,
|
||||
JsonTokenType.False => false,
|
||||
JsonTokenType.StartObject => JsonSerializer.Deserialize<TitleBarOverlay>(ref reader, options),
|
||||
_ => throw new JsonException("Invalid value for TitleBarOverlay. Expected true or false."),
|
||||
};
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, TitleBarOverlay value, JsonSerializerOptions options)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
writer.WriteNullValue();
|
||||
return;
|
||||
}
|
||||
|
||||
var @bool = (bool?)value;
|
||||
if (@bool.HasValue)
|
||||
{
|
||||
writer.WriteBooleanValue(@bool.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonSerializer.Serialize(writer, value, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user