Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Grabacr07 committed Sep 13, 2015
1 parent de9f876 commit d6ab4b3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion source/SylphyHorn/Application.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected override void OnStartup(StartupEventArgs e)

if (GeneralSettings.AccentColor.Value == null)
{
VisualHelper.ForceChangeTheme(VisualHelper.GetWindowsAccentColor());
VisualHelper.ForceChangeAccent(VisualHelper.GetWindowsAccentColor());
}

this.ShowNotifyIcon();
Expand Down
25 changes: 14 additions & 11 deletions source/SylphyHorn/Models/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,27 @@ public static int GetWindowsAccentColor()
return color;
}

public static void ForceChangeTheme(long color)
public static void ForceChangeAccent(long color)
{
ForceChangeTheme(Color.FromArgb((byte)(color >> 24), (byte)(color >> 16), (byte)(color >> 8), (byte)color));
ForceChangeAccent(Color.FromArgb((byte)(color >> 24), (byte)(color >> 16), (byte)(color >> 8), (byte)color));
}

public static void ForceChangeTheme(Color color)
private static FieldInfo appAccentField;

public static void ForceChangeAccent(Color color)
{
color.A = byte.MaxValue;

var appAcent = typeof(ThemeService).GetField("appAccent", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(ThemeService.Current) as ResourceDictionary;
if (appAcent != null)
var fieldInfo = appAccentField ?? (appAccentField = typeof(ThemeService).GetField("appAccent", BindingFlags.Instance | BindingFlags.NonPublic));
var appAccent = fieldInfo?.GetValue(ThemeService.Current) as ResourceDictionary;
if (appAccent != null)
{
appAcent["AccentColorKey"] = color;
appAcent["AccentBrushKey"] = new SolidColorBrush(color);
appAcent["AccentActiveColorKey"] = color;
appAcent["AccentActiveBrushKey"] = new SolidColorBrush(color);
appAcent["AccentHighlightColorKey"] = color;
appAcent["AccentHighlightBrushKey"] = new SolidColorBrush(color);
appAccent["AccentColorKey"] = color;
appAccent["AccentBrushKey"] = new SolidColorBrush(color);
appAccent["AccentActiveColorKey"] = color;
appAccent["AccentActiveBrushKey"] = new SolidColorBrush(color);
appAccent["AccentHighlightColorKey"] = color;
appAccent["AccentHighlightBrushKey"] = new SolidColorBrush(color);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions source/SylphyHorn/Views/TransparentWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected override IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr
{
if (msg == (int)WM.DWMCOLORIZATIONCOLORCHANGED)
{
VisualHelper.ForceChangeTheme((long)wParam);
VisualHelper.ForceChangeAccent((long)wParam);
}

return base.WindowProc(hwnd, msg, wParam, lParam, ref handled);
Expand All @@ -35,7 +35,7 @@ protected override IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr

public class RawWindow
{
protected HwndSource Source { get; private set; }
public HwndSource Source { get; private set; }

public IntPtr Handle => this.Source?.Handle ?? IntPtr.Zero;

Expand All @@ -44,7 +44,7 @@ public virtual void Show()
this.Show(new HwndSourceParameters());
}

public void Show(HwndSourceParameters parameters)
protected void Show(HwndSourceParameters parameters)
{
this.Source = new HwndSource(parameters);
this.Source.AddHook(this.WindowProc);
Expand Down

0 comments on commit d6ab4b3

Please sign in to comment.