Browse Source

change controller status if needed

- Change controller based on power mode
- Stop before exiting

Based on GangZhuo's code

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
tags/3.3.1
Syrone Wong 8 years ago
parent
commit
ab464ca8b1
1 changed files with 30 additions and 1 deletions
  1. +30
    -1
      shadowsocks-csharp/Program.cs

+ 30
- 1
shadowsocks-csharp/Program.cs View File

@@ -3,6 +3,7 @@ using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using Microsoft.Win32;
using Shadowsocks.Controller;
using Shadowsocks.Util;
@@ -12,6 +13,8 @@ namespace Shadowsocks
{
static class Program
{
static ShadowsocksController controller;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
@@ -30,6 +33,8 @@ namespace Shadowsocks
using (Mutex mutex = new Mutex(false, "Global\\Shadowsocks_" + Application.StartupPath.GetHashCode()))
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.ApplicationExit += Application_ApplicationExit;
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
@@ -56,7 +61,7 @@ namespace Shadowsocks
#else
Logging.OpenLogFile();
#endif
ShadowsocksController controller = new ShadowsocksController();
controller = new ShadowsocksController();
MenuViewController viewController = new MenuViewController(controller);
controller.Start();
Application.Run();
@@ -76,5 +81,29 @@ namespace Shadowsocks
Application.Exit();
}
}
private static void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
switch (e.Mode)
{
case PowerModes.Resume:
Logging.Info("os wake up");
controller?.Start();
break;
case PowerModes.Suspend:
controller?.Stop();
Logging.Info("os suspend");
break;
}
}
private static void Application_ApplicationExit(object sender, EventArgs e)
{
if (controller != null)
{
controller.Stop();
controller = null;
}
}
}
}

Loading…
Cancel
Save