示例#1
0
 public CSharpTools(ref Engine engine, ref MainWindow mainWindow, ref WebServer server)
 {
     _mainWindow = mainWindow;
     _engine     = engine;
     _server     = server;
 }
示例#2
0
        public MainWindow()
        {
            InitializeComponent();

            Current = this;

            this.Resize += OnWinResize;

            string AppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            _cefSettings = new CefSettings()
            {
                CachePath = null
            };

            _cefSettings.CefCommandLineArgs.Add("--disable-cache", "1");
            _cefSettings.CefCommandLineArgs.Add("--disable-application-cache", "1");
            _cefSettings.CefCommandLineArgs.Add("--disable-session-storage", "1");
            _cefSettings.CefCommandLineArgs.Add("--disable-local-storage", "1");
            _cefSettings.CefCommandLineArgs.Add("--disable-web-security", "1");

            if (System.IO.File.Exists($"{AppData}\\ORB\\cef.log"))
            {
                System.IO.File.Delete($"{AppData}\\ORB\\cef.log");
            }

            _cefSettings.LogFile     = $"{AppData}\\ORB\\cef.log";
            _cefSettings.LogSeverity = LogSeverity.Error | LogSeverity.Info | LogSeverity.Warning;

            Cef.Initialize(_cefSettings);

            if (!Cef.IsInitialized)
            {
                throw new Exception("Couldn't initialize CEF.");
            }

            Logger.MainLogger.Log(Logger.LogTypes.Info, "CEF.Initialize -> Success");

            CefSharpSettings.LegacyJavascriptBindingEnabled = true;

            var manager = Cef.GetGlobalCookieManager();

            _server = new WebServer();
            _server.Start();

            Logger.MainLogger.Log(Logger.LogTypes.Info, "HTTPServer.Start -> Success");

            if (System.IO.File.Exists($"{AppData}\\ORB\\Private\\Key"))
            {
                Engine.ApiKey = System.IO.File.ReadAllText($"{AppData}\\ORB\\Private\\Key");
                Logger.MainLogger.Log(Logger.LogTypes.Info, "APIKey.Load -> Success");
            }

            _browser = new ChromiumWebBrowser($"{_server.Url}html/mainwindow.html")
            {
                Dock = DockStyle.Fill
            };

            Logger.MainLogger.Log(Logger.LogTypes.Info, "BrowserObject.Create -> Success");
            _browser.RegisterJsObject("cSharpTools", new CSharpTools(ref _server.Engine, ref Current, ref _server));
            Logger.MainLogger.Log(Logger.LogTypes.Info, "BrowserObject.RegisterJS -> Success");
            _browser.BackColor = Color.Black;
            this.BackColor     = Color.Black;

            manager.SetCookie(_server.Url, new CefSharp.Cookie()
            {
                Path  = "/",
                Name  = "token",
                Value = Convert.ToBase64String(_server.Token)
            });

            Logger.MainLogger.Log(Logger.LogTypes.Info, "CookieManager.SetCookie -> Success");
            _browser.Dock = DockStyle.None;

            _browser.IsBrowserInitializedChanged += InitializeStatus;
            this.Controls.Add(_browser);
            _browser.Paint += BrowserPaint;

            Color panelColor = _server.Engine.LocalSettings.NightMode ?
                               Color.FromArgb(32, 31, 36) : Color.White;

            if (!_server.Engine.LocalSettings.NightMode)
            {
                _loadingPanel = new Panel
                {
                    Dock      = DockStyle.Fill,
                    BackColor = panelColor
                };

                this.Controls.Add(_loadingPanel);
                _loadingPanel.BringToFront();
            }

            BackColor = Color.Black;
        }