Skip to content

Commit

Permalink
Removed condition judgment using NullReferenceException
Browse files Browse the repository at this point in the history
  • Loading branch information
geforce-hisa0904 committed Aug 15, 2020
1 parent 964b252 commit 7f74999
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions RunCat/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,16 @@ public RunCatApplicationContext()
private string GetAppsUseTheme()
{
string keyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize";
try
using (RegistryKey rKey = Registry.CurrentUser.OpenSubKey(keyName))
{
using (RegistryKey rKey = Registry.CurrentUser.OpenSubKey(keyName))
{
int theme = (int)rKey.GetValue("SystemUsesLightTheme");
return theme == 0 ? "dark" : "light";
object value;
if (rKey == null || (value = rKey.GetValue("SystemUsesLightTheme")) == null)
{
Console.WriteLine("Oh No! Couldn't get theme light/dark");
return "light";
}
}
catch (NullReferenceException)
{
Console.WriteLine("Oh No! Couldn't get theme light/dark");
return "light";
int theme = (int)value;
return theme == 0 ? "dark" : "light";
}
}

Expand Down

0 comments on commit 7f74999

Please sign in to comment.