Skip to content

Commit

Permalink
fix startup bug (Temporarily disabled for win8+)
Browse files Browse the repository at this point in the history
  • Loading branch information
EFLFE committed Mar 16, 2021
1 parent 1ab6b03 commit 79fccea
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 26 deletions.
24 changes: 14 additions & 10 deletions NotificationIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,25 +399,29 @@ private void MenuExitClick(object sender, EventArgs e)
private void MenuSetting(object sender, EventArgs e)
{
var dlgResult = new Setting().ShowDialog();

if (dlgResult == DialogResult.OK)
{
if (Config.RunOnStartup)
if (Utils.IsWindows8Next()) // bug in win8+ for startup
{
if (!startupManager.IsInStartup())
if (Config.RunOnStartup)
{
if (!startupManager.RunOnStartup())
if (!startupManager.IsInStartup())
{
MessageBox.Show("Adding to autorun is failed!");
if (!startupManager.RunOnStartup())
{
MessageBox.Show("Adding to autorun is failed!");
}
}
}
}
else
{
if (startupManager.IsInStartup())
else
{
if (!startupManager.RemoveFromStartup())
if (startupManager.IsInStartup())
{
MessageBox.Show("Failed on disabling autorun!");
if (!startupManager.RemoveFromStartup())
{
MessageBox.Show("Failed on disabling autorun!");
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions PingoMeter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<Compile Include="Setting.Designer.cs">
<DependentUpon>Setting.cs</DependentUpon>
</Compile>
<Compile Include="Utils.cs" />
<Compile Include="vendor\StartupCreator\StartupCreator.cs" />
<Compile Include="vendor\StartupCreator\StartupViaRegistry.cs" />
<Compile Include="vendor\StartupCreator\StartupViaLink.cs" />
Expand Down
32 changes: 16 additions & 16 deletions Setting.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 Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public Setting()
connectionLostSFXBtn.MouseDown += (s, e) => ClearSFX(connectionLostSFXBtn, e);
connectionResumeSFXBtn.MouseDown += (s, e) => ClearSFX(connectionResumeSFXBtn, e);

if (Utils.IsWindows8Next())
{
cbStartupRun.Enabled = false;
cbStartupRun.Visible = false;
Config.RunOnStartup = false;
}

loaded = true;
}

Expand Down
24 changes: 24 additions & 0 deletions Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Microsoft.Win32;

namespace PingoMeter
{
public static class Utils
{
/// <summary>
/// Return true if app running on Windows 8 or next versions.
/// </summary>
public static bool IsWindows8Next()
{
try
{
string productName = (string)Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue("ProductName");
return productName.StartsWith("Windows 8") || productName.StartsWith("Windows 10");
}
catch
{
return false;
}
}
}
}

0 comments on commit 79fccea

Please sign in to comment.