diff --git a/shadowsocks-csharp/Util/Util.cs b/shadowsocks-csharp/Util/Util.cs index 8912eb68..81ea61e5 100755 --- a/shadowsocks-csharp/Util/Util.cs +++ b/shadowsocks-csharp/Util/Util.cs @@ -268,34 +268,33 @@ namespace Shadowsocks.Util private static extern bool SetProcessWorkingSetSize(IntPtr process, UIntPtr minimumWorkingSetSize, UIntPtr maximumWorkingSetSize); - - // See: https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx - public static bool IsSupportedRuntimeVersion() + public static void OpenInBrowser(string url) { - /* - * +-----------------------------------------------------------------+----------------------------+ - * | Version | Value of the Release DWORD | - * +-----------------------------------------------------------------+----------------------------+ - * | .NET Framework 4.6.2 installed on Windows 10 Anniversary Update | 394802 | - * | .NET Framework 4.6.2 installed on all other Windows OS versions | 394806 | - * +-----------------------------------------------------------------+----------------------------+ - */ - const int minSupportedRelease = 394802; - - const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"; - using (var ndpKey = OpenRegKey(subkey, false, RegistryHive.LocalMachine)) + try { - if (ndpKey?.GetValue("Release") != null) + Process.Start(url); + } + catch + { + // hack because of this: https://github.com/dotnet/corefx/issues/10361 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - var releaseKey = (int)ndpKey.GetValue("Release"); - - if (releaseKey >= minSupportedRelease) - { - return true; - } + url = url.Replace("&", "^&"); + Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true }); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Process.Start("xdg-open", url); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + Process.Start("open", url); + } + else + { + throw; } } - return false; } } } diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index e31fa67b..b04c28ab 100644 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -38,7 +38,7 @@ namespace Shadowsocks.View private ToolStripMenuItem disableItem; private ToolStripMenuItem AutoStartupItem; private ToolStripMenuItem ShareOverLANItem; - private ToolStripSeparator SeperatorItem; + private ToolStripSeparator SeperatorItem; private ToolStripMenuItem ConfigItem; private ToolStripMenuItem ServersItem; private ToolStripMenuItem globalModeItem; @@ -277,12 +277,12 @@ namespace Shadowsocks.View private ToolStripMenuItem CreateToolStripMenuItem(string text, EventHandler click) { - return new ToolStripMenuItem(I18N.GetString(text),null, click); + return new ToolStripMenuItem(I18N.GetString(text), null, click); } private ToolStripMenuItem CreateMenuGroup(string text, ToolStripItem[] items) { - return new ToolStripMenuItem(I18N.GetString(text), null,items); + return new ToolStripMenuItem(I18N.GetString(text), null, items); } private void LoadMenu() @@ -461,7 +461,7 @@ namespace Shadowsocks.View int strategyCount = 0; foreach (var strategy in controller.GetStrategies()) { - if (!items.OfType().Any(ts=>ts.Text==strategy.Name)) + if (!items.OfType().Any(ts => ts.Text == strategy.Name)) { ToolStripMenuItem item = new ToolStripMenuItem(strategy.Name); item.Tag = strategy.ID; @@ -496,9 +496,17 @@ namespace Shadowsocks.View foreach (var item in items) { var menuItem = item as ToolStripMenuItem; - if (menuItem != null && menuItem.Tag != null && (menuItem.Tag.ToString() == configuration.index.ToString() || menuItem.Tag.ToString() == configuration.strategy)) + if (menuItem == null || menuItem.Tag == null) continue; + + if ( + menuItem.Tag.ToString() == configuration.index.ToString() + || menuItem.Tag.ToString() == configuration.strategy + ) { menuItem.Checked = true; + } else + { + menuItem.Checked = false; } } } @@ -624,7 +632,7 @@ namespace Shadowsocks.View private void AboutItem_Click(object sender, EventArgs e) { - Process.Start("https://github.com/shadowsocks/shadowsocks-windows"); + Utils.OpenInBrowser("https://github.com/shadowsocks/shadowsocks-windows"); } private void notifyIcon1_Click(object sender, MouseEventArgs e) @@ -846,7 +854,7 @@ namespace Shadowsocks.View void openURLFromQRCode(object sender, FormClosedEventArgs e) { - Process.Start(_urlToOpen); + Utils.OpenInBrowser(_urlToOpen); } private void AutoStartupItem_Click(object sender, EventArgs e)