Esempio n. 1
0
        private static void InitializeCef()
        {
            if (!Cef.IsInitialized)
            {
                var cefSettings = new CefSettings();
                cefSettings.LogSeverity = string.IsNullOrWhiteSpace(LogFile) ? LogSeverity.Disable : (EnableErrorLogOnly ? LogSeverity.Error : LogSeverity.Verbose);
                cefSettings.LogFile     = LogFile;
                cefSettings.UncaughtExceptionStackSize = 100; // enable stack capture
                cefSettings.CachePath = TempDir;              // enable cache for external resources to speedup loading
                cefSettings.WindowlessRenderingEnabled = true;

                CefSharpSettings.ConcurrentTaskExecution             = true;
                CefSharpSettings.LegacyJavascriptBindingEnabled      = true;
                CefSharpSettings.SubprocessExitIfParentProcessClosed = true;

                foreach (var scheme in CustomSchemes)
                {
                    cefSettings.RegisterScheme(new CefCustomScheme()
                    {
                        SchemeName           = scheme,
                        SchemeHandlerFactory = new CefSchemeHandlerFactory()
                    });
                }

                cefSettings.BrowserSubprocessPath = CefLoader.GetBrowserSubProcessPath();

                Cef.Initialize(cefSettings, performDependencyCheck: false, browserProcessHandler: null);

                if (Application.Current != null)
                {
                    Application.Current.Exit += OnApplicationExit;
                    subscribedApplicationExit = true;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The warn user on load.
        /// </summary>
        /// <returns>
        /// The list of temporary files generated
        /// </returns>
        private static List <string> WarnUserOnLoad()
        {
            var tempFiles = new List <string>();

            try
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                var startTempFile = LaunchStartPage();
                tempFiles.Add(startTempFile);

                CefLoader.Load();

                stopwatch.Stop();
                var competedTempFile = LaunchCompletedPage($"Time elapsed: {stopwatch.Elapsed}.");

                if (competedTempFile != null)
                {
                    tempFiles.Add(competedTempFile);
                }

                Thread.Sleep(TimeSpan.FromSeconds(2));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                var onErrorTempFile = LaunchErrorPage(ex);
                tempFiles.Add(onErrorTempFile);
                Environment.Exit(0);
            }

            return(tempFiles);
        }
Esempio n. 3
0
        /// <summary>
        /// The warn user on load.
        /// </summary>
        /// <returns>
        /// The list of temporary files generated
        /// </returns>
        private static List <string> DownloadAndNotifyUser(ChromelyPlatform platform)
        {
            var tempFiles = new List <string>();

            try
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                var startTempFile = ShowDownloadStartedPage();
                tempFiles.Add(startTempFile);

                CefLoader.Download(platform);

                stopwatch.Stop();
                var competedTempFile = ShowDownloadCompletedPage($"Time elapsed: {stopwatch.Elapsed}.");

                if (competedTempFile != null)
                {
                    tempFiles.Add(competedTempFile);
                }

                Thread.Sleep(TimeSpan.FromSeconds(2));
            }
            catch (Exception ex)
            {
                Logger.Instance.Log.Error(ex);
                var onErrorTempFile = ShowErrorPage(ex);
                tempFiles.Add(onErrorTempFile);
                Environment.Exit(0);
            }

            return(tempFiles);
        }
Esempio n. 4
0
        private static void InitializeCef()
        {
            if (!Cef.IsInitialized)
            {
                var cefSettings = new CefSettings();
                cefSettings.LogSeverity = LogSeverity.Disable; // disable writing of debug.log
                cefSettings.UncaughtExceptionStackSize = 100;  // enable stack capture
                cefSettings.CachePath = TempDir;               // enable cache for external resources to speedup loading
                CefSharpSettings.LegacyJavascriptBindingEnabled = true;

                foreach (var scheme in CustomSchemes)
                {
                    cefSettings.RegisterScheme(new CefCustomScheme()
                    {
                        SchemeName           = scheme,
                        SchemeHandlerFactory = new CefSchemeHandlerFactory()
                    });
                }

                cefSettings.BrowserSubprocessPath = CefLoader.GetBrowserSubProcessPath();

                Cef.Initialize(cefSettings, performDependencyCheck: false, browserProcessHandler: null);

                if (Application.Current != null)
                {
                    Application.Current.Exit += OnApplicationExit;
                    subscribedApplicationExit = true;
                }
            }
        }
Esempio n. 5
0
 private static void InitializeCef()
 {
     if (!Cef.IsInitialized)
     {
         CefSettings cefSettings = new CefSettings();
         cefSettings.LogSeverity = LogSeverity.Disable;
         cefSettings.UncaughtExceptionStackSize = 100;
         cefSettings.CachePath = WebView.TempDir;
         cefSettings.WindowlessRenderingEnabled               = true;
         CefSharpSettings.LegacyJavascriptBindingEnabled      = true;
         CefSharpSettings.SubprocessExitIfParentProcessClosed = true;
         foreach (string schemeName in WebView.CustomSchemes)
         {
             cefSettings.RegisterScheme(new CefCustomScheme
             {
                 SchemeName           = schemeName,
                 SchemeHandlerFactory = new CefSchemeHandlerFactory()
             });
         }
         cefSettings.BrowserSubprocessPath = CefLoader.GetBrowserSubProcessPath();
         Cef.Initialize(cefSettings, false, browserProcessHandler:  null);
         if (System.Windows.Application.Current != null)
         {
             System.Windows.Application.Current.Exit += WebView.OnApplicationExit;
             WebView.subscribedApplicationExit        = true;
         }
     }
 }
Esempio n. 6
0
    /// <summary>
    /// Download CEF runtime files.
    /// </summary>
    /// <exception cref="Exception"></exception>
    public static void Download(ChromelyPlatform platform)
    {
        Logger.Instance.Log.LogInformation("CefLoader: Installing CEF runtime from " + CefBuildsDownloadUrl);

        var loader = new CefLoader(platform);

        try
        {
            var watch = new Stopwatch();
            watch.Start();
            loader.GetDownloadUrl();
            if (!loader.ParallelDownload())
            {
                loader.Download();
            }
            Logger.Instance.Log.LogInformation("CefLoader: Download took {watch.ElapsedMilliseconds}ms", watch.ElapsedMilliseconds);
            watch.Restart();
            loader.DecompressArchive();
            Logger.Instance.Log.LogInformation("CefLoader: Decompressing archive took {watch.ElapsedMilliseconds}ms", watch.ElapsedMilliseconds);
            watch.Restart();
            loader.CopyFilesToAppDirectory();
            Logger.Instance.Log.LogInformation("CefLoader: Copying files took {watch.ElapsedMilliseconds}ms", watch.ElapsedMilliseconds);
        }
        catch (Exception ex)
        {
            Logger.Instance.Log.LogError("CefLoader: {ex.Message}", ex.Message);
            throw;
        }
        finally
        {
            if (!string.IsNullOrEmpty(loader._tempBz2File))
            {
                File.Delete(loader._tempBz2File);
            }

            if (!string.IsNullOrEmpty(loader._tempTarStream))
            {
                File.Delete(loader._tempTarStream);
            }

            if (!string.IsNullOrEmpty(loader._tempTarFile))
            {
                File.Delete(loader._tempTarFile);
            }
            if (!string.IsNullOrEmpty(loader._tempDirectory) && Directory.Exists(loader._tempDirectory))
            {
                Directory.Delete(loader._tempDirectory, true);
            }
        }
    }
Esempio n. 7
0
        private static void CheckArchiveName(int build)
        {
            var name = CefLoader.FindCefArchiveName(ChromelyPlatform.Windows, Architecture.X86, build);

            Assert.True(!string.IsNullOrEmpty(name), $"Not found {build} for Windows x86");

            name = CefLoader.FindCefArchiveName(ChromelyPlatform.Windows, Architecture.X64, build);
            Assert.True(!string.IsNullOrEmpty(name), $"Not found {build} for Windows x64");

            name = CefLoader.FindCefArchiveName(ChromelyPlatform.Linux, Architecture.X86, build);
            Assert.True(!string.IsNullOrEmpty(name), $"Not found {build} for Linux x86");

            name = CefLoader.FindCefArchiveName(ChromelyPlatform.Linux, Architecture.X64, build);
            Assert.True(!string.IsNullOrEmpty(name), $"Not found {build} for Linux x86");

            name = CefLoader.FindCefArchiveName(ChromelyPlatform.MacOSX, Architecture.X64, build);
            Assert.True(!string.IsNullOrEmpty(name), $"Not found {build} for MaxOSX x64");
        }
Esempio n. 8
0
    /// <summary>Load Cef binaries</summary>
    /// <param name="cefBinariesDownloader">The cef binaries downloader.</param>
    /// <param name="config">The chromely configuration.</param>
    /// <returns>The list of temporary files generated</returns>
    public static List <string> Load(ICefBinariesDownloader cefBinariesDownloader, IChromelyConfiguration config)
    {
        try
        {
            var platform = CefRuntime.Platform;
            var version  = CefRuntime.ChromeVersion;
            Logger.Instance.Log.LogInformation("Running {platform} chromium {version}", platform, version);

            try
            {
                CefRuntime.Load();
            }
            catch (Exception ex)
            {
                Logger.Instance.Log.LogError(ex);

                if (config.CefDownloadOptions.AutoDownloadWhenMissing)
                {
                    if (config.CefDownloadOptions.DownloadSilently)
                    {
                        cefBinariesDownloader.Download(config);
                        CefLoader.SetMacOSAppName(config);
                    }
                    else
                    {
                        var fileList = DownloadAndNotifyUser(cefBinariesDownloader, config);
                        CefLoader.SetMacOSAppName(config);
                        return(fileList);
                    }
                }
                else
                {
                    Environment.Exit(0);
                }
            }
        }
        catch (Exception ex)
        {
            Logger.Instance.Log.LogError(ex);
            Environment.Exit(0);
        }

        return(new List <string>());
    }
Esempio n. 9
0
        /// <summary>
        /// The load.
        /// </summary>
        /// <param name="config">
        /// The config.
        /// </param>
        /// <returns>
        /// The list of temporary files generated
        /// </returns>
        public static List <string> Load(ChromelyConfiguration config)
        {
            try
            {
                var platform = CefRuntime.Platform;
                var version  = CefRuntime.ChromeVersion;
                Log.Info($"Running {platform} chromium {version}");

                try
                {
                    CefRuntime.Load();
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    if (config.LoadCefBinariesIfNotFound)
                    {
                        if (config.SilentCefBinariesLoading)
                        {
                            CefLoader.Load();
                        }
                        else
                        {
                            return(WarnUserOnLoad());
                        }
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                Environment.Exit(0);
            }

            return(null);
        }
Esempio n. 10
0
        /// <summary>Load Cef binaries</summary>
        /// <param name="options">The config.</param>
        /// <param name="chromelyPlatform">The chromely platform.</param>
        /// <returns>The list of temporary files generated</returns>
        public static List <string> Load(ICefDownloadOptions options, ChromelyPlatform chromelyPlatform)
        {
            try
            {
                var platform = CefRuntime.Platform;
                var version  = CefRuntime.ChromeVersion;
                Logger.Instance.Log.Info($"Running {platform} chromium {version}");

                try
                {
                    CefRuntime.Load();
                }
                catch (Exception ex)
                {
                    Logger.Instance.Log.Error(ex);
                    if (options.AutoDownloadWhenMissing)
                    {
                        if (options.DownloadSilently)
                        {
                            CefLoader.Download(chromelyPlatform);
                        }
                        else
                        {
                            return(DownloadAndNotifyUser(chromelyPlatform));
                        }
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Log.Error(ex);
                Environment.Exit(0);
            }

            return(null);
        }
 /// <inheritdoc/>
 public void Download(IChromelyConfiguration config)
 {
     CefLoader.Download(config.Platform);
 }
Esempio n. 12
0
 internal static void Run()
 {
     CefLoader.RegisterCefSharpAssemblyResolver();
 }