Exemple #1
0
        public MenuViewController(V2RayShellController 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;

            updateChecker = new UpdateChecker();

            LoadCurrentConfiguration();

            Configuration config = controller.GetConfigurationCopy();

            if (config.isDefault)
            {
                _isFirstRun = true;
                ShowConfigForm();
            }
            else if (config.autoCheckUpdate)
            {
                CheckUpdate(config);
            }
        }
Exemple #2
0
        private void UpdateTrayIcon()
        {
            _notifyIcon.Icon = Resources.v2ray;
            Configuration config     = controller.GetConfigurationCopy();
            bool          enabled    = config.enabled;
            bool          global     = config.global;
            string        serverInfo = config.GetCurrentServer().ps;
            string        text       = I18N.GetString("V2RayShell") + " " + Global.Version + "\n" +
                                       (enabled ?
                                        I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) :
                                        String.Format(I18N.GetString("Running: Port {0}"), $"{config.corePort}/{config.localPort}"))
                                       + "\n" + serverInfo;

            _notifyIcon.SetNotifyIconText(text);
        }
Exemple #3
0
        private void UpdateTrayIcon()
        {
            int dpi;

            using (var graphics = Graphics.FromHwnd(IntPtr.Zero))
            {
                dpi = (int)graphics.DpiX;
            }
            iconBase = null;
            if (dpi < 96)
            {
                //72
                iconBase = Resources.T18;
            }
            else if (dpi < 192)
            {
                //96
                iconBase = Resources.T24;
            }
            else
            {
                //192
                iconBase = Resources.T48;
            }
            var config  = controller.GetConfigurationCopy();
            var enabled = config.enabled;
            var global  = config.global;

            iconBase         = getTrayIconByState(iconBase, enabled, global);
            trayIcon         = Icon.FromHandle(iconBase.GetHicon());
            _notifyIcon.Icon = trayIcon;

            var serverInfo = config.GetCurrentServer().ps;
            var text       = I18N.GetString("V2RayShell") + " " + Global.Version + "\n" +
                             (enabled ?
                              I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) :
                              String.Format(I18N.GetString("Running: Port {0}"), $"{config.corePort}/{config.localPort}"))
                             + "\n" + serverInfo;

            _notifyIcon.SetNotifyIconText(text);
        }