Exemple #1
0
        private int RunInternal(string[] args)
        {
            Initialize();

            _config.ChromelyVersion = CefRuntime.ChromeVersion;

            var tempFiles = CefBinariesLoader.Load(_config);

            CefRuntime.EnableHighDpiSupport();

            var settings = new CefSettings
            {
                MultiThreadedMessageLoop = _config.Platform == ChromelyPlatform.Windows,
                LogSeverity      = CefLogSeverity.Info,
                LogFile          = "logs\\chromely.cef_" + DateTime.Now.ToString("yyyyMMdd") + ".log",
                ResourcesDirPath = _config.AppExeLocation
            };

            if (_config.WindowOptions.WindowFrameless || _config.WindowOptions.KioskMode)
            {
                // MultiThreadedMessageLoop is not allowed to be used as it will break frameless mode
                settings.MultiThreadedMessageLoop = false;
            }

            settings.LocalesDirPath      = Path.Combine(settings.ResourcesDirPath, "locales");
            settings.RemoteDebuggingPort = 20480;
            settings.Locale    = "en-US";
            settings.NoSandbox = true;

            var argv = args;

            if (CefRuntime.Platform != CefRuntimePlatform.Windows)
            {
                argv = new string[args.Length + 1];
                Array.Copy(args, 0, argv, 1, args.Length);
                argv[0] = "-";
            }

            // Update configuration settings
            settings.Update(_config.CustomSettings);

            // Set DevTools url
            _config.DevToolsUrl = $"http://127.0.0.1:{settings.RemoteDebuggingPort}";

            var    mainArgs = new CefMainArgs(argv);
            CefApp app      = new CefGlueApp(_config);

            if (ClientAppUtils.ExecuteProcess(_config.Platform, argv))
            {
                // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
                // that share the same executable. This function checks the command-line and,
                // if this is a sub-process, executes the appropriate logic.
                var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);
                if (exitCode >= 0)
                {
                    // The sub-process has completed so return here.
                    Logger.Instance.Log.Info($"Sub process executes successfully with code: {exitCode}");
                    return(exitCode);
                }
            }

            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

            ScanAssemblies();
            RegisterRoutes();
            RegisterMessageRouters();
            RegisterResourceHandlers();
            RegisterSchemeHandlers();
            RegisterAjaxSchemeHandlers();

            CefBinariesLoader.DeleteTempFiles(tempFiles);

            CreateMainWindow();

            Run();

            _mainWindow.Dispose();
            _mainWindow = null;

            Shutdown();

            return(0);
        }
Exemple #2
0
        /// <summary>
        /// The run internal.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private int RunInternal(string[] args)
        {
            Initialize();

            var tempFiles = CefBinariesLoader.Load(HostConfig);

            CefRuntime.EnableHighDpiSupport();

            var settings = new CefSettings
            {
                MultiThreadedMessageLoop = HostConfig.Platform == ChromelyPlatform.Windows,
                LogSeverity      = (CefLogSeverity)HostConfig.LogSeverity,
                LogFile          = HostConfig.LogFile,
                ResourcesDirPath = HostConfig.AppExeLocation
            };

            if (HostConfig.HostPlacement.Frameless || HostConfig.HostPlacement.KioskMode)
            {
                // MultiThreadedMessageLoop is not allowed to be used as it will break frameless mode
                settings.MultiThreadedMessageLoop = false;
            }

            settings.LocalesDirPath      = Path.Combine(settings.ResourcesDirPath, "locales");
            settings.RemoteDebuggingPort = 20480;
            settings.Locale    = HostConfig.Locale;
            settings.NoSandbox = true;

            var argv = args;

            if (CefRuntime.Platform != CefRuntimePlatform.Windows)
            {
                argv = new string[args.Length + 1];
                Array.Copy(args, 0, argv, 1, args.Length);
                argv[0] = "-";
            }

            // Update configuration settings
            settings.Update(HostConfig.CustomSettings);

            var    mainArgs = new CefMainArgs(argv);
            CefApp app      = new CefGlueApp(HostConfig);

            // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
            // that share the same executable. This function checks the command-line and,
            // if this is a sub-process, executes the appropriate logic.
            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

            if (exitCode >= 0)
            {
                // The sub-process has completed so return here.
                CefBinariesLoader.DeleteTempFiles(tempFiles);
                Log.Info($"Sub process executes successfully with code: {exitCode}");
                return(exitCode);
            }

            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

            RegisterSchemeHandlers();
            RegisterMessageRouters();

            CreateMainWindow();

            bool centerScreen = HostConfig.HostPlacement.CenterScreen;

            if (centerScreen)
            {
                _mainView.CenterToScreen();
            }

            _windowCreated = true;


            IoC.RegisterInstance(typeof(IChromelyWindow), typeof(IChromelyWindow).FullName, this);

            CefBinariesLoader.DeleteTempFiles(tempFiles);

            RunMessageLoop();

            _mainView.Dispose();
            _mainView = null;

            CefRuntime.Shutdown();

            Shutdown();

            return(0);
        }
Exemple #3
0
        /// <summary>
        /// The run internal.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private int RunInternal(string[] args)
        {
            var tempFiles = CefBinariesLoader.Load(HostConfig);

            CefRuntime.EnableHighDpiSupport();

            var assembly = Assembly.GetEntryAssembly() ?? typeof(ChromelyConfiguration).Assembly;
            var settings = new CefSettings
            {
                MultiThreadedMessageLoop = true,
                LogSeverity      = (CefLogSeverity)HostConfig.LogSeverity,
                LogFile          = HostConfig.LogFile,
                ResourcesDirPath = Path.GetDirectoryName(new Uri(assembly.CodeBase).LocalPath)
            };

            if (HostConfig.HostFrameless || HostConfig.KioskMode)
            {
                if (HostConfig.HostApi == ChromelyHostApi.Gtk)
                {
                    throw new NotSupportedException("Chromely currently does not support frameless windows using GTK.");
                }

                // MultiThreadedMessageLoop is not allowed to be used as it will break frameless mode
                settings.MultiThreadedMessageLoop = false;
            }

            settings.LocalesDirPath      = Path.Combine(settings.ResourcesDirPath, "locales");
            settings.RemoteDebuggingPort = 20480;
            settings.NoSandbox           = true;
            settings.Locale = HostConfig.Locale;

            if (HostConfig.UseDefaultSubprocess)
            {
                var subprocessExeFullpath = DefaultSubprocessExe.FulPath;
                settings.BrowserSubprocessPath = subprocessExeFullpath ?? settings.BrowserSubprocessPath;
            }

            var argv = args;

            if (CefRuntime.Platform != CefRuntimePlatform.Windows)
            {
                argv = new string[args.Length + 1];
                Array.Copy(args, 0, argv, 1, args.Length);
                argv[0] = "-";
            }

            // Update configuration settings
            settings.Update(HostConfig.CustomSettings);

            var mainArgs = new CefMainArgs(argv);
            var app      = new CefGlueApp(HostConfig);

            // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
            // that share the same executable. This function checks the command-line and,
            // if this is a sub-process, executes the appropriate logic.
            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

            if (exitCode >= 0)
            {
                // The sub-process has completed so return here.
                CefBinariesLoader.DeleteTempFiles(tempFiles);
                Log.Info($"Sub process executes successfully with code: {exitCode}");
                return(exitCode);
            }

            // guard if something wrong
            foreach (var arg in args)
            {
                if (arg.StartsWith("--type="))
                {
                    return(-2);
                }
            }

            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

            RegisterSchemeHandlers();
            RegisterMessageRouters();

            Initialize();

            _mainView = CreateMainView();

            if (HostConfig.HostCenterScreen)
            {
                _mainView.CenterToScreen();
            }

            _windowCreated = true;

            CefBinariesLoader.DeleteTempFiles(tempFiles);

            RunMessageLoop();

            _mainView.Dispose();
            _mainView = null;

            CefRuntime.Shutdown();

            Shutdown();

            return(0);
        }
Exemple #4
0
        /// <summary>
        /// The run internal.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private int RunInternal(string[] args)
        {
            var tempFiles = CefBinariesLoader.Load(HostConfig);

            CefRuntime.EnableHighDpiSupport();

            var settings = new CefSettings
            {
                MultiThreadedMessageLoop = true,
                LogSeverity      = (CefLogSeverity)HostConfig.LogSeverity,
                LogFile          = HostConfig.LogFile,
                ResourcesDirPath = Path.GetDirectoryName(
                    new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath)
            };

            settings.LocalesDirPath      = Path.Combine(settings.ResourcesDirPath, "locales");
            settings.RemoteDebuggingPort = 20480;
            settings.NoSandbox           = true;
            settings.Locale = HostConfig.Locale;

            var argv = args;

            if (CefRuntime.Platform != CefRuntimePlatform.Windows)
            {
                argv = new string[args.Length + 1];
                Array.Copy(args, 0, argv, 1, args.Length);
                argv[0] = "-";
            }

            // Update configuration settings
            settings.Update(HostConfig.CustomSettings);

            var mainArgs = new CefMainArgs(argv);
            var app      = new CefGlueApp(HostConfig);

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

            Log.Info($"CefRuntime.ExecuteProcess() returns {exitCode}");

            if (exitCode != -1)
            {
                // An error has occured.
                CefBinariesLoader.DeleteTempFiles(tempFiles);
                return(exitCode);
            }

            // guard if something wrong
            foreach (var arg in args)
            {
                if (arg.StartsWith("--type="))
                {
                    return(-2);
                }
            }

            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

            RegisterSchemeHandlers();
            RegisterMessageRouters();

            Initialize();

            mMainView = CreateMainView();

            if (HostConfig.HostCenterScreen)
            {
                mMainView.CenterToScreen();
            }

            mWindowCreated = true;

            CefBinariesLoader.DeleteTempFiles(tempFiles);

            RunMessageLoop();

            mMainView.Dispose();
            mMainView = null;

            CefRuntime.Shutdown();

            Shutdown();

            return(0);
        }