Exemple #1
0
        public MenuViewController(ShadowsocksController controller)
        {
            this.controller = controller;

            LoadMenu();

            controller.EnableStatusChanged       += controller_EnableStatusChanged;
            controller.ConfigChanged             += controller_ConfigChanged;
            controller.PACFileReadyToOpen        += controller_FileReadyToOpen;
            controller.UserRuleFileReadyToOpen   += controller_FileReadyToOpen;
            controller.ShareOverLANStatusChanged += controller_ShareOverLANStatusChanged;
            controller.EnableGlobalChanged       += controller_EnableGlobalChanged;
            controller.Errored += controller_Errored;
            controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
            controller.UpdatePACFromGFWListError     += controller_UpdatePACFromGFWListError;

            _notifyIcon = new NotifyIcon();
            UpdateTrayIcon();
            _notifyIcon.Visible           = true;
            _notifyIcon.ContextMenu       = contextMenu1;
            _notifyIcon.MouseDoubleClick += notifyIcon1_DoubleClick;

            LoadCurrentConfiguration();

            if (controller.GetConfigurationCopy().isDefault)
            {
                _isFirstRun = true;
                ShowConfigForm();
            }
        }
Exemple #2
0
        public LogForm(ShadowsocksController controller, string filename)
        {
            this.controller = controller;
            this.filename   = filename;
            InitializeComponent();
            Icon = Icon.FromHandle(Resources.ssw128.GetHicon());

            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();
            }

            controller.TrafficChanged += controller_TrafficChanged;

            UpdateTexts();
        }
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration          = controller.GetConfigurationCopy().proxy;
     UseProxyCheckBox.Checked        = _modifiedConfiguration.useProxy;
     ProxyServerTextBox.Text         = _modifiedConfiguration.proxyServer;
     ProxyPortTextBox.Text           = _modifiedConfiguration.proxyPort.ToString();
     ProxyTypeComboBox.SelectedIndex = _modifiedConfiguration.proxyType;
 }
Exemple #4
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));
        }
        public MenuViewController(ShadowsocksController controller)
        {
            this.controller = controller;

            LoadMenu();

            controller.EnableStatusChanged         += controller_EnableStatusChanged;
            controller.ConfigChanged               += controller_ConfigChanged;
            controller.PACFileReadyToOpen          += controller_FileReadyToOpen;
            controller.UserRuleFileReadyToOpen     += controller_FileReadyToOpen;
            controller.ShareOverLANStatusChanged   += controller_ShareOverLANStatusChanged;
            controller.VerboseLoggingStatusChanged += controller_VerboseLoggingStatusChanged;
            controller.EnableGlobalChanged         += controller_EnableGlobalChanged;
            controller.Errored += controller_Errored;
            controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
            controller.UpdatePACFromGFWListError     += controller_UpdatePACFromGFWListError;

            _notifyIcon = new NotifyIcon();
            UpdateTrayIcon();
            _notifyIcon.Visible            = true;
            _notifyIcon.ContextMenu        = contextMenu1;
            _notifyIcon.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
            _notifyIcon.MouseClick        += notifyIcon1_Click;
            _notifyIcon.MouseDoubleClick  += notifyIcon1_DoubleClick;
            _notifyIcon.BalloonTipClosed  += _notifyIcon_BalloonTipClosed;
            controller.TrafficChanged     += controller_TrafficChanged;

            this.updateChecker = new UpdateChecker();
            updateChecker.CheckUpdateCompleted += updateChecker_CheckUpdateCompleted;

            #region 抓取网络地址
            //var servers = GetServers.Download();
            //if (servers != null && servers.Count > 0)
            //{
            //    controller.SaveServers(servers, 1080, true);
            //}
            #endregion
            LoadCurrentConfiguration();

            Configuration config = controller.GetConfigurationCopy();



            if (config.isDefault)
            {
                _isFirstRun = true;
                ShowConfigForm();
            }
            else if (config.autoCheckUpdate)
            {
                _isStartupChecking = true;
                updateChecker.CheckUpdate(config, 3000);
            }
        }
Exemple #6
0
        public static void Init(ShadowsocksController controller, View.MenuViewController menu)
        {
            _hotKeyManager             = new HotKeyManager();
            _hotKeyManager.KeyPressed += HotKeyManagerPressed;

            HotkeyCallbacks.InitInstance(controller, menu);

            var keys = controller.GetConfigurationCopy()?.hotkey ?? new HotkeyConfig();

            LoadConfiguration(keys);
        }
Exemple #7
0
        public MenuViewController(ShadowsocksController controller)
        {
            this.controller = controller;
            #region SSD
            _SetStaticMenuView();
            #endregion
            LoadMenu();

            controller.EnableStatusChanged         += controller_EnableStatusChanged;
            controller.ConfigChanged               += controller_ConfigChanged;
            controller.PACFileReadyToOpen          += controller_FileReadyToOpen;
            controller.UserRuleFileReadyToOpen     += controller_FileReadyToOpen;
            controller.ShareOverLANStatusChanged   += controller_ShareOverLANStatusChanged;
            controller.VerboseLoggingStatusChanged += controller_VerboseLoggingStatusChanged;
            controller.ShowPluginOutputChanged     += controller_ShowPluginOutputChanged;
            controller.EnableGlobalChanged         += controller_EnableGlobalChanged;
            controller.Errored += controller_Errored;
            controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
            controller.UpdatePACFromGFWListError     += controller_UpdatePACFromGFWListError;

            _notifyIcon = new NotifyIcon();
            UpdateTrayIconAndNotifyText();
            _notifyIcon.Visible            = true;
            _notifyIcon.ContextMenu        = contextMenu1;
            _notifyIcon.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
            _notifyIcon.MouseClick        += notifyIcon1_Click;
            _notifyIcon.MouseDoubleClick  += notifyIcon1_DoubleClick;
            _notifyIcon.BalloonTipClosed  += _notifyIcon_BalloonTipClosed;
            controller.TrafficChanged     += controller_TrafficChanged;

            this.updateChecker = new UpdateChecker();
            updateChecker.CheckUpdateCompleted += updateChecker_CheckUpdateCompleted;

            LoadCurrentConfiguration();

            Configuration config = controller.GetConfigurationCopy();

            if (config.isDefault)
            {
                _isFirstRun = true;
                #region SSD
                //ShowConfigForm();
                _DisableFirstRun();
                #endregion
            }
            else if (config.autoCheckUpdate)
            {
                _isStartupChecking = true;
                updateChecker.CheckUpdate(config, 3000);
            }
            #region SSD
            _InitOther();
            #endregion
        }
Exemple #8
0
        public MenuViewController(ShadowsocksController controller)
        {
            this.controller = controller;

            LoadMenu();

            controller.EnableStatusChanged         += controller_EnableStatusChanged;
            controller.ConfigChanged               += controller_ConfigChanged;
            controller.PACFileReadyToOpen          += controller_FileReadyToOpen;
            controller.UserRuleFileReadyToOpen     += controller_FileReadyToOpen;
            controller.ShareOverLANStatusChanged   += controller_ShareOverLANStatusChanged;
            controller.VerboseLoggingStatusChanged += controller_VerboseLoggingStatusChanged;
            controller.EnableGlobalChanged         += controller_EnableGlobalChanged;
            controller.Errored += controller_Errored;
            controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
            controller.UpdatePACFromGFWListError     += controller_UpdatePACFromGFWListError;

            _notifyIcon = new NotifyIcon();
            UpdateTrayIcon();
            _notifyIcon.Visible            = true;
            _notifyIcon.ContextMenu        = contextMenu1;
            _notifyIcon.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
            _notifyIcon.MouseClick        += notifyIcon1_Click;
            _notifyIcon.MouseDoubleClick  += notifyIcon1_DoubleClick;
            _notifyIcon.BalloonTipClosed  += _notifyIcon_BalloonTipClosed;
            controller.TrafficChanged     += controller_TrafficChanged;

            this.updateChecker = new UpdateChecker();
            updateChecker.CheckUpdateCompleted += updateChecker_CheckUpdateCompleted;

            LoadCurrentConfiguration();

            Configuration config = controller.GetConfigurationCopy();

            if (config.isDefault)
            {
                _isFirstRun = true;
                ShowConfigForm();
            }
            else if (config.autoCheckUpdate)
            {
                _isStartupChecking = true;
                updateChecker.CheckUpdate(config, 3000);
            }

            if (config.grabInterval > 0)
            {
                this.getServerFromInternetTimer          = new Timer();
                this.getServerFromInternetTimer.Interval = config.grabInterval * 1000;
                this.getServerFromInternetTimer.Tick    += new System.EventHandler(this.GetServerFromInternetTimer_Tick);
                this.getServerFromInternetTimer.Enabled  = true;
            }
        }
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = controller.GetConfigurationCopy();
     LoadConfiguration(_modifiedConfiguration);
     _oldSelectedIndex = _modifiedConfiguration.index;
     if (_oldSelectedIndex < 0)
     {
         _oldSelectedIndex = 0;
     }
     ServersListBox.SelectedIndex = _oldSelectedIndex;
     LoadSelectedServer();
 }
Exemple #10
0
        public MenuViewController(ShadowsocksController controller)
        {
            this.controller = controller;

            LoadMenu();

            controller.EnableStatusChanged       += controller_EnableStatusChanged;
            controller.ConfigChanged             += controller_ConfigChanged;
            controller.PACFileReadyToOpen        += controller_FileReadyToOpen;
            controller.UserRuleFileReadyToOpen   += controller_FileReadyToOpen;
            controller.ShareOverLANStatusChanged += controller_ShareOverLANStatusChanged;
            controller.EnableGlobalChanged       += controller_EnableGlobalChanged;
            controller.Errored += controller_Errored;
            controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
            controller.UpdatePACFromGFWListError     += controller_UpdatePACFromGFWListError;

            _notifyIcon = new NotifyIcon();
            UpdateTrayIcon();
            _notifyIcon.Visible            = true;
            _notifyIcon.ContextMenu        = contextMenu1;
            _notifyIcon.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
            _notifyIcon.MouseClick        += notifyIcon1_Click;
            _notifyIcon.MouseDoubleClick  += notifyIcon1_DoubleClick;
            _notifyIcon.BalloonTipClosed  += _notifyIcon_BalloonTipClosed;

            this.updateChecker = new UpdateChecker();
            updateChecker.CheckUpdateCompleted += updateChecker_CheckUpdateCompleted;


            LoadCurrentConfiguration();

            var config = controller.GetConfigurationCopy();

            if (config.isDefault)
            {
                _isFirstRun = true;
            }
            else if (config.autoCheckUpdate)
            {
                _isStartupChecking = true;
                updateChecker.CheckUpdate(config, 3000);
            }



            timer.Tick += (s, e) =>
            {
                //provisional Over
                //TimerFunction();
            };

            TimerFunction();
        }
 private void LoadCurrentConfiguration()
 {
     _modifiedProxyConfig            = controller.GetConfigurationCopy().proxy;
     UseProxyCheckBox.Checked        = _modifiedProxyConfig.useProxy;
     ProxyServerTextBox.Text         = _modifiedProxyConfig.proxyServer;
     ProxyPortTextBox.Text           = _modifiedProxyConfig.proxyPort.ToString();
     ProxyTimeoutTextBox.Text        = _modifiedProxyConfig.proxyTimeout.ToString();
     ProxyTypeComboBox.SelectedIndex = _modifiedProxyConfig.proxyType;
     UseAuthCheckBox.Checked         = _modifiedProxyConfig.useAuth;
     AuthUserTextBox.Text            = _modifiedProxyConfig.authUser;
     AuthPwdTextBox.Text             = _modifiedProxyConfig.authPwd;
 }
Exemple #12
0
        public MenuViewController(ShadowsocksController controller)
        {
            this.controller = controller;

            LoadMenu();
            enableItem.Visible       = false;
            modeItem.Visible         = false;
            PACItem.Visible          = false;
            proxyItem.Visible        = false;
            ShareOverLANItem.Visible = false;
            hotKeyItem.Visible       = false;
            //tableLayoutPanel6.Visible = false;
            //tableLayoutPanel7.Visible = false;

            controller.EnableStatusChanged         += controller_EnableStatusChanged;
            controller.ConfigChanged               += controller_ConfigChanged;
            controller.PACFileReadyToOpen          += controller_FileReadyToOpen;
            controller.UserRuleFileReadyToOpen     += controller_FileReadyToOpen;
            controller.ShareOverLANStatusChanged   += controller_ShareOverLANStatusChanged;
            controller.VerboseLoggingStatusChanged += controller_VerboseLoggingStatusChanged;
            controller.EnableGlobalChanged         += controller_EnableGlobalChanged;
            controller.Errored += controller_Errored;
            controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
            controller.UpdatePACFromGFWListError     += controller_UpdatePACFromGFWListError;

            _notifyIcon = new NotifyIcon();
            UpdateTrayIcon();
            _notifyIcon.Visible            = true;
            _notifyIcon.ContextMenu        = contextMenu1;
            _notifyIcon.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
            _notifyIcon.MouseClick        += notifyIcon1_Click;
            _notifyIcon.MouseDoubleClick  += notifyIcon1_DoubleClick;
            _notifyIcon.BalloonTipClosed  += _notifyIcon_BalloonTipClosed;
            controller.TrafficChanged     += controller_TrafficChanged;

            this.updateChecker = new UpdateChecker();
            updateChecker.CheckUpdateCompleted += updateChecker_CheckUpdateCompleted;

            LoadCurrentConfiguration();

            Configuration config = controller.GetConfigurationCopy();

            if (config.isDefault)
            {
                _isFirstRun = true;
                ShowConfigForm();
            }
            else if (config.autoCheckUpdate)
            {
                _isStartupChecking = true;
                updateChecker.CheckUpdate(config, 3000);
            }
        }
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = controller.GetConfigurationCopy();
     LoadConfiguration(_modifiedConfiguration);
     _lastSelectedIndex = _modifiedConfiguration.index;
     if (_lastSelectedIndex < 0)
     {
         _lastSelectedIndex = 0;
     }
     ServersListBox.SelectedIndex = _lastSelectedIndex;
     UpdateMoveUpAndDownButton();
     LoadSelectedServer();
 }
Exemple #14
0
        public ServerCrawler(ShadowsocksController controller)
        {
            this.controller = controller;
            configuration   = controller.GetConfigurationCopy();

            this.serverList = new List <Server>();
            foreach (var server in configuration.configs)
            {
                if (server.remarks == CRAWLER_REMARKS)
                {
                    this.serverList.Add(server);
                }
            }
        }
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = controller.GetConfigurationCopy();
     LoadConfiguration(_modifiedConfiguration);
     _lastSelectedIndex = _modifiedConfiguration.index;
     if (_lastSelectedIndex < 0 || _lastSelectedIndex >= ServersListBox.Items.Count)
     {
         _lastSelectedIndex = 0;
     }
     ServersListBox.SelectedIndex = _lastSelectedIndex;
     UpdateMoveUpAndDownButton();
     LoadSelectedServer();
     TempFolderTextBox.Text = _modifiedConfiguration.tempFolder;
 }
Exemple #16
0
 private void LoadCurrentConfiguration()
 {
     _modifiedConfiguration = controller.GetConfigurationCopy();
     LoadConfiguration(_modifiedConfiguration);
     _lastSelectedIndex = _modifiedConfiguration.index;
     if (_lastSelectedIndex < 0 || _lastSelectedIndex >= ServersListBox.Items.Count)
     {
         _lastSelectedIndex = 0;
     }
     ServersListBox.SelectedIndex = _lastSelectedIndex;
     UpdateMoveUpAndDownButton();
     LoadSelectedServer();
     PortableModeCheckBox.Checked = _modifiedConfiguration.portableMode;
 }
Exemple #17
0
        public MenuViewController(ShadowsocksController shadowsocksController)
        {
            _shadowsocksController = shadowsocksController;
            _shadowsocksController.EnableStatusChanged       += controller_EnableStatusChanged;
            _shadowsocksController.ConfigChanged             += controller_ConfigChanged;
            _shadowsocksController.PACFileReadyToOpen        += controller_FileReadyToOpen;
            _shadowsocksController.UserRuleFileReadyToOpen   += controller_FileReadyToOpen;
            _shadowsocksController.ShareOverLANStatusChanged += controller_ShareOverLANStatusChanged;
            _shadowsocksController.EnableGlobalChanged       += controller_EnableGlobalChanged;
            _shadowsocksController.Errored += controller_Errored;
            _shadowsocksController.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
            _shadowsocksController.UpdatePACFromGFWListError     += controller_UpdatePACFromGFWListError;

            LoadMenu();

            _notifyIcon = new NotifyIcon();

            UpdateTrayIcon();

            _notifyIcon.Visible           = true;
            _notifyIcon.ContextMenu       = _trayIconcontextMenu;
            _notifyIcon.MouseDoubleClick += notifyIcon1_DoubleClick;

            _updateChecker = new UpdateChecker();
            _updateChecker.NewVersionFound += updateChecker_NewVersionFound;

            LoadCurrentConfiguration();

            _updateChecker.CheckUpdate(_shadowsocksController.GetConfigurationCopy());

            if (_shadowsocksController.GetConfigurationCopy().isDefault)
            {
                _isFirstRun = true;
                ShowConfigForm();
            }
        }
        private void LoadCurrentConfiguration()
        {
            _modifiedConfiguration = controller.GetConfigurationCopy();
            LoadServerNameListToUI(_modifiedConfiguration);

            _lastSelectedIndex = _modifiedConfiguration.index;
            if (_lastSelectedIndex < 0 || _lastSelectedIndex >= ServersListBox.Items.Count)
            {
                _lastSelectedIndex = 0;
            }

            ServersListBox.SelectedIndex = _lastSelectedIndex;
            UpdateButtons();
            LoadSelectedServerDetails();
            ProxyPortTextBox.Text        = _modifiedConfiguration.localPort.ToString();
            PortableModeCheckBox.Checked = _modifiedConfiguration.portableMode;
        }
Exemple #19
0
        private void LogForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            timer.Stop();
            LogViewerConfig config = controller.GetConfigurationCopy().logViewer;

            if (config == null)
            {
                config = new LogViewerConfig();
            }
            config.topMost      = topMostTrigger;
            config.wrapText     = wrapTextTrigger;
            config.toolbarShown = toolbarTrigger;
            config.SetFont(LogMessageTextBox.Font);
            config.SetBackgroundColor(LogMessageTextBox.BackColor);
            config.SetTextColor(LogMessageTextBox.ForeColor);
            controller.SaveLogViewerConfig(config);
        }
Exemple #20
0
        public LogForm(ShadowsocksController controller, string filename)
        {
            this.controller = controller;
            this.filename   = filename;
            InitializeComponent();
            Icon = Resources.global;

            LogViewerConfig config = controller.GetConfigurationCopy().logViewer;

            topMostTrigger              = config.topMost;
            wrapTextTrigger             = config.wrapText;
            toolbarTrigger              = config.toolbarShown;
            LogMessageTextBox.BackColor = config.BackgroundColor;
            LogMessageTextBox.ForeColor = config.TextColor;
            LogMessageTextBox.Font      = config.Font;

            controller.TrafficChanged += controller_TrafficChanged;

            UpdateTexts();
        }
Exemple #21
0
        public SubscriptionManagementForm(ShadowsocksController controllerSet)
        {
            InitializeComponent();
            Controller        = controllerSet;
            ConfigurationCopy = Controller.GetConfigurationCopy();

            Text                    = I18N.GetString("Subscription Management");
            Label_url.Text          = I18N.GetString("Subscription URL");
            Label_name.Text         = I18N.GetString("Airport Name");
            Button_add.Text         = I18N.GetString("&Add");
            Button_save.Text        = I18N.GetString("&Save");
            Button_delete.Text      = I18N.GetString("&Delete");
            CheckBox_use_proxy.Text = I18N.GetString("Use Proxy");
            Label_traffic_used.Text = I18N.GetString("Traffic Used:");
            Label_expiry_date.Text  = I18N.GetString("Expiry Date:");
            Label_proxy_tips.Text   = I18N.GetString("* Proxy will always be used in Global Mode");
            ResetShowed();

            Icon = Icon.FromHandle(Resources.ssw128.GetHicon());
        }
        public MenuViewController(ShadowsocksController controller)
        {
            this.controller = controller;

            LoadMenu();
            //             controller.ConfigChanged += controller_ConfigChanged;
            //             controller.PACFileReadyToOpen += controller_FileReadyToOpen;
            //             controller.UserRuleFileReadyToOpen += controller_FileReadyToOpen;
            //             controller.Errored += controller_Errored;
            //             controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
            //             controller.UpdatePACFromGFWListError += controller_UpdatePACFromGFWListError;

            _notifyIcon = new NotifyIcon();
            UpdateTrayIconAndNotifyText();
            _notifyIcon.Visible            = true;
            _notifyIcon.ContextMenu        = contextMenu1;
            _notifyIcon.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
            _notifyIcon.MouseDoubleClick  += notifyIcon1_DoubleClick;
            _notifyIcon.BalloonTipClosed  += _notifyIcon_BalloonTipClosed;
            controller.TrafficChanged     += controller_TrafficChanged;

            this.updateChecker = new UpdateChecker();
            updateChecker.CheckUpdateCompleted += updateChecker_CheckUpdateCompleted;

            Configuration config = controller.GetConfigurationCopy();

            if (config.isDefault)
            {
                _isFirstRun = true;
            }
            else if (config.autoCheckUpdate)
            {
                _isStartupChecking = true;
                updateChecker.CheckUpdate(config, 3000);
            }

            ShowConfigForm();
        }
Exemple #23
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 LoadCurrentConfiguration()
 {
     _modifiedConfig = _controller.GetConfigurationCopy().hotkey;
     LoadConfiguration(_modifiedConfig);
 }
        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);
        }
Exemple #26
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();
            }
            // 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));
        }
Exemple #27
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);
        }
        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);
        }
        private void SwitchSystemProxyCallback()
        {
            bool enabled = _controller.GetConfigurationCopy().enabled;

            _controller.ToggleEnable(!enabled);
        }
        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);
        }