Esempio n. 1
0
        protected int RunInternal(string[] args)
        {
            // For Windows 7 and above, best to include relevant app.manifest entries as well
            Cef.EnableHighDPISupport();

            var localFolder = _config.AppExeLocation;

            if (string.IsNullOrWhiteSpace(localFolder))
            {
                var codeBase = Assembly.GetExecutingAssembly().CodeBase;
                localFolder = Path.GetDirectoryName(new Uri(codeBase).LocalPath);
            }
            var localesDirPath = Path.Combine(localFolder ?? throw new InvalidOperationException(), "locales");

            _settings = new CefSettings
            {
                LocalesDirPath           = localesDirPath,
                Locale                   = "en-US",
                RemoteDebuggingPort      = 20480,
                MultiThreadedMessageLoop = !_config.WindowOptions.UseOnlyCefMessageLoop,
                CachePath                = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
                LogSeverity              = LogSeverity.Default,
                LogFile                  = "logs\\chromely.cef_" + DateTime.Now.ToString("yyyyMMdd") + ".log",
            };

            // Update configuration settings
            _settings.Update(_config.CustomSettings);
            _settings.UpdateCommandOptions(_config.CommandLineOptions);
            _settings.UpdateCommandLineArgs(_config.CommandLineArgs);

            // If MultiThreadedMessageLoop is overriden in Setting using CustomSettings, then
            // It is assumed that the developer way not be aware of IWindowOptions - UseOnlyCefMessageLoop
            _config.WindowOptions.UseOnlyCefMessageLoop = !_settings.MultiThreadedMessageLoop;

            // Set DevTools url
            string devtoolsUrl = _config.DevToolsUrl;

            if (string.IsNullOrWhiteSpace(devtoolsUrl))
            {
                _config.DevToolsUrl = $"http://127.0.0.1:{_settings.RemoteDebuggingPort}";
            }
            else
            {
                Uri uri = new Uri(devtoolsUrl);
                if (uri.Port <= 80)
                {
                    _config.DevToolsUrl = $"{devtoolsUrl}:{_settings.RemoteDebuggingPort}";
                }
            }

            RegisterDefaultSchemeHandlers();
            RegisterCustomSchemeHandlers();

            // Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(_settings, true, browserProcessHandler: null);

            _window.RegisterHandlers();
            _window.Init(_settings);

            NativeHost_CreateAndShowWindow();
            NativeHost_Run();

            Cef.Shutdown();

            NativeHost_Quit();

            return(0);
        }