예제 #1
0
        private void InitializeUI()
        {
            _overlay = _manager.CreateUIElement(OverlayUIId, () => new CefOverlayForm());
            _overlay.Show(); //initializes all properties
            _overlay.Visible = false;

            _configManager.AddPropertyChangeListener("behaviour.frame.chat", true, true, OnEvent_ConfigManager_PositionChange);

            _moveCallback = new DelayedCallback(TimeSpan.FromSeconds(1), () =>
            {
                var location = _overlay.Location;
                if (IsFrameOnScreens(_overlay.DesktopBounds))
                {
                    _configManager.SetProperty("behaviour.frame.chat.position.x", location.X);
                    _configManager.SetProperty("behaviour.frame.chat.position.y", location.Y);
                    _configManager.DispatchChangeEvents();
                }
                else // restore last location and size from config
                {
                    UpdateFormPosition();
                }
            });

            _resizeCallback = new DelayedCallback(TimeSpan.FromSeconds(1), () =>
            {
                var size = _overlay.Size;
                if (IsFrameOnScreens(_overlay.DesktopBounds))
                {
                    _configManager.SetProperty("behaviour.frame.chat.size.width", size.Width);
                    _configManager.SetProperty("behaviour.frame.chat.size.height", size.Height);
                    _configManager.DispatchChangeEvents();
                }
                else // restore last location and size from config
                {
                    UpdateFormPosition();
                }
            });

            _overlay.Move        += (s, e) => _moveCallback.Call();
            _overlay.SizeChanged += (s, e) => _resizeCallback.Call();

            _overlay.Browser.OnBrowserLoadPageDone += (s, e) =>
            {
                if (!_overlay.Visible)
                {
                    _manager.UISynchronizer.RunSync(() => _overlay.Visible = true);
                }
            };

            if (_manager.TryGetUIElement <INotifyIconManager>(AppModuleNotifyIcon.NotifyIconManagerId, out var trayIcon))
            {
                //trayIcon.Icon = Gobchat.Resource.GobTrayIconOff;

                trayIcon.OnIconClick += (s, e) => _overlay.Visible = !_overlay.Visible;

                var menuItemHideShow = new ToolStripMenuItem();
                menuItemHideShow.Text    = _overlay.Visible ? Resources.Module_NotifyIcon_UI_Hide : Resources.Module_NotifyIcon_UI_Show;
                menuItemHideShow.Click  += (s, e) => _overlay.Visible = !_overlay.Visible;
                _overlay.VisibleChanged += (s, e) => menuItemHideShow.Text = _overlay.Visible ? Resources.Module_NotifyIcon_UI_Hide : Resources.Module_NotifyIcon_UI_Show;
                trayIcon.AddMenu("overlay.showhide", menuItemHideShow);

                var menuItemReload = new ToolStripMenuItem(Resources.Module_NotifyIcon_UI_Reload);
                menuItemReload.Click += (s, e) => _overlay.Reload();
                trayIcon.AddMenu("overlay.reload", menuItemReload);

                var menuItemFrameReset = new ToolStripMenuItem(Resources.Module_NotifyIcon_UI_Reset);
                menuItemFrameReset.Click += (s, e) => ResetFrameToDefaultLocation();
                trayIcon.AddMenu("overlay.reset", menuItemFrameReset);

#if DEBUG
                var menuItemDevTool = new ToolStripMenuItem("DevTool");
                menuItemDevTool.Click += (s, e) => _overlay.Browser.ShowDevTools();
                trayIcon.AddMenuToGroup("debug", "overlay.devtool", menuItemDevTool);
#endif
            }

            _overlay.Visible = false;
        }