Skip to content

Commit

Permalink
Bug fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
brondavies committed May 1, 2024
1 parent 2a7e401 commit fbd293a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/TrayToolbar/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal class ConfigHelper
const string REGKEY_STARTUP = @"Software\Microsoft\Windows\CurrentVersion\Run";
const string REGKEY_SHOWINTRAY = @"Software\Microsoft\Windows\CurrentVersion\RunNotification"; //StartupTNotiTrayToolbar (DWORD) = 1
const string UPDATE_URL = "https://github.com/brondavies/TrayToolbar/releases/latest";
const string STARTUP_VALUE = "TrayToolbar";

internal static readonly string ApplicationRoot =
new FileInfo(
Expand All @@ -25,7 +26,7 @@ internal class ConfigHelper
internal static bool GetStartupKey()
{
using RegistryKey key = Registry.CurrentUser.CreateSubKey(REGKEY_STARTUP);
var val = key.GetValue("TrayToolbar");
var val = key.GetValue(STARTUP_VALUE);
var value = (string?)val == Assembly.GetExecutingAssembly().Location;

key.Close();
Expand All @@ -37,11 +38,14 @@ internal static void SetStartupKey(bool value)
using RegistryKey key = Registry.CurrentUser.CreateSubKey(REGKEY_STARTUP);
if (value)
{
key.SetValue("TrayToolbar", Assembly.GetExecutingAssembly().Location, RegistryValueKind.String);
key.SetValue(STARTUP_VALUE, Assembly.GetExecutingAssembly().Location, RegistryValueKind.String);
}
else
{
key.DeleteValue("TrayToolbar");
if (key.GetValueNames().Contains(STARTUP_VALUE))
{
key.DeleteValue(STARTUP_VALUE);
}
}
key.Close();
}
Expand Down Expand Up @@ -78,8 +82,11 @@ internal static bool WriteConfiguration(TrayToolbarConfiguration configuration)
Directory.CreateDirectory(ProfileFolder);
}
var json = JsonSerializer.Serialize(configuration, jsonOption);
if (File.Exists(ConfigurationFile))
{
File.Delete(ConfigurationFile);
}
File.WriteAllText(ConfigurationFile, json);
File.SetAttributes(ConfigurationFile, FileAttributes.Hidden);
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion src/TrayToolbar/TrayToolbar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<StartupObject>TrayToolbar.Program</StartupObject>
<ApplicationIcon>TrayIcon.ico</ApplicationIcon>
<Version>1.1.1</Version>
<Version>1.1.2</Version>
<Title>TrayToolbar</Title>
<Copyright>© Brontech, LLC</Copyright>
<PackageProjectUrl>https://github.com/brondavies/TrayToolbar</PackageProjectUrl>
Expand Down

0 comments on commit fbd293a

Please sign in to comment.