This commit is contained in:
clowwindy
2014-12-20 16:56:25 +08:00
parent 254f0ef622
commit 52ca609e3e
10 changed files with 255 additions and 105 deletions
+50 -35
View File
@@ -19,7 +19,7 @@ namespace Shadowsocks.View
private ShadowsocksController controller;
private UpdateChecker updateChecker;
private NotifyIcon notifyIcon1;
private NotifyIcon _notifyIcon;
private ContextMenu contextMenu1;
private bool _isFirstRun;
@@ -44,10 +44,10 @@ namespace Shadowsocks.View
public MenuViewController(ShadowsocksController controller)
{
LoadMenu();
LoadTrayIcon();
this.controller = controller;
LoadMenu();
controller.EnableStatusChanged += controller_EnableStatusChanged;
controller.ConfigChanged += controller_ConfigChanged;
controller.PACFileReadyToOpen += controller_PACFileReadyToOpen;
@@ -55,6 +55,13 @@ namespace Shadowsocks.View
controller.EnableGlobalChanged += controller_EnableGlobalChanged;
controller.Errored += controller_Errored;
_notifyIcon = new NotifyIcon();
LoadTrayIcon();
_notifyIcon.Visible = true;
_notifyIcon.Text = I18N.GetString("Shadowsocks");
_notifyIcon.ContextMenu = contextMenu1;
_notifyIcon.DoubleClick += notifyIcon1_DoubleClick;
this.updateChecker = new UpdateChecker();
updateChecker.NewVersionFound += updateChecker_NewVersionFound;
@@ -71,7 +78,7 @@ namespace Shadowsocks.View
void controller_Errored(object sender, System.IO.ErrorEventArgs e)
{
MessageBox.Show(e.GetException().ToString(), "Error: " + e.GetException().Message);
MessageBox.Show(e.GetException().ToString(), String.Format(I18N.GetString("Shadowsocks Error: {0}"), e.GetException().Message));
}
private void LoadTrayIcon()
@@ -95,13 +102,20 @@ namespace Shadowsocks.View
{
icon = Resources.ss24;
}
notifyIcon1 = new NotifyIcon();
notifyIcon1.Text = "Shadowsocks";
notifyIcon1.Icon = Icon.FromHandle(icon.GetHicon());
notifyIcon1.Visible = true;
notifyIcon1.ContextMenu = contextMenu1;
notifyIcon1.DoubleClick +=notifyIcon1_DoubleClick;
if (!controller.GetConfiguration().enabled)
{
Bitmap iconCopy = new Bitmap(icon);
for (int x = 0; x < iconCopy.Width; x++)
{
for (int y = 0; y < iconCopy.Height; y++)
{
Color color = icon.GetPixel(x, y);
iconCopy.SetPixel(x, y , Color.FromArgb((byte)(color.A / 1.25), color.R, color.G, color.B));
}
}
icon = iconCopy;
}
_notifyIcon.Icon = Icon.FromHandle(icon.GetHicon());
}
private void LoadMenu()
@@ -146,7 +160,7 @@ namespace Shadowsocks.View
// enableItem
//
this.enableItem.Index = 0;
this.enableItem.Text = "&Enable";
this.enableItem.Text = I18N.GetString("Enable");
this.enableItem.Click += new System.EventHandler(this.EnableItem_Click);
//
// modeMenu
@@ -155,18 +169,18 @@ namespace Shadowsocks.View
this.modeItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.PACModeItem,
this.globalModeItem});
this.modeItem.Text = "Mode";
this.modeItem.Text = I18N.GetString("Mode");
//
// PACModeItem
//
this.PACModeItem.Index = 0;
this.PACModeItem.Text = "PAC";
this.PACModeItem.Text = I18N.GetString("PAC");
this.PACModeItem.Click += new System.EventHandler(this.PACModeItem_Click);
//
// globalModeItem
//
this.globalModeItem.Index = 1;
this.globalModeItem.Text = "Global";
this.globalModeItem.Text = I18N.GetString("Global");
this.globalModeItem.Click += new System.EventHandler(this.GlobalModeItem_Click);
//
// ServersItem
@@ -175,7 +189,7 @@ namespace Shadowsocks.View
this.ServersItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.SeperatorItem,
this.ConfigItem});
this.ServersItem.Text = "&Servers";
this.ServersItem.Text = I18N.GetString("Servers");
//
// SeperatorItem
//
@@ -185,7 +199,7 @@ namespace Shadowsocks.View
// ConfigItem
//
this.ConfigItem.Index = 1;
this.ConfigItem.Text = "Edit Servers...";
this.ConfigItem.Text = I18N.GetString("Edit Servers...");
this.ConfigItem.Click += new System.EventHandler(this.Config_Click);
//
// menuItem1
@@ -196,19 +210,19 @@ namespace Shadowsocks.View
// AutoStartupItem
//
this.AutoStartupItem.Index = 4;
this.AutoStartupItem.Text = "Start on Boot";
this.AutoStartupItem.Text = I18N.GetString("Start on Boot");
this.AutoStartupItem.Click += new System.EventHandler(this.AutoStartupItem_Click);
//
// ShareOverLANItem
//
this.ShareOverLANItem.Index = 5;
this.ShareOverLANItem.Text = "Share over LAN";
this.ShareOverLANItem.Text = I18N.GetString("Share over LAN");
this.ShareOverLANItem.Click += new System.EventHandler(this.ShareOverLANItem_Click);
//
// editPACFileItem
//
this.editPACFileItem.Index = 6;
this.editPACFileItem.Text = "Edit &PAC File...";
this.editPACFileItem.Text = I18N.GetString("Edit PAC File...");
this.editPACFileItem.Click += new System.EventHandler(this.EditPACFileItem_Click);
//
// menuItem4
@@ -219,19 +233,19 @@ namespace Shadowsocks.View
// QRCodeItem
//
this.QRCodeItem.Index = 8;
this.QRCodeItem.Text = "Show &QRCode...";
this.QRCodeItem.Text = I18N.GetString("Show QRCode...");
this.QRCodeItem.Click += new System.EventHandler(this.QRCodeItem_Click);
//
// ShowLogItem
//
this.ShowLogItem.Index = 9;
this.ShowLogItem.Text = "Show Logs...";
this.ShowLogItem.Text = I18N.GetString("Show Logs...");
this.ShowLogItem.Click += new System.EventHandler(this.ShowLogItem_Click);
//
// aboutItem
//
this.aboutItem.Index = 10;
this.aboutItem.Text = "About...";
this.aboutItem.Text = I18N.GetString("About...");
this.aboutItem.Click += new System.EventHandler(this.AboutItem_Click);
//
// menuItem3
@@ -242,7 +256,7 @@ namespace Shadowsocks.View
// quitItem
//
this.quitItem.Index = 12;
this.quitItem.Text = "&Quit";
this.quitItem.Text = I18N.GetString("Quit");
this.quitItem.Click += new System.EventHandler(this.Quit_Click);
}
@@ -254,6 +268,7 @@ namespace Shadowsocks.View
private void controller_EnableStatusChanged(object sender, EventArgs e)
{
enableItem.Checked = controller.GetConfiguration().enabled;
LoadTrayIcon();
}
void controller_ShareOverLANStatusChanged(object sender, EventArgs e)
@@ -276,11 +291,11 @@ namespace Shadowsocks.View
void updateChecker_NewVersionFound(object sender, EventArgs e)
{
notifyIcon1.BalloonTipTitle = "Shadowsocks " + updateChecker.LatestVersionNumber + " Update Found";
notifyIcon1.BalloonTipText = "Click here to download";
notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
notifyIcon1.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
notifyIcon1.ShowBalloonTip(5000);
_notifyIcon.BalloonTipTitle = String.Format(I18N.GetString("Shadowsocks {0} Update Found"), updateChecker.LatestVersionNumber);
_notifyIcon.BalloonTipText = I18N.GetString("Click here to download");
_notifyIcon.BalloonTipIcon = ToolTipIcon.Info;
_notifyIcon.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
_notifyIcon.ShowBalloonTip(5000);
_isFirstRun = false;
}
@@ -354,7 +369,7 @@ namespace Shadowsocks.View
private void Quit_Click(object sender, EventArgs e)
{
controller.Stop();
notifyIcon1.Visible = false;
_notifyIcon.Visible = false;
Application.Exit();
}
@@ -362,10 +377,10 @@ namespace Shadowsocks.View
{
if (_isFirstRun)
{
notifyIcon1.BalloonTipTitle = "Shadowsocks is here";
notifyIcon1.BalloonTipText = "You can turn on/off Shadowsocks in the context menu";
notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
notifyIcon1.ShowBalloonTip(0);
_notifyIcon.BalloonTipTitle = I18N.GetString("Shadowsocks is here");
_notifyIcon.BalloonTipText = I18N.GetString("You can turn on/off Shadowsocks in the context menu");
_notifyIcon.BalloonTipIcon = ToolTipIcon.Info;
_notifyIcon.ShowBalloonTip(0);
_isFirstRun = false;
}
}