Skip to content

Commit

Permalink
themes.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
rounk-ctrl committed Sep 18, 2023
1 parent 76a3244 commit 399d0ae
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 171 deletions.
75 changes: 0 additions & 75 deletions Rectify11Installer/Controls/CustomProgressBar.cs

This file was deleted.

8 changes: 4 additions & 4 deletions Rectify11Installer/Core/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static string InstalledVersion
public class NavigationHelper
{
public static event EventHandler OnNavigate;
public static void InvokeOnNavigate(object sender, EventArgs e)
public static void InvokeOnNavigate(object sender, EventArgs e)
=> OnNavigate?.Invoke(sender, e);
}

Expand Down Expand Up @@ -195,13 +195,13 @@ public class Logger
+ "\n═════════════════════════════\n";
#endregion
#region Public Methods
public static void WriteLine(string s)
public static void WriteLine(string s)
=> Text += s + "\n";

public static void WriteLine(string s, Exception ex)
public static void WriteLine(string s, Exception ex)
=> Text += s + ". " + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + Environment.NewLine;

public static void CommitLog()
public static void CommitLog()
=> File.WriteAllText(System.IO.Path.Combine(Variables.r11Folder, "installer.log"), Text);

public static void Warn(string v)
Expand Down
3 changes: 0 additions & 3 deletions Rectify11Installer/Rectify11Installer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\CustomProgressBar.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\DarkAwareControls.cs">
<SubType>Component</SubType>
</Compile>
Expand Down
167 changes: 78 additions & 89 deletions Rectify11Installer/Win32/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,95 +7,84 @@

namespace Rectify11Installer.Core
{
public class Theme
{
#region Variables
public static VisualStyle DarkStyle = new();
public static VisualStyle LightStyle = new();
public static bool IsUsingDarkMode { get; private set; }
#endregion
#region Public Methods
public static void InitTheme()
{
var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
if (key != null)
{
var registryValueObject = key.GetValue("AppsUseLightTheme");
if (registryValueObject == null)
{
return;
}
public class Theme
{
#region Variables
public static VisualStyle DarkStyle = new();
public static VisualStyle LightStyle = new();
public static bool IsUsingDarkMode { get; private set; }
public static event EventHandler OnThemeChanged;
#endregion
#region Public Methods
public static void InitTheme()
{
IsUsingDarkMode = (int)Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize")?.GetValue("AppsUseLightTheme") <= 0;
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
}

var registryValue = (int)registryValueObject;
IsUsingDarkMode = registryValue <= 0;
}
public static void LoadTheme()
{
DarkStyle.Load(Path.Combine(Path.GetTempPath(), "Dark.msstyles"));
LightStyle.Load(Path.Combine(Path.GetTempPath(), "light.msstyles"));
}

SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
}
public static event EventHandler OnThemeChanged;

public static void LoadTheme()
{
DarkStyle.Load(Path.Combine(Path.GetTempPath(), "Dark.msstyles"));
LightStyle.Load(Path.Combine(Path.GetTempPath(), "light.msstyles"));
}

public static StylePart GetNavArrowPart(VisualStyle v, NavigationButtonType type)
{
return (from classes in v.Classes.Values
where classes.ClassName == "Navigation"
let partStr = type switch
{
NavigationButtonType.Forward => "FORWARDBUTTON",
NavigationButtonType.Backward => "BACKBUTTON",
NavigationButtonType.Menu => "MENUBUTTON",
_ => throw new NotImplementedException()
}
from parts in classes.Parts
where parts.Value.PartName == partStr
select parts.Value).FirstOrDefault();
}
public static StylePart GetCommandLinkPart(VisualStyle v)
{
return (from classes in v.Classes.Values where classes.ClassName == "Button" from parts in classes.Parts where parts.Value.PartName == "COMMANDLINK" select parts.Value).FirstOrDefault();
}
public static StylePart GetGroupBox(VisualStyle v)
{
return (from classes in v.Classes.Values where classes.ClassName == "Button" from parts in classes.Parts where parts.Value.PartName == "GROUPBOX" select parts.Value).FirstOrDefault();
}
public static StylePart GetCommandLinkGlyphPart(VisualStyle v)
{
return (from classes in v.Classes.Values where classes.ClassName == "Button" from parts in classes.Parts where parts.Value.PartName == "COMMANDLINKGLYPH" select parts.Value).FirstOrDefault();
}
#nullable enable
public static StylePart? GetProgressbarBg(VisualStyle v)
{
return (from classes in v.Classes.Values where classes.ClassName == "Progress" from parts in classes.Parts where parts.Value.PartName == "BAR" select parts.Value).FirstOrDefault();
}
public static StylePart? GetProgressbarFill(VisualStyle v)
{
return (from classes in v.Classes.Values where classes.ClassName == "Progress" from parts in classes.Parts where parts.Value.PartName == "FILL" select parts.Value).FirstOrDefault();
}
#nullable disable
public static StylePart GetButtonPart(VisualStyle v)
{
return (from classes in v.Classes.Values where classes.ClassName == "Button" from parts in classes.Parts where parts.Value.PartName == "PUSHBUTTON" select parts.Value).FirstOrDefault();
}
#endregion
#region Private Methods
private static void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
switch (e.Category)
{
case UserPreferenceCategory.General:
if (OnThemeChanged != null)
{
InitTheme();
OnThemeChanged.Invoke(sender, e);
}
break;
}
}
#endregion
}
public static StylePart GetNavArrowPart(VisualStyle v, NavigationButtonType type)
{
return (from classes in v.Classes.Values
where classes.ClassName == "Navigation"
let partStr = type switch
{
NavigationButtonType.Forward => "FORWARDBUTTON",
NavigationButtonType.Backward => "BACKBUTTON",
NavigationButtonType.Menu => "MENUBUTTON",
_ => throw new NotImplementedException()
}
from parts in classes.Parts
where parts.Value.PartName == partStr
select parts.Value).FirstOrDefault();
}
public static StylePart GetCommandLinkPart(VisualStyle v)
{
return (from classes in v.Classes.Values
where classes.ClassName == "Button"
from parts in classes.Parts
where parts.Value.PartName == "COMMANDLINK"
select parts.Value).FirstOrDefault();
}
public static StylePart GetGroupBox(VisualStyle v)
{
return (from classes in v.Classes.Values
where classes.ClassName == "Button"
from parts in classes.Parts
where parts.Value.PartName == "GROUPBOX"
select parts.Value).FirstOrDefault();
}
public static StylePart GetCommandLinkGlyphPart(VisualStyle v)
{
return (from classes in v.Classes.Values
where classes.ClassName == "Button"
from parts in classes.Parts
where parts.Value.PartName == "COMMANDLINKGLYPH"
select parts.Value).FirstOrDefault();
}
public static StylePart GetButtonPart(VisualStyle v)
{
return (from classes in v.Classes.Values
where classes.ClassName == "Button"
from parts in classes.Parts
where parts.Value.PartName == "PUSHBUTTON"
select parts.Value).FirstOrDefault();
}
#endregion
#region Private Methods
private static void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
if (e.Category == UserPreferenceCategory.General)
{
InitTheme();
OnThemeChanged?.Invoke(sender, e);
}
}
}
#endregion
}

0 comments on commit 399d0ae

Please sign in to comment.