Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickiel committed Apr 17, 2022
1 parent 15b38b9 commit 399b3c3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 40 deletions.
26 changes: 18 additions & 8 deletions src/VolumeScroller/MainModel.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
namespace VolumeScroller;
using Microsoft.Win32;

namespace VolumeScroller;

public class MainModel
{
public MainModel()
{
ResetRunOnStartup();
}

public int Increment
public static int Increment
{
get => Properties.Settings.Default.Increment;
set
Expand All @@ -17,7 +18,7 @@ public int Increment
}
}

public bool TaskbarMustBeVisible
public static bool TaskbarMustBeVisible
{
get => Properties.Settings.Default.TaskbarMustBeVisible;
set
Expand All @@ -28,7 +29,19 @@ public bool TaskbarMustBeVisible
}
}

public bool RunOnStartup
public static string TaskBarIconPath => GetTaskbarIconPath();

private static string GetTaskbarIconPath()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
var isLightTheme = (int)key.GetValue("SystemUsesLightTheme") == 1;

return isLightTheme
? "/Resources/VolumeScroller_light.ico"
: "/Resources/VolumeScroller_dark.ico";
}

public static bool RunOnStartup
{
get => Properties.Settings.Default.RunOnStartup;
set
Expand All @@ -38,7 +51,4 @@ public bool RunOnStartup
new StartupManager(Process.GetCurrentProcess()).Set(value);
}
}

public void ResetRunOnStartup()
=> RunOnStartup = Properties.Settings.Default.RunOnStartup;
}
43 changes: 13 additions & 30 deletions src/VolumeScroller/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,36 @@ namespace VolumeScroller;

public class MainViewModel : ViewModelBase, IDisposable
{
private readonly MainModel mainModel;
private string taskBarIconPath;

public MainViewModel(MainModel mainModel)
{
this.mainModel = mainModel;
TaskBarIconPath = GetTaskbarIconPath();
{
SystemEvents.UserPreferenceChanged += UserPreferenceChanged;
}

public string TaskBarIconPath
{
get => taskBarIconPath;
set => SetProperty(ref taskBarIconPath, value);
}
public string TaskBarIconPath => MainModel.TaskBarIconPath;

public bool RunOnStartup
public static bool RunOnStartup
{
get => mainModel.RunOnStartup;
set => mainModel.RunOnStartup = value;
get => MainModel.RunOnStartup;
set => MainModel.RunOnStartup = value;
}

public bool TaskbarMustBeVisible
public static bool TaskbarMustBeVisible
{
get => mainModel.TaskbarMustBeVisible;
set => mainModel.TaskbarMustBeVisible = value;
get => MainModel.TaskbarMustBeVisible;
set => MainModel.TaskbarMustBeVisible = value;
}

public int Increment
public static int Increment
{
get => mainModel.Increment * 2;
set => mainModel.Increment = value / 2;
get => MainModel.Increment * 2;
set => MainModel.Increment = value / 2;
}

public void Dispose()
=> SystemEvents.UserPreferenceChanged -= UserPreferenceChanged;

private void UserPreferenceChanged(object sender, EventArgs e)
=> TaskBarIconPath = GetTaskbarIconPath();

private static string GetTaskbarIconPath()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
var isLightTheme = (int)key.GetValue("SystemUsesLightTheme") == 1;

return isLightTheme
? "/Resources/VolumeScroller_light.ico"
: "/Resources/VolumeScroller_dark.ico";
}
private void UserPreferenceChanged(object sender, EventArgs e)
=> OnPropertyChanged(nameof(TaskBarIconPath));
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@
Grid.Row="0"
Grid.Column="0"
HorizontalAlignment="Right" />
<Label Content="{Binding Increment}"
<Label Content="{Binding ElementName=IncrementSlider, Path=Value}"
HorizontalAlignment="Left"
Grid.Row="0"
Grid.Column="1" />
</StackPanel>
<Slider Width="100"
<Slider x:Name="IncrementSlider"
Width="100"
Minimum="2"
Maximum="20"
Grid.Column="1"
Expand All @@ -55,6 +56,7 @@
Value="{Binding Increment, Mode=TwoWay}"
TickPlacement="BottomRight"
AutoToolTipPlacement="TopLeft"
AutoToolTipPrecision="0"
IsSnapToTickEnabled="True"
TickFrequency="2" />
<Label Content="Run on startup"
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 399b3c3

Please sign in to comment.