Пример #1
0
        public string makeMessage()
        {
            string message = HeaderString + Comma + VersionString + Comma + CommandInt.ToString("00") + Comma + DeviceID + Comma + StatInt.ToString("0000") + Comma + PowerStatInt.ToString("00") + Comma + DatetimeString;

            return(message + makeOtherInfoString());
        }
Пример #2
0
        //constructor
        public Browser()
        {
            InitializeComponent();

            //set up browser options from config file
            grip       = options.borderThickness;
            gripCorner = grip * 4;

            //create container for chromium browser
            container = new Container
            {
                Dock      = DockStyle.Fill,
                Padding   = Grip,
                BackColor = options.borderColor
            };
            Controls.Add(container);

            //create draggable toolbar
            toolbar = new Panel()
            {
                Dock      = DockStyle.Top,
                BackColor = options.toolbar.backgroundColor,
                ForeColor = options.toolbar.fontColor,
                Height    = options.toolbar.height
            };
            toolbar.DoubleClick += Toolbar_DoubleClick;
            toolbar.MouseDown   += Toolbar_MouseDown;
            toolbar.MouseMove   += Toolbar_MouseMove;
            toolbar.MouseUp     += Toolbar_MouseUp;
            Controls.Add(toolbar);

            //create controls for toolbar
            title           = new Label();
            title.Dock      = DockStyle.Left;
            title.TextAlign = ContentAlignment.MiddleLeft;
            title.Height    = options.toolbar.height;
            title.Padding   = options.toolbar.padding;
            title.Text      = options.title;
            title.Font      = new Font(options.toolbar.fontFamily, options.toolbar.fontSize, FontStyle.Regular);
            title.AutoSize  = true;
            toolbar.Controls.Add(title);

            //create maximize button
            buttonMinimize        = new MenuButton(ButtonType.minimize, options.button);
            buttonMinimize.Width  = options.button.width;
            buttonMinimize.Height = options.button.height;
            buttonMinimize.Dock   = DockStyle.Right;
            buttonMinimize.UpdateColors(options.button);
            buttonMinimize.Click += ButtonMinimize_Click;
            toolbar.Controls.Add(buttonMinimize);

            //create maximize button
            buttonMaximize        = new MenuButton(ButtonType.maximize, options.button);
            buttonMaximize.Width  = options.button.width;
            buttonMaximize.Height = options.button.height;
            buttonMaximize.Dock   = DockStyle.Right;
            buttonMaximize.UpdateColors(options.button);
            buttonMaximize.Click += ButtonMaximize_Click;
            toolbar.Controls.Add(buttonMaximize);

            //create close button
            buttonClose        = new MenuButton(ButtonType.close, options.button);
            buttonClose.Width  = options.button.width;
            buttonClose.Height = options.button.height;
            buttonClose.Dock   = DockStyle.Right;
            buttonClose.UpdateColors(options.button);
            buttonClose.Click += ButtonClose_Click;
            toolbar.Controls.Add(buttonClose);

            //load default theme
            DefaultTheme();

            //set up browser settings
            var paths    = Application.LocalUserAppDataPath.Split('\\');
            var dataPath = string.Join("\\", paths.Take(paths.Length - 1)) + "\\";
            var settings = new CefSettings()
            {
                CachePath   = dataPath + "Profile\\",
                LogSeverity = LogSeverity.Disable
            };
            var browserSettings = new BrowserSettings()
            {
                BackgroundColor = Utility.ColorToUInt(Color.FromArgb(35, 35, 35))
            };

            //delete cache (optional)
            if (Utility.IsDebugMode == true && Directory.Exists(dataPath + "Profile\\Cache"))
            {
                FileSystem.DeleteDirectory(dataPath + "Profile\\Cache");
            }

            //add command line arguments when creating web browser
            var cmdArgs = settings.CefCommandLineArgs;

            cmdArgs.Add("disable-plugin-discovery", "1");
            cmdArgs.Add("disable-direct-write", "1");

            Cef.Initialize(settings);
            Cef.EnableHighDPISupport();
            browser = new ChromiumWebBrowser(options.url)
            {
                Dock        = DockStyle.Fill,
                BackColor   = options.borderColor,
                MenuHandler = new CustomMenuHandler()
            };
            browser.BrowserSettings = browserSettings;
            container.Controls.Add(browser);

            //set up browser internal events
            browser.IsBrowserInitializedChanged += (object sender, IsBrowserInitializedChangedEventArgs e) =>
            {
                if (e.IsBrowserInitialized == true)
                {
                    //show DevTools
                    if (options.showDevTools == true)
                    {
                        browser.ShowDevTools();
                    }
                }
            };
            browser.TitleChanged += (object sender, TitleChangedEventArgs e) =>
            {
                Invoke(changeTitle, e.Title);
            };

            //set up form window
            events         = new JsEvents();
            DoubleBuffered = true;
            SetStyle(ControlStyles.ResizeRedraw, true);

            //bind delegates for cross-thread purposes
            maximize            = new Command(MaximizeWindow);
            normalize           = new Command(NormalizeWindow);
            minimize            = new Command(MinimizeWindow);
            drag                = new Command(DragWindow);
            borderColor         = new CommandColor(BorderColor);
            toolbarColor        = new CommandColor(ToolbarColor);
            toolbarFontColor    = new CommandColor(ToolbarFontColor);
            toolbarButtonColors = new CommandButtonColors(ToolbarButtonColors);
            changeGripSize      = new CommandInt(ChangeGripSize);
            newwindow           = new Command(NewWindow);
            exit                = new Command(Exit);
            defaultTheme        = new Command(DefaultTheme);
            changeTitle         = new CommandStr(ChangeTitle);

            //bind JsEvents instance to JavaScript
            browser.JavascriptObjectRepository.Register("Rhino", events, false);
        }