Ejemplo n.º 1
0
        public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText)
        {
            // This needs to happen first.
            settingsTab.Initialize(pluginStatusText);

            settingsTab.OnButtonShowDevTools += (o, e) =>
            {
                browserWindow.BrowserControl.Browser.ShowDevTools();
            };
            settingsTab.OnCheckboxIgnoresMouseChanged += (o, e) =>
            {
                browserWindow.Clickable = !((CheckBox)o).Checked;
            };
            settingsTab.OnCheckboxLayoutModeChanged += (o, e) =>
            {
                const string enableLayoutModeStr =
                    @"
                        if (window.enableLayoutMode)
                            window.enableLayoutMode();
                    ";
                const string disableLayoutModeStr =
                    @"
                        if (window.disableLayoutMode)
                            window.disableLayoutMode();
                    ";

                bool layoutModeEnabled = ((CheckBox)o).Checked;
                browserWindow.BrowserControl.Browser.ExecuteScriptAsync(
                    layoutModeEnabled ? enableLayoutModeStr : disableLayoutModeStr);
                browserWindow.Clickable = layoutModeEnabled;
            };
            settingsTab.OnButtonReload += (o, e) =>
            {
                bool ignoreCache = true;
                browserWindow.BrowserControl.Browser.Reload(ignoreCache);
            };
            settingsTab.OnToggleWindowVisibility += (o, e) =>
            {
                visibilityControl.visibleViaHotkey = !(visibilityControl.visibleViaHotkey);
            };

            CefSettings cefSettings = new CefSettings();
            cefSettings.CachePath = BrowserCacheDir();
            Cef.Initialize(cefSettings);

            browserWindow = new BrowserWindow();
            browserWindow.ShowInTaskbar = false;
            browserWindow.BrowserControl.CreationHandlers += OnBrowserCreated;
            browserWindow.Clickable = false;
            browserWindow.Show();

            visibilityControl = new VisibilityControl(browserWindow);

            pluginScreenSpace.Text = "Cactbot";
            pluginScreenSpace.Controls.Add(settingsTab);

            Application.ApplicationExit += OnACTShutdown;
        }
Ejemplo n.º 2
0
        public VisibilityControl(BrowserWindow bw)
        {
            // Grab a handle to the browser window so we can control it
            browserWindow = bw;

            visibleViaFocus = false;
            visibleViaHotkey = true;

            // Glue to avoid interop exceptions from calling Show/Hide directly
            VisibilityChecker myChecker = CheckVisibility;
            var currentDispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher;

            // Let the polling begin
            timer = new System.Timers.Timer(timerInterval);
            timer.Elapsed += (o, e) => { currentDispatcher.Invoke(myChecker); };
            timer.Start();
        }