Skip to content

Commit

Permalink
Added CurrentTheme property (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Aug 30, 2023
1 parent 1425859 commit 56d2846
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions PeyrSharp.Env/PeyrSharp.Env.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="PeyrSharp.Enums" Version="1.8.0.2308" />
</ItemGroup>
</Project>
23 changes: 23 additions & 0 deletions PeyrSharp.Env/Sys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using Microsoft.Win32;
using PeyrSharp.Enums;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -241,6 +242,28 @@ public static void ExecuteAsAdmin(string filename)
/// <returns>The name of the current computer.</returns>
public static string ComputerName => Environment.MachineName;

/// <summary>
/// Gets the current theme. Only works on Windows 10/11.
/// </summary>
[SupportedOSPlatform("windows")]
public static SystemThemes CurrentTheme
{
get
{
if (CurrentWindowsVersion != WindowsVersion.Windows10 && CurrentWindowsVersion != WindowsVersion.Windows11)
{
return SystemThemes.Unknown; // Avoid errors on older OSs
}
var t = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "SystemUsesLightTheme", "1");
return t switch
{
0 => SystemThemes.Dark,
1 => SystemThemes.Light,
_ => SystemThemes.Unknown
}; // Return
}
}

/// <summary>
/// Terminates a process with the specified process ID.
/// </summary>
Expand Down

0 comments on commit 56d2846

Please sign in to comment.