Skip to content

Commit

Permalink
Add autorun option
Browse files Browse the repository at this point in the history
  • Loading branch information
Xorboo committed Jun 4, 2023
1 parent c952906 commit 62993f6
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 22 deletions.
27 changes: 27 additions & 0 deletions HdrSwitcher/AutorunManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Win32;

namespace HdrSwitcher
{
internal static class AutorunManager
{
const string AutorunRegistryPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
const string AppRegistryName = "Hdr Switcher";

public static bool AutorunEnabled
{
get
{
var rk = Registry.CurrentUser.OpenSubKey(AutorunRegistryPath, false);
return rk?.GetValue(AppRegistryName) != null;
}
set
{
var rk = Registry.CurrentUser.OpenSubKey(AutorunRegistryPath, true);
if (value)
rk?.SetValue(AppRegistryName, Application.ExecutablePath);
else
rk?.DeleteValue(AppRegistryName, false);
}
}
}
}
53 changes: 42 additions & 11 deletions HdrSwitcher/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions HdrSwitcher/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public FormMain()

_tracker = new MonitorTracker(Properties.Settings.Default.MonitorIndex);
UpdateMonitorState();

autorunToolStripMenuItem.Checked = AutorunManager.AutorunEnabled;
}


Expand Down Expand Up @@ -69,6 +71,11 @@ private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
UpdateMonitorState();
}

private void autorunToolStripMenuItem_Click(object sender, EventArgs e)
{
AutorunManager.AutorunEnabled = !AutorunManager.AutorunEnabled;
}

private void checkTimer_Tick(object sender, EventArgs e)
{
UpdateMonitorState();
Expand Down
19 changes: 9 additions & 10 deletions HdrSwitcher/HdrSwitcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
</PropertyGroup>

<ItemGroup>
<Content Include="Resources\IconEnabled.ico" />
<Content Include="Resources\IconDisabled.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Resources\IconEnabled.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Resources\IconUnsupported.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -46,15 +54,6 @@
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<None Update="Resources\IconDisabled.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\IconEnabled.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\IconUnsupported.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion HdrSwitcher/MonitorTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace HdrSwitcher
{
public class MonitorTracker
internal class MonitorTracker
{
public enum MonitorState
{
Expand Down

0 comments on commit 62993f6

Please sign in to comment.