Ejemplo n.º 1
0
        private void UpdateTrayIconAndNotifyText()
        {
            Configuration config  = controller.GetConfigurationCopy();
            bool          enabled = config.enabled;
            bool          global  = config.global;

            Color colorMask = SelectColorMask(enabled, global);
            Size  iconSize  = SelectIconSize();

            UpdateIconSet(colorMask, iconSize, out icon, out icon_in, out icon_out, out icon_both);

            previousIcon     = icon;
            _notifyIcon.Icon = previousIcon;

            string serverInfo = null;

            if (controller.GetCurrentStrategy() != null)
            {
                serverInfo = controller.GetCurrentStrategy().Name;
            }
            else
            {
                serverInfo = config.GetCurrentServer().FriendlyName();
            }
            // show more info by hacking the P/Invoke declaration for NOTIFYICONDATA inside Windows Forms
            string text = I18N.GetString("TenonVPN") + " " + P2pLib.kCurrentVersion;

            if (text.Length > 127)
            {
                text = text.Substring(0, 126 - 3) + "...";
            }
            ViewUtils.SetNotifyIconText(_notifyIcon, text);
        }
        private void UpdateTrayIcon()
        {
            int      dpi;
            Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);

            dpi = (int)graphics.DpiX;
            graphics.Dispose();
            icon_baseBitmap = null;
            if (dpi < 97)
            {
                // dpi = 96;
                icon_baseBitmap = Resources.ss16;
            }
            else if (dpi < 121)
            {
                // dpi = 120;
                icon_baseBitmap = Resources.ss20;
            }
            else if (dpi < 192)
            {
                // dpi = 120;
                icon_baseBitmap = Resources.ss24;
            }
            else
            {
                icon_baseBitmap = Resources.ss48;
            }
            Configuration config  = controller.GetConfigurationCopy();
            bool          enabled = config.enabled;
            bool          global  = config.global;

            icon_baseBitmap = getTrayIconByState(icon_baseBitmap, enabled, global);

            icon_base        = Icon.FromHandle(icon_baseBitmap.GetHicon());
            targetIcon       = icon_base;
            icon_in          = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, dpi > 190 ? Resources.ssIn48 : Resources.ssIn24).GetHicon());
            icon_out         = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, dpi > 190 ? Resources.ssOut48 : Resources.ssOut24).GetHicon());
            icon_both        = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, dpi > 190 ? Resources.ssIn48 : Resources.ssIn24, dpi > 190 ? Resources.ssOut48 : Resources.ssOut24).GetHicon());
            _notifyIcon.Icon = targetIcon;

            string serverInfo = null;

            if (controller.GetCurrentStrategy() != null)
            {
                serverInfo = controller.GetCurrentStrategy().Name;
            }
            else
            {
                serverInfo = config.GetCurrentServer().FriendlyName();
            }
            // show more info by hacking the P/Invoke declaration for NOTIFYICONDATA inside Windows Forms
            string text = I18N.GetString("Shadowsocks") + " " + Program.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;

            _notifyIcon.SetNotifyIconText(text);
        }
Ejemplo n.º 3
0
        private void UpdateTrayIcon()
        {
            int      dpi;
            Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);

            dpi = (int)graphics.DpiX;
            graphics.Dispose();
            icon_baseBitmap = null;
            if (dpi < 97)
            {
                // dpi = 96;
                icon_baseBitmap = Resources.ss16;
            }
            else if (dpi < 121)
            {
                // dpi = 120;
                icon_baseBitmap = Resources.ss20;
            }
            else
            {
                icon_baseBitmap = Resources.ss24;
            }
            Configuration config  = controller.GetConfigurationCopy();
            bool          enabled = config.enabled;
            bool          global  = config.global;

            icon_baseBitmap = getTrayIconByState(icon_baseBitmap, enabled, global);

            icon_base        = Icon.FromHandle(icon_baseBitmap.GetHicon());
            targetIcon       = icon_base;
            icon_in          = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, Resources.ssIn24).GetHicon());
            icon_out         = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, Resources.ssOut24).GetHicon());
            icon_both        = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, Resources.ssIn24, Resources.ssOut24).GetHicon());
            _notifyIcon.Icon = targetIcon;

            string serverInfo = null;

            if (controller.GetCurrentStrategy() != null)
            {
                serverInfo = controller.GetCurrentStrategy().Name;
            }
            else
            {
                serverInfo = config.GetCurrentServer().FriendlyName();
            }

            var user = controller.GetCurrentUser();

            // we want to show more details but notify icon title is limited to 63 characters
            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" + "登录时剩余流量:" + Format(user.transfer_enable - user.d - user.u)
                          + "\n" + serverInfo;

            //text +=
            _notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length));
        }
Ejemplo n.º 4
0
        private void UpdateTrayIcon()
        {
            int      dpi, icon_baseSize;
            Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);

            dpi = (int)graphics.DpiX;
            graphics.Dispose();
            //icon_baseBitmap = null;

            Configuration config  = controller.GetFreshConfiguration();
            bool          enabled = config.enabled;
            bool          global  = config.global;

            //icon_baseBitmap = getTrayIconByState(icon_base.ToBitmap(), enabled, global);

            if (!enabled)
            {
                icon_base = Resources.icon_32_g;
            }
            else
            {
                icon_base = Resources.icon_32_b;
                icon_in   = Resources.icon_32_d;
                icon_out  = Resources.icon_32_u;
                icon_both = Resources.icon_32_ud;
            }

            _notifyIcon.Icon = icon_base;
            // Bug: System.Runtime.IneropServices.ExternalExeption

            string serverInfo = null;

            if (controller.GetCurrentStrategy() != null)
            {
                serverInfo = controller.GetCurrentStrategy().Name;
            }
            else
            {
                serverInfo = config.GetCurrentServer().FriendlyName();
            }
            // we want to show more details but notify icon title is limited to 63 characters
            string text = I18N.GetString("Rallets") + " " + Util.Utils.getCurrentVersion() + "\n"
                          + this.TrafficItem.Text
                          + (enabled ?
                             I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global Mode") : I18N.GetString("Smart Mode")) :
                             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));
        }
Ejemplo n.º 5
0
 private void LogWhenEnabled(string log)
 {
     if (_controller.GetCurrentStrategy()?.ID == ID) //output when enabled
     {
         Console.WriteLine(log);
     }
 }
Ejemplo n.º 6
0
        private void ChooseNewServer(List <Server> servers)
        {
            if (statistics == null)
            {
                return;
            }
            try
            {
                var bestResult = (from server in servers
                                  let name = server.FriendlyName()
                                             where statistics.ContainsKey(name)
                                             select new
                {
                    server,
                    score = GetScore(statistics[name])
                }
                                  ).Aggregate((result1, result2) => result1.score > result2.score ? result1 : result2);

                if (_controller.GetCurrentStrategy().ID == ID && _currentServer != bestResult.server) //output when enabled
                {
                    Console.WriteLine("Switch to server: {0} by package loss:{1}", bestResult.server.FriendlyName(), 1 - bestResult.score);
                }
                _currentServer = bestResult.server;
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
            }
        }
Ejemplo n.º 7
0
        private void UpdateTrayIcon()
        {
            int      dpi;
            Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);

            dpi = (int)graphics.DpiX;
            graphics.Dispose();
            Bitmap icon = null;

            if (dpi < 97)
            {
                // dpi = 96;
                icon = Resources.ss16;
            }
            else if (dpi < 121)
            {
                // dpi = 120;
                icon = Resources.ss20;
            }
            else
            {
                icon = Resources.ss24;
            }
            Configuration config = controller.GetConfigurationCopy();

            _notifyIcon.Icon = Icon.FromHandle(icon.GetHicon());

            string serverInfo = null;

            if (controller.GetCurrentStrategy() != null)
            {
                serverInfo = controller.GetCurrentStrategy().Name;
            }
            else
            {
                serverInfo = config.GetCurrentServer().FriendlyName();
            }
            // we want to show more details but notify icon title is limited to 63 characters
            string text = I18N.GetString("Shadowsocks") + " " + AppVersion.Version + "\n" +
                          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));
        }
Ejemplo n.º 8
0
        private void destConnectTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var timer = (ServerTimer)sender;

            timer.Elapsed -= destConnectTimer_Elapsed;
            timer.Enabled  = false;
            timer.Dispose();

            if (_destConnected || Closed)
            {
                return;
            }

            var       session  = timer.Session;
            Server    server   = timer.Server;
            IStrategy strategy = _controller.GetCurrentStrategy();

            strategy?.SetFailure(server);
            Logging.Info($"{server.FriendlyName()} timed out");
            session.Remote.Close();
            Close();
        }
        private void UpdateTrayIconAndNotifyText()
        {
            Configuration config  = controller.GetConfigurationCopy();
            bool          enabled = config.enabled;
            bool          global  = config.global;

            Color colorMask = SelectColorMask(enabled, global);
            Size  iconSize  = SelectIconSize();

            UpdateIconSet(colorMask, iconSize, out icon, out icon_in, out icon_out, out icon_both);

            previousIcon     = icon;
            _notifyIcon.Icon = previousIcon;

            string serverInfo = null;

            if (controller.GetCurrentStrategy() != null)
            {
                serverInfo = controller.GetCurrentStrategy().Name;
            }
            else
            {
                serverInfo = config.GetCurrentServer().FriendlyName();
            }
            // show more info by hacking the P/Invoke declaration for NOTIFYICONDATA inside Windows Forms
            string text = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version + "\n" +
                          (enabled ?
                           I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) :
                           I18N.GetString("Running: Port {0}", config.localPort))     // this feedback is very important because they need to know Shadowsocks is running
                          + "\n" + serverInfo;

            if (text.Length > 127)
            {
                text = text.Substring(0, 126 - 3) + "...";
            }
            ViewUtils.SetNotifyIconText(_notifyIcon, text);
        }
Ejemplo n.º 10
0
        private void UpdateTrayIcon()
        {
            int      dpi;
            Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);

            dpi = (int)graphics.DpiX;
            graphics.Dispose();
            icon_baseBitmap = null;
            if (dpi < 97)
            {
                // dpi = 96;
                icon_baseBitmap = Resources.ss16;
            }
            else if (dpi < 121)
            {
                // dpi = 120;
                icon_baseBitmap = Resources.ss20;
            }
            else
            {
                icon_baseBitmap = Resources.ss24;
            }
            Configuration config  = controller.GetConfigurationCopy();
            bool          enabled = config.enabled;
            bool          global  = config.global;

            // set Windows 10 Theme color (1903+)
            currentWindowsThemeMode = Utils.GetWindows10SystemThemeSetting();

            if (currentWindowsThemeMode == Utils.WindowsThemeMode.Light)
            {
                if (!global || !enabled)
                {
                    icon_baseBitmap = getDarkTrayIcon(icon_baseBitmap);
                }
            }

            icon_baseBitmap = getTrayIconByState(icon_baseBitmap, enabled, global);

            icon_base        = Icon.FromHandle(icon_baseBitmap.GetHicon());
            targetIcon       = icon_base;
            icon_in          = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, Resources.ssIn24).GetHicon());
            icon_out         = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, Resources.ssOut24).GetHicon());
            icon_both        = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, Resources.ssIn24, Resources.ssOut24).GetHicon());
            _notifyIcon.Icon = targetIcon;

            string serverInfo = null;

            if (controller.GetCurrentStrategy() != null)
            {
                serverInfo = controller.GetCurrentStrategy().Name;
            }
            else
            {
                serverInfo = config.GetCurrentServer().FriendlyName();
            }
            // show more info by hacking the P/Invoke declaration for NOTIFYICONDATA inside Windows Forms
            string text = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version + "\n" +
                          (enabled ?
                           I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) :
                           I18N.GetString("Running: Port {0}", config.localPort))     // this feedback is very important because they need to know Shadowsocks is running
                          + "\n" + serverInfo;

            if (text.Length > 127)
            {
                text = text.Substring(0, 126 - 3) + "...";
            }
            ViewUtils.SetNotifyIconText(_notifyIcon, text);
        }
Ejemplo n.º 11
0
        private void UpdateTrayIcon()
        {
            int      dpi;
            Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);

            dpi = (int)graphics.DpiX;
            graphics.Dispose();
            Bitmap icon = null;

            if (dpi < 97)
            {
                // dpi = 96;
                icon = Resources.ss16;
            }
            else if (dpi < 121)
            {
                // dpi = 120;
                icon = Resources.ss20;
            }
            else
            {
                icon = Resources.ss24;
            }
            Configuration config  = controller.GetConfigurationCopy();
            bool          enabled = config.enabled;
            bool          global  = config.global;

            if (!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());

            string serverInfo = null;

            if (controller.GetCurrentStrategy() != null)
            {
                serverInfo = controller.GetCurrentStrategy().Name;
            }
            else
            {
                serverInfo = config.GetCurrentServer().FriendlyName();
            }
            // we want to show more details but notify icon title is limited to 63 characters
            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;

            _notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length));
        }
        private void UpdateTrayIcon()
        {
            int      dpi;
            Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);

            dpi = (int)graphics.DpiX;
            graphics.Dispose();
            icon_baseBitmap = null;
            if (dpi < 97)
            {
                // dpi = 96;
                icon_baseBitmap = Resources.ss16;
            }
            else if (dpi < 121)
            {
                // dpi = 120;
                icon_baseBitmap = Resources.ss20;
            }
            else
            {
                icon_baseBitmap = Resources.ss24;
            }
            Configuration config  = controller.GetConfigurationCopy();
            bool          enabled = config.enabled;
            bool          global  = config.global;

            icon_baseBitmap = getTrayIconByState(icon_baseBitmap, enabled, global);

            icon_base        = Icon.FromHandle(icon_baseBitmap.GetHicon());
            targetIcon       = icon_base;
            icon_in          = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, Resources.ssIn24).GetHicon());
            icon_out         = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, Resources.ssOut24).GetHicon());
            icon_both        = Icon.FromHandle(AddBitmapOverlay(icon_baseBitmap, Resources.ssIn24, Resources.ssOut24).GetHicon());
            _notifyIcon.Icon = targetIcon;

            string serverInfo = null;

            if (controller.GetCurrentStrategy() != null)
            {
                serverInfo = controller.GetCurrentStrategy().Name;
            }
            else
            {
                /************************************<Start> Edit by Ian.May, Oct.18*****************************************/
                //used for patially display channel infomation
                //serverInfo = config.GetCurrentServer().FriendlyName();
                serverInfo = config.GetCurrentServer().FriendlyName(controller.isShadowFogMode);
            }
            // show more info by hacking the P/Invoke declaration for NOTIFYICONDATA inside Windows Forms
            //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;
            string text;

            if (!controller.isShadowFogMode)
            {
                // we want to show more details but notify icon title is limited to 63 characters
                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;
            }
            else
            {
                // this trayIcon update only execute when controller.config is changed, so it's not associated with the fogmodetoggle checkbox, but tha's ok;
                text = I18N.GetString("ShadowFog") + " " + UpdateChecker.ShadowFogVersion + "\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;
            }
            //Ends
            /**************************************<End> Edit by Ian.May, Oct.18*****************************************/
            ViewUtils.SetNotifyIconText(_notifyIcon, text);
        }