diff --git a/ElectronNET.API/Entities/ThemeSourceMode.cs b/ElectronNET.API/Entities/ThemeSourceMode.cs new file mode 100644 index 0000000..53fa23e --- /dev/null +++ b/ElectronNET.API/Entities/ThemeSourceMode.cs @@ -0,0 +1,28 @@ +using System.ComponentModel; + +namespace ElectronNET.API.Entities +{ + /// + /// Defines the ThemeSourceMode enumeration. + /// + public enum ThemeSourceMode + { + /// + /// Operating system default. + /// + [Description("system")] + System, + + /// + /// Light theme. + /// + [Description("light")] + Light, + + /// + /// Dark theme. + /// + [Description("dark")] + Dark + } +} \ No newline at end of file diff --git a/ElectronNET.API/NativeTheme.cs b/ElectronNET.API/NativeTheme.cs index a3485cc..81770e9 100644 --- a/ElectronNET.API/NativeTheme.cs +++ b/ElectronNET.API/NativeTheme.cs @@ -1,5 +1,7 @@ using System; using System.Threading.Tasks; +using ElectronNET.API.Entities; +using ElectronNET.API.Extensions; namespace ElectronNET.API { @@ -33,24 +35,9 @@ namespace ElectronNET.API } /// - /// Checks if the new ThemeSource is valid. - /// - /// The new ThemeSource to check. - /// True, if is a valid ThemeSource. - internal bool IsValidThemeSource(string themeSource) - { - var result = - string.Equals(themeSource, "dark", StringComparison.OrdinalIgnoreCase) || - string.Equals(themeSource, "light", StringComparison.OrdinalIgnoreCase) || - string.Equals(themeSource, "system", StringComparison.OrdinalIgnoreCase); - - return result; - } - - /// - /// Setting this property to 'system' will remove the override and everything will be reset to the OS default. By default 'ThemeSource' is 'system'. + /// Setting this property to will remove the override and everything will be reset to the OS default. By default 'ThemeSource' is . /// - /// Settings this property to 'dark' will have the following effects: + /// Settings this property to will have the following effects: /// /// /// will be when accessed @@ -69,10 +56,10 @@ namespace ElectronNET.API /// /// /// - /// Settings this property to 'light' will have the following effects: + /// Settings this property to will have the following effects: /// /// - /// will be false when accessed + /// will be when accessed /// /// /// Any UI Electron renders on Linux and Windows including context menus, devtools, etc. will use the light UI. @@ -91,42 +78,40 @@ namespace ElectronNET.API /// /// /// - /// Follow OS: SetThemeSource("system"); + /// Follow OS: SetThemeSource(ThemeSourceMode.System); /// /// - /// Dark Mode: SetThemeSource("dark"); + /// Dark Mode: SetThemeSource(ThemeSourceMode.Dark); /// /// - /// Light Mode: SetThemeSource("light"); + /// Light Mode: SetThemeSource(ThemeSourceMode.Light); /// /// /// Your application should then always use to determine what CSS to apply. /// /// The new ThemeSource. - public void SetThemeSource(string themeSource) + public void SetThemeSource(ThemeSourceMode themeSourceMode) { - // Check for supported themeSource, otherwise it sets the default - if (!IsValidThemeSource(themeSource)) - { - themeSource = "system"; - } + var themeSource = themeSourceMode.GetDescription(); - BridgeConnector.Socket.Emit("nativeTheme-themeSource", themeSource.ToLower()); + BridgeConnector.Socket.Emit("nativeTheme-themeSource", themeSource); } /// - /// A property that can be 'system', 'light' or 'dark'. It is used to override () and + /// A property that can be , or . It is used to override () and /// supercede the value that Chromium has chosen to use internally. /// - public Task GetThemeSourceAsync() + public Task GetThemeSourceAsync() { - var taskCompletionSource = new TaskCompletionSource(); + var taskCompletionSource = new TaskCompletionSource(); BridgeConnector.Socket.On("nativeTheme-themeSource-getCompleted", (themeSource) => { BridgeConnector.Socket.Off("nativeTheme-themeSource-getCompleted"); - taskCompletionSource.SetResult((string)themeSource); + var themeSourceValue = (ThemeSourceMode)Enum.Parse(typeof(ThemeSourceMode), (string)themeSource, true); + + taskCompletionSource.SetResult(themeSourceValue); }); BridgeConnector.Socket.Emit("nativeTheme-themeSource-get");