Browse Source

Invoke EventHandler instead of show balloon tip when updated

tags/4.1.9.3
Student Main 5 years ago
parent
commit
13a3471fa3
3 changed files with 28 additions and 28 deletions
  1. +19
    -0
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  2. +9
    -5
      shadowsocks-csharp/Program.cs
  3. +0
    -23
      shadowsocks-csharp/View/MenuViewController.cs

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

@@ -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)
{


+ 9
- 5
shadowsocks-csharp/Program.cs View File

@@ -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();


+ 0
- 23
shadowsocks-csharp/View/MenuViewController.cs View File

@@ -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)


Loading…
Cancel
Save