コード例 #1
0
        /// <summary>Setups the specified setting.</summary>
        /// <param name="setting">The setting.</param>
        public void Setup(Window setting)
        {
            try
            {
                this.config = setting;
                this.Text = this.config.Name;
                this.TopMost = this.config.OnTop;
                this.Icon = Resources.TrayIcon;

                this.browser = new GeckoWebBrowser
                {
                    Parent = this,
                    Dock = DockStyle.Fill,
                    Location = new Point(0, 0),
                    Name = "browser",
                    Size = new Size(104, 100),
                    TabIndex = 0
                };
                this.ClientSize = new Size(104, 100);
                this.ControlBox = false;
                this.Controls.Add(this.browser);
                this.MaximizeBox = false;
                this.MinimizeBox = false;
                this.Name = "browser";
                this.SizeGripStyle = SizeGripStyle.Hide;
                this.StartPosition = FormStartPosition.Manual;
                this.ResumeLayout(false);
            #if DEBUG
                this.FormBorderStyle = FormBorderStyle.Fixed3D;
            #else
                this.FormBorderStyle = FormBorderStyle.None;
            #endif

                this.browser.HandleCreated += this.GeckoBrowserHandleCreated;

                var showOnScreen = this.config.ShowOnScreen;
                showOnScreen = (showOnScreen >= Screen.AllScreens.Length) ? 0 : showOnScreen;
                var screen = Screen.AllScreens[showOnScreen];
                var left = screen.Bounds.Left;
                var top = screen.Bounds.Top;
                var posX = this.config.Position.PosX;
                var posY = this.config.Position.PosY;
                this.Location = new Point(left + posX, top + posY);
                var width = this.config.Dimensions.Width;
                int num5;
                if (width == "max" || width == "max2")
                {
                    num5 = (width == "max") ? screen.Bounds.Width : (screen.Bounds.Width * 2);
                    num5 -= posX;
                }
                else
                {
                    num5 = Convert.ToInt32(width);
                }

                var height = this.config.Dimensions.Height;
                int num6;
                if (height == "max" || height == "max2")
                {
                    num6 = (height == "max") ? screen.Bounds.Height : (screen.Bounds.Height * 2);
                    num6 -= posY;
                }
                else
                {
                    num6 = Convert.ToInt32(height);
                }

                this.ClientSize = new Size(num5, num6);
                this.browser.DOMContentLoaded += this.BrowserOnDomContentLoaded;
                this.browser.DomMouseScroll += this.BrowserOnDomMouseScroll;
                this.browser.DomKeyDown += this.BrowserOnDomKeyDown;

                if (setting.ReloadInSeconds > 0)
                {
                    // This timer works as auto reload of the webpage.
                    var reloadTimer = new Timer { Interval = setting.ReloadInSeconds * 1000, AutoReset = true };
                    this.browser.Disposed += (sender, args) =>
                    {
                        if (reloadTimer == null)
                        {
                            return;
                        }

                        reloadTimer.Stop();
                        reloadTimer.Dispose();
                        reloadTimer = null;
                    };

                    reloadTimer.Elapsed += (sender, args) =>
                    {
                        if (this.browser.Disposing || !this.DomContentLoaded)
                        {
                            return;
                        }

                        lock (this.reloadLockObject)
                        {
                            this.DocumentCookies.Clear();
                            this.browser.Reload();
                        }
                    };
                    reloadTimer.Start();
                }
            }
            catch (Exception exception)
            {
                Logger.Warn(exception);
            }
        }