Browse Source

Add an option for checking updates

tags/3.0
Gang Zhuo 9 years ago
parent
commit
00ccb52bef
5 changed files with 71 additions and 17 deletions
  1. +10
    -9
      shadowsocks-csharp/Controller/Service/UpdateChecker.cs
  2. +6
    -0
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  3. +4
    -0
      shadowsocks-csharp/Data/cn.txt
  4. +2
    -0
      shadowsocks-csharp/Model/Configuration.cs
  5. +49
    -8
      shadowsocks-csharp/View/MenuViewController.cs

+ 10
- 9
shadowsocks-csharp/Controller/Service/UpdateChecker.cs View File

@@ -14,9 +14,10 @@ namespace Shadowsocks.Controller
{
private const string UpdateURL = "https://api.github.com/repos/shadowsocks/shadowsocks-windows/releases";
public bool NewVersionFound;
public string LatestVersionNumber;
public string LatestVersionURL;
public event EventHandler NewVersionFound;
public event EventHandler CheckUpdateCompleted;
public const string Version = "2.5.8";
@@ -114,17 +115,17 @@ namespace Shadowsocks.Controller
}
}
if (versions.Count == 0)
if (versions.Count != 0)
{
return;
// sort versions
SortVersions(versions);
NewVersionFound = true;
LatestVersionURL = versions[versions.Count - 1];
LatestVersionNumber = ParseVersionFromURL(LatestVersionURL);
}
// sort versions
SortVersions(versions);
LatestVersionURL = versions[versions.Count - 1];
LatestVersionNumber = ParseVersionFromURL(LatestVersionURL);
if (NewVersionFound != null)
if (CheckUpdateCompleted != null)
{
NewVersionFound(this, new EventArgs());
CheckUpdateCompleted(this, new EventArgs());
}
}
catch (Exception ex)


+ 6
- 0
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -280,6 +280,12 @@ namespace Shadowsocks.Controller
}
}
public void ToggleCheckingUpdate(bool enabled)
{
_config.autoCheckUpdate = enabled;
Configuration.Save(_config);
}
protected void Reload()
{
// some logic in configuration updated the config when saving, we need to read it again


+ 4
- 0
shadowsocks-csharp/Data/cn.txt View File

@@ -21,6 +21,9 @@ Show QRCode...=显示二维码...
Scan QRCode from Screen...=扫描屏幕上的二维码...
Availability Statistics=统计可用性
Show Logs...=显示日志...
Updates...=更新...
Check Updates...=检查更新
Automatically Check Updates=自动检查更新
About...=关于...
Quit=退出
Edit Servers=编辑服务器
@@ -78,6 +81,7 @@ Password can not be blank=密码不能为空
Port out of range=端口超出范围
Port can't be 8123=端口不能为 8123
Shadowsocks {0} Update Found=Shadowsocks {0} 更新
No update is available=没有可用的更新
Click here to download=点击这里下载
Shadowsocks is here=Shadowsocks 在这里
You can turn on/off Shadowsocks in the context menu=可以在右键菜单中开关 Shadowsocks


+ 2
- 0
shadowsocks-csharp/Model/Configuration.cs View File

@@ -23,6 +23,7 @@ namespace Shadowsocks.Model
public string pacUrl;
public bool useOnlinePac;
public bool availabilityStatistics;
public bool autoCheckUpdate;
private static string CONFIG_FILE = "gui-config.json";
@@ -76,6 +77,7 @@ namespace Shadowsocks.Model
index = 0,
isDefault = true,
localPort = 1080,
autoCheckUpdate = true,
configs = new List<Server>()
{
GetDefaultServer()


+ 49
- 8
shadowsocks-csharp/View/MenuViewController.cs View File

@@ -26,6 +26,7 @@ namespace Shadowsocks.View
private ContextMenu contextMenu1;
private bool _isFirstRun;
private bool _isStartupChecking;
private MenuItem enableItem;
private MenuItem modeItem;
private MenuItem AutoStartupItem;
@@ -42,6 +43,7 @@ namespace Shadowsocks.View
private MenuItem updateFromGFWListItem;
private MenuItem editGFWUserRuleItem;
private MenuItem editOnlinePACItem;
private MenuItem autoCheckUpdatesToggleItem;
private ConfigForm configForm;
private string _urlToOpen;
@@ -68,13 +70,19 @@ namespace Shadowsocks.View
_notifyIcon.MouseDoubleClick += notifyIcon1_DoubleClick;
this.updateChecker = new UpdateChecker();
updateChecker.NewVersionFound += updateChecker_NewVersionFound;
updateChecker.CheckUpdateCompleted += updateChecker_CheckUpdateCompleted;
LoadCurrentConfiguration();
updateChecker.CheckUpdate(controller.GetConfigurationCopy());
Configuration config = controller.GetConfigurationCopy();
if (controller.GetConfigurationCopy().isDefault)
if (config.autoCheckUpdate)
{
_isStartupChecking = true;
updateChecker.CheckUpdate(config);
}
if (config.isDefault)
{
_isFirstRun = true;
ShowConfigForm();
@@ -182,6 +190,11 @@ namespace Shadowsocks.View
this.ShareOverLANItem = CreateMenuItem("Allow Clients from LAN", new EventHandler(this.ShareOverLANItem_Click)),
new MenuItem("-"),
CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)),
CreateMenuGroup("Updates...", new MenuItem[] {
CreateMenuItem("Check Updates...", new EventHandler(this.checkUpdatesItem_Click)),
new MenuItem("-"),
this.autoCheckUpdatesToggleItem = CreateMenuItem("Automatically Check Updates", new EventHandler(this.autoCheckUpdatesToggleItem_Click)),
}),
CreateMenuItem("About...", new EventHandler(this.AboutItem_Click)),
new MenuItem("-"),
CreateMenuItem("Quit", new EventHandler(this.Quit_Click))
@@ -238,11 +251,20 @@ namespace Shadowsocks.View
ShowBalloonTip(I18N.GetString("Shadowsocks"), result, ToolTipIcon.Info, 1000);
}
void updateChecker_NewVersionFound(object sender, EventArgs e)
void updateChecker_CheckUpdateCompleted(object sender, EventArgs e)
{
ShowBalloonTip(String.Format(I18N.GetString("Shadowsocks {0} Update Found"), updateChecker.LatestVersionNumber), I18N.GetString("Click here to download"), ToolTipIcon.Info, 5000);
_notifyIcon.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
_isFirstRun = false;
if (updateChecker.NewVersionFound)
{
ShowBalloonTip(String.Format(I18N.GetString("Shadowsocks {0} Update Found"), updateChecker.LatestVersionNumber), I18N.GetString("Click here to download"), ToolTipIcon.Info, 5000);
_notifyIcon.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
_isFirstRun = false;
}
else if (!_isStartupChecking)
{
ShowBalloonTip(I18N.GetString("Shadowsocks"), I18N.GetString("No update is available"), ToolTipIcon.Info, 5000);
_isFirstRun = false;
}
_isStartupChecking = false;
}
void notifyIcon1_BalloonTipClicked(object sender, EventArgs e)
@@ -266,6 +288,7 @@ namespace Shadowsocks.View
onlinePACItem.Checked = onlinePACItem.Enabled && config.useOnlinePac;
localPACItem.Checked = !onlinePACItem.Checked;
UpdatePACItemsEnabledStatus();
UpdateUpdateMenu();
}
private void UpdateServersMenu()
@@ -343,7 +366,7 @@ namespace Shadowsocks.View
if (_isFirstRun)
{
_notifyIcon.BalloonTipTitle = I18N.GetString("Shadowsocks is here");
_notifyIcon.BalloonTipText = I18N.GetString("You can turn on/off Shadowsocks in the context menu");
_notifyIcon.BalloonTipText = I18N.GetString("You can turn on/off Shadowsocks in the context menu");
_notifyIcon.BalloonTipIcon = ToolTipIcon.Info;
_notifyIcon.ShowBalloonTip(0);
_isFirstRun = false;
@@ -591,5 +614,23 @@ namespace Shadowsocks.View
this.editOnlinePACItem.Enabled = true;
}
}
private void UpdateUpdateMenu()
{
Configuration configuration = controller.GetConfigurationCopy();
autoCheckUpdatesToggleItem.Checked = configuration.autoCheckUpdate;
}
private void autoCheckUpdatesToggleItem_Click(object sender, EventArgs e)
{
Configuration configuration = controller.GetConfigurationCopy();
controller.ToggleCheckingUpdate(!configuration.autoCheckUpdate);
UpdateUpdateMenu();
}
private void checkUpdatesItem_Click(object sender, EventArgs e)
{
updateChecker.CheckUpdate(controller.GetConfigurationCopy());
}
}
}

Loading…
Cancel
Save