Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit a4bc6b9

Browse files
committed
Merge branch 'jcansdale/theme-detection-outside-vs' into fixes/dialog-style-guide
2 parents 89c6302 + cd7aea5 commit a4bc6b9

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/GitHub.VisualStudio.UI/Colors.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.VisualStudio.PlatformUI;
22
using System;
3+
using System.Windows;
34
using System.Windows.Media;
45

56
namespace GitHub.VisualStudio.Helpers
@@ -34,25 +35,22 @@ public static Color ToColor(this System.Drawing.Color color)
3435

3536
public static string DetectTheme()
3637
{
37-
try
38+
if (Application.Current?.TryFindResource(EnvironmentColors.AccentMediumColorKey) is Color cc)
3839
{
39-
var color = VSColorTheme.GetThemedColor(EnvironmentColors.AccentMediumColorKey);
40-
var cc = color.ToColor();
4140
if (cc == AccentMediumBlueTheme)
4241
return "Blue";
4342
if (cc == AccentMediumLightTheme)
4443
return "Light";
4544
if (cc == AccentMediumDarkTheme)
4645
return "Dark";
46+
var color = System.Drawing.Color.FromArgb(cc.A, cc.R, cc.R, cc.B);
4747
var brightness = color.GetBrightness();
4848
var dark = brightness < 0.5f;
4949
return dark ? "Dark" : "Light";
5050
}
51-
// this throws in design time and when running outside of VS
52-
catch (ArgumentNullException)
53-
{
54-
return "Dark";
55-
}
51+
52+
// When Visual Studio resources aren't active
53+
return "Dark";
5654
}
5755
}
5856
}

0 commit comments

Comments
 (0)