- Only use one instance of LogForm Signed-off-by: Syrone Wong <wong.syrone@gmail.com>tags/3.3.1
@@ -348,18 +348,30 @@ namespace Shadowsocks.Controller | |||||
{ | { | ||||
_config.autoCheckUpdate = enabled; | _config.autoCheckUpdate = enabled; | ||||
Configuration.Save(_config); | Configuration.Save(_config); | ||||
if (ConfigChanged != null) | |||||
{ | |||||
ConfigChanged(this, new EventArgs()); | |||||
} | |||||
} | } | ||||
public void SaveLogViewerConfig(LogViewerConfig newConfig) | public void SaveLogViewerConfig(LogViewerConfig newConfig) | ||||
{ | { | ||||
_config.logViewer = newConfig; | _config.logViewer = newConfig; | ||||
Configuration.Save(_config); | Configuration.Save(_config); | ||||
if (ConfigChanged != null) | |||||
{ | |||||
ConfigChanged(this, new EventArgs()); | |||||
} | |||||
} | } | ||||
public void SaveProxyConfig(ProxyConfig newConfig) | public void SaveProxyConfig(ProxyConfig newConfig) | ||||
{ | { | ||||
_config.proxy = newConfig; | _config.proxy = newConfig; | ||||
Configuration.Save(_config); | Configuration.Save(_config); | ||||
if (ConfigChanged != null) | |||||
{ | |||||
ConfigChanged(this, new EventArgs()); | |||||
} | |||||
} | } | ||||
public void UpdateLatency(Server server, TimeSpan latency) | public void UpdateLatency(Server server, TimeSpan latency) | ||||
@@ -56,6 +56,10 @@ namespace Shadowsocks.Model | |||||
config.localPort = 1080; | config.localPort = 1080; | ||||
if (config.index == -1 && config.strategy == null) | if (config.index == -1 && config.strategy == null) | ||||
config.index = 0; | config.index = 0; | ||||
if (config.logViewer == null) | |||||
config.logViewer = new LogViewerConfig(); | |||||
if (config.proxy == null) | |||||
config.proxy = new ProxyConfig(); | |||||
return config; | return config; | ||||
} | } | ||||
catch (Exception e) | catch (Exception e) | ||||
@@ -13,7 +13,9 @@ namespace Shadowsocks | |||||
{ | { | ||||
static class Program | static class Program | ||||
{ | { | ||||
static ShadowsocksController controller; | |||||
private static ShadowsocksController _controller; | |||||
// XXX: Don't change this name | |||||
private static MenuViewController _viewController; | |||||
/// <summary> | /// <summary> | ||||
/// 应用程序的主入口点。 | /// 应用程序的主入口点。 | ||||
@@ -61,9 +63,9 @@ namespace Shadowsocks | |||||
#else | #else | ||||
Logging.OpenLogFile(); | Logging.OpenLogFile(); | ||||
#endif | #endif | ||||
controller = new ShadowsocksController(); | |||||
MenuViewController viewController = new MenuViewController(controller); | |||||
controller.Start(); | |||||
_controller = new ShadowsocksController(); | |||||
_viewController = new MenuViewController(_controller); | |||||
_controller.Start(); | |||||
Application.Run(); | Application.Run(); | ||||
} | } | ||||
} | } | ||||
@@ -88,10 +90,10 @@ namespace Shadowsocks | |||||
{ | { | ||||
case PowerModes.Resume: | case PowerModes.Resume: | ||||
Logging.Info("os wake up"); | Logging.Info("os wake up"); | ||||
controller?.Start(); | |||||
_controller?.Start(); | |||||
break; | break; | ||||
case PowerModes.Suspend: | case PowerModes.Suspend: | ||||
controller?.Stop(); | |||||
_controller?.Stop(); | |||||
Logging.Info("os suspend"); | Logging.Info("os suspend"); | ||||
break; | break; | ||||
} | } | ||||
@@ -99,10 +101,10 @@ namespace Shadowsocks | |||||
private static void Application_ApplicationExit(object sender, EventArgs e) | private static void Application_ApplicationExit(object sender, EventArgs e) | ||||
{ | { | ||||
if (controller != null) | |||||
if (_controller != null) | |||||
{ | { | ||||
controller.Stop(); | |||||
controller = null; | |||||
_controller.Stop(); | |||||
_controller = null; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -35,19 +35,13 @@ namespace Shadowsocks.View | |||||
Icon = Icon.FromHandle(Resources.ssw128.GetHicon()); | Icon = Icon.FromHandle(Resources.ssw128.GetHicon()); | ||||
LogViewerConfig config = controller.GetConfigurationCopy().logViewer; | LogViewerConfig config = controller.GetConfigurationCopy().logViewer; | ||||
if (config == null) | |||||
{ | |||||
config = new LogViewerConfig(); | |||||
} | |||||
else | |||||
{ | |||||
topMostTrigger = config.topMost; | |||||
wrapTextTrigger = config.wrapText; | |||||
toolbarTrigger = config.toolbarShown; | |||||
LogMessageTextBox.BackColor = config.GetBackgroundColor(); | |||||
LogMessageTextBox.ForeColor = config.GetTextColor(); | |||||
LogMessageTextBox.Font = config.GetFont(); | |||||
} | |||||
topMostTrigger = config.topMost; | |||||
wrapTextTrigger = config.wrapText; | |||||
toolbarTrigger = config.toolbarShown; | |||||
LogMessageTextBox.BackColor = config.GetBackgroundColor(); | |||||
LogMessageTextBox.ForeColor = config.GetTextColor(); | |||||
LogMessageTextBox.Font = config.GetFont(); | |||||
controller.TrafficChanged += controller_TrafficChanged; | controller.TrafficChanged += controller_TrafficChanged; | ||||
@@ -219,8 +213,7 @@ namespace Shadowsocks.View | |||||
timer.Start(); | timer.Start(); | ||||
LogViewerConfig config = controller.GetConfigurationCopy().logViewer; | LogViewerConfig config = controller.GetConfigurationCopy().logViewer; | ||||
if (config == null) | |||||
config = new LogViewerConfig(); | |||||
Height = config.height; | Height = config.height; | ||||
Width = config.width; | Width = config.width; | ||||
Top = config.GetBestTop(); | Top = config.GetBestTop(); | ||||
@@ -246,8 +239,7 @@ namespace Shadowsocks.View | |||||
timer.Stop(); | timer.Stop(); | ||||
controller.TrafficChanged -= controller_TrafficChanged; | controller.TrafficChanged -= controller_TrafficChanged; | ||||
LogViewerConfig config = controller.GetConfigurationCopy().logViewer; | LogViewerConfig config = controller.GetConfigurationCopy().logViewer; | ||||
if (config == null) | |||||
config = new LogViewerConfig(); | |||||
config.topMost = topMostTrigger; | config.topMost = topMostTrigger; | ||||
config.wrapText = wrapTextTrigger; | config.wrapText = wrapTextTrigger; | ||||
config.toolbarShown = toolbarTrigger; | config.toolbarShown = toolbarTrigger; | ||||
@@ -52,8 +52,7 @@ namespace Shadowsocks.View | |||||
private MenuItem VerboseLoggingToggleItem; | private MenuItem VerboseLoggingToggleItem; | ||||
private ConfigForm configForm; | private ConfigForm configForm; | ||||
private ProxyForm proxyForm; | private ProxyForm proxyForm; | ||||
private List<LogForm> logForms = new List<LogForm>(); | |||||
private bool logFormsVisible = false; | |||||
private LogForm logForm; | |||||
private string _urlToOpen; | private string _urlToOpen; | ||||
public MenuViewController(ShadowsocksController controller) | public MenuViewController(ShadowsocksController controller) | ||||
@@ -133,6 +132,8 @@ namespace Shadowsocks.View | |||||
MessageBox.Show(e.GetException().ToString(), String.Format(I18N.GetString("Shadowsocks Error: {0}"), e.GetException().Message)); | MessageBox.Show(e.GetException().ToString(), String.Format(I18N.GetString("Shadowsocks Error: {0}"), e.GetException().Message)); | ||||
} | } | ||||
#region Tray Icon | |||||
private void UpdateTrayIcon() | private void UpdateTrayIcon() | ||||
{ | { | ||||
int dpi; | int dpi; | ||||
@@ -177,10 +178,10 @@ namespace Shadowsocks.View | |||||
} | } | ||||
// we want to show more details but notify icon title is limited to 63 characters | // we want to show more details but notify icon title is limited to 63 characters | ||||
string text = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version + "\n" + | string text = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version + "\n" + | ||||
(enabled ? | |||||
I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) : | |||||
String.Format(I18N.GetString("Running: Port {0}"), config.localPort)) // this feedback is very important because they need to know Shadowsocks is running | |||||
+ "\n" + serverInfo; | |||||
(enabled ? | |||||
I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) : | |||||
String.Format(I18N.GetString("Running: Port {0}"), config.localPort)) // this feedback is very important because they need to know Shadowsocks is running | |||||
+ "\n" + serverInfo; | |||||
_notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length)); | _notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length)); | ||||
} | } | ||||
@@ -201,7 +202,7 @@ namespace Shadowsocks.View | |||||
else if (global) | else if (global) | ||||
{ | { | ||||
Color flyBlue = Color.FromArgb(25, 125, 191); | Color flyBlue = Color.FromArgb(25, 125, 191); | ||||
// Muliply with flyBlue | |||||
// Multiply with flyBlue | |||||
int red = color.R * flyBlue.R / 255; | int red = color.R * flyBlue.R / 255; | ||||
int green = color.G * flyBlue.G / 255; | int green = color.G * flyBlue.G / 255; | ||||
int blue = color.B * flyBlue.B / 255; | int blue = color.B * flyBlue.B / 255; | ||||
@@ -230,6 +231,10 @@ namespace Shadowsocks.View | |||||
return bitmap; | return bitmap; | ||||
} | } | ||||
#endregion | |||||
#region MenuItems and MenuGroups | |||||
private MenuItem CreateMenuItem(string text, EventHandler click) | private MenuItem CreateMenuItem(string text, EventHandler click) | ||||
{ | { | ||||
return new MenuItem(I18N.GetString(text), click); | return new MenuItem(I18N.GetString(text), click); | ||||
@@ -282,6 +287,8 @@ namespace Shadowsocks.View | |||||
}); | }); | ||||
} | } | ||||
#endregion | |||||
private void controller_ConfigChanged(object sender, EventArgs e) | private void controller_ConfigChanged(object sender, EventArgs e) | ||||
{ | { | ||||
LoadCurrentConfiguration(); | LoadCurrentConfiguration(); | ||||
@@ -406,7 +413,7 @@ namespace Shadowsocks.View | |||||
i++; | i++; | ||||
} | } | ||||
// user want a seperator item between strategy and servers menugroup | |||||
// user wants a seperator item between strategy and servers menugroup | |||||
items.Add( i++, new MenuItem("-") ); | items.Add( i++, new MenuItem("-") ); | ||||
int strategyCount = i; | int strategyCount = i; | ||||
@@ -459,31 +466,25 @@ namespace Shadowsocks.View | |||||
} | } | ||||
} | } | ||||
private void ShowLogForms() | |||||
private void ShowLogForm() | |||||
{ | { | ||||
if (logForms.Count == 0) | |||||
if (logForm != null) | |||||
{ | { | ||||
LogForm f = new LogForm(controller, Logging.LogFilePath); | |||||
f.Show(); | |||||
f.Activate(); | |||||
f.FormClosed += logForm_FormClosed; | |||||
logForms.Add(f); | |||||
logFormsVisible = true; | |||||
logForm.Activate(); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
logFormsVisible = !logFormsVisible; | |||||
foreach (LogForm f in logForms) | |||||
{ | |||||
f.Visible = logFormsVisible; | |||||
} | |||||
logForm = new LogForm(controller, Logging.LogFilePath); | |||||
logForm.Show(); | |||||
logForm.Activate(); | |||||
logForm.FormClosed += logForm_FormClosed; | |||||
} | } | ||||
} | } | ||||
void logForm_FormClosed(object sender, FormClosedEventArgs e) | void logForm_FormClosed(object sender, FormClosedEventArgs e) | ||||
{ | { | ||||
logForms.Remove((LogForm)sender); | |||||
logForm = null; | |||||
Utils.ReleaseMemory(true); | |||||
} | } | ||||
void configForm_FormClosed(object sender, FormClosedEventArgs e) | void configForm_FormClosed(object sender, FormClosedEventArgs e) | ||||
@@ -519,11 +520,9 @@ namespace Shadowsocks.View | |||||
private void CheckUpdateForFirstRun() | private void CheckUpdateForFirstRun() | ||||
{ | { | ||||
Configuration config = controller.GetConfigurationCopy(); | Configuration config = controller.GetConfigurationCopy(); | ||||
if (!config.isDefault) | |||||
{ | |||||
_isStartupChecking = true; | |||||
updateChecker.CheckUpdate(config, 3000); | |||||
} | |||||
if (config.isDefault) return; | |||||
_isStartupChecking = true; | |||||
updateChecker.CheckUpdate(config, 3000); | |||||
} | } | ||||
private void ShowFirstTimeBalloon() | private void ShowFirstTimeBalloon() | ||||
@@ -547,7 +546,7 @@ namespace Shadowsocks.View | |||||
} | } | ||||
else if (e.Button == MouseButtons.Middle) | else if (e.Button == MouseButtons.Middle) | ||||
{ | { | ||||
ShowLogForms(); | |||||
ShowLogForm(); | |||||
} | } | ||||
} | } | ||||
@@ -607,15 +606,6 @@ namespace Shadowsocks.View | |||||
controller.SelectStrategy((string)item.Tag); | controller.SelectStrategy((string)item.Tag); | ||||
} | } | ||||
private void ShowLogItem_Click(object sender, EventArgs e) | |||||
{ | |||||
LogForm f = new LogForm(controller, Logging.LogFilePath); | |||||
f.Show(); | |||||
f.FormClosed += logForm_FormClosed; | |||||
logForms.Add(f); | |||||
} | |||||
private void VerboseLoggingToggleItem_Click( object sender, EventArgs e ) { | private void VerboseLoggingToggleItem_Click( object sender, EventArgs e ) { | ||||
VerboseLoggingToggleItem.Checked = ! VerboseLoggingToggleItem.Checked; | VerboseLoggingToggleItem.Checked = ! VerboseLoggingToggleItem.Checked; | ||||
controller.ToggleVerboseLogging( VerboseLoggingToggleItem.Checked ); | controller.ToggleVerboseLogging( VerboseLoggingToggleItem.Checked ); | ||||
@@ -820,5 +810,10 @@ namespace Shadowsocks.View | |||||
{ | { | ||||
ShowProxyForm(); | ShowProxyForm(); | ||||
} | } | ||||
private void ShowLogItem_Click(object sender, EventArgs e) | |||||
{ | |||||
ShowLogForm(); | |||||
} | |||||
} | } | ||||
} | } |
@@ -47,11 +47,6 @@ namespace Shadowsocks.View | |||||
private void LoadCurrentConfiguration() | private void LoadCurrentConfiguration() | ||||
{ | { | ||||
_modifiedConfiguration = controller.GetConfigurationCopy().proxy; | _modifiedConfiguration = controller.GetConfigurationCopy().proxy; | ||||
if (_modifiedConfiguration == null) | |||||
{ | |||||
_modifiedConfiguration = new ProxyConfig(); | |||||
controller.SaveProxyConfig(_modifiedConfiguration); | |||||
} | |||||
UseProxyCheckBox.Checked = _modifiedConfiguration.useProxy; | UseProxyCheckBox.Checked = _modifiedConfiguration.useProxy; | ||||
ProxyServerTextBox.Text = _modifiedConfiguration.proxyServer; | ProxyServerTextBox.Text = _modifiedConfiguration.proxyServer; | ||||
ProxyPortTextBox.Text = _modifiedConfiguration.proxyPort.ToString(); | ProxyPortTextBox.Text = _modifiedConfiguration.proxyPort.ToString(); | ||||