@@ -52,6 +52,12 @@ namespace Shadowsocks.Controller | |||
public string Path; | |||
} | |||
public class UpdatedEventArgs : EventArgs | |||
{ | |||
public string OldVersion; | |||
public string NewVersion; | |||
} | |||
public class TrafficPerSecond | |||
{ | |||
public long inboundCounter; | |||
@@ -78,6 +84,9 @@ namespace Shadowsocks.Controller | |||
public event ErrorEventHandler Errored; | |||
// Invoked when controller.Start(); | |||
public event EventHandler<UpdatedEventArgs> ProgramUpdated; | |||
public ShadowsocksController() | |||
{ | |||
_config = Configuration.Load(); | |||
@@ -90,6 +99,16 @@ namespace Shadowsocks.Controller | |||
public void Start(bool regHotkeys = true) | |||
{ | |||
if (_config.updated && regHotkeys) | |||
{ | |||
_config.updated = false; | |||
ProgramUpdated.Invoke(this, new UpdatedEventArgs() | |||
{ | |||
OldVersion = _config.version, | |||
NewVersion = UpdateChecker.Version, | |||
}); | |||
Configuration.Save(_config); | |||
} | |||
Reload(); | |||
if (regHotkeys) | |||
{ | |||
@@ -25,7 +25,7 @@ namespace Shadowsocks | |||
static void Main(string[] args) | |||
{ | |||
// .NET Framework 4.7.2 on Win7 compatibility | |||
System.Net.ServicePointManager.SecurityProtocol |= | |||
System.Net.ServicePointManager.SecurityProtocol |= | |||
System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12; | |||
// store args for further use | |||
@@ -78,18 +78,22 @@ namespace Shadowsocks | |||
return; | |||
} | |||
Directory.SetCurrentDirectory(Application.StartupPath); | |||
#if DEBUG | |||
Logging.OpenLogFile(); | |||
#if DEBUG | |||
// truncate privoxy log file while debugging | |||
string privoxyLogFilename = Utils.GetTempPath("privoxy.log"); | |||
if (File.Exists(privoxyLogFilename)) | |||
using (new FileStream(privoxyLogFilename, FileMode.Truncate)) { } | |||
#else | |||
Logging.OpenLogFile(); | |||
#endif | |||
MainController = new ShadowsocksController(); | |||
MenuController = new MenuViewController(MainController); | |||
MainController.ProgramUpdated += (o, e) => | |||
{ | |||
Logging.Info($"Updated from {e.OldVersion} to {e.NewVersion}"); | |||
}; | |||
HotKeys.Init(MainController); | |||
MainController.Start(); | |||
Application.Run(); | |||
@@ -30,7 +30,6 @@ namespace Shadowsocks.View | |||
private bool _isFirstRun; | |||
private bool _isStartupChecking; | |||
private string _urlToOpen; | |||
private bool _updated; | |||
private ContextMenu contextMenu1; | |||
private MenuItem disableItem; | |||
@@ -114,18 +113,6 @@ namespace Shadowsocks.View | |||
_isStartupChecking = true; | |||
updateChecker.CheckUpdate(config, 3000); | |||
} | |||
if (config.updated) | |||
{ | |||
ShowBalloonTip( | |||
I18N.GetString("Updated"), | |||
I18N.GetString("updated"), | |||
ToolTipIcon.Info, | |||
0 | |||
); | |||
config.updated = false; | |||
Configuration.Save(config); | |||
} | |||
} | |||
private void controller_TrafficChanged(object sender, EventArgs e) | |||
@@ -586,16 +573,6 @@ namespace Shadowsocks.View | |||
); | |||
_isFirstRun = false; | |||
} | |||
if (_updated) | |||
{ | |||
ShowBalloonTip( | |||
I18N.GetString("Updated"), | |||
I18N.GetString("updated"), | |||
ToolTipIcon.Info, | |||
0 | |||
); | |||
_updated = false; | |||
} | |||
} | |||
void proxyForm_FormClosed(object sender, FormClosedEventArgs e) | |||