Esempio n. 1
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));
        }
Esempio n. 2
0
 public static bool Authed(this ShadowsocksController controller)
 {
     return(controller.GetCurrentUser() != null);
 }