Beispiel #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            string cachePath = AppDomain.CurrentDomain.BaseDirectory + "cache";

            if (Directory.Exists(cachePath))
            {
                Directory.Delete(cachePath, true);
            }
            cachePath = AppDomain.CurrentDomain.BaseDirectory + "cookies";
            if (Directory.Exists(cachePath))
            {
                Directory.Delete(cachePath, true);
            }


            CefManager.Strat();

            logger = new LoggerFacade().GetInstance("DS.AFP.WPF.App");
            logger.Debug("WPF宿主容器开始启动");
            bootstrapper = new Bootstrapper(logger);
            bootstrapper.Run();
            EventAggregator = Bootstrapper.EventAggregator;
            logger.Debug("WPF宿主容器启动完成,运行正常!");


            EventAggregator.GetEvent <BrowserExitEventSignal>().Subscribe(o =>
            {
                App.Current.Shutdown();
            }, ThreadOption.UIThread, true);

            AddTrayIcon();
        }
Beispiel #2
0
 void IRequestHandler.OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status)
 {
     //AppLogger.Instance.Log($"Render has been terminated, status: {status}, content:{browserControl.Address}");
     if (!CefManager.ReloadBrowser(browserControl))
     {
         //AppLogger.Instance.Log($"reload is blocked, content:{browserControl.Address}, app will be killed");
         System.Diagnostics.Process.GetCurrentProcess().Kill();
     }
 }
Beispiel #3
0
        public virtual void CloseFrame(CloseTypes type = CloseTypes.CloseSelf)
        {
            this.InvokeActionSafely(() =>
            {
                base.Hide();
                this.RestoreBrowser();
            });

            if (type == CloseTypes.Hide2Tray)
            {
                return;
            }

            if (type == CloseTypes.CloseSelf && this._options.IsMain)
            {
                type = CloseTypes.CloseApp;
            }

            if (type == CloseTypes.CloseApp)
            {
                var cancellationTokenSource = new CancellationTokenSource();
                Task.Run(async() =>
                {
                    await Task.Delay(10000);
                    if (!cancellationTokenSource.Token.IsCancellationRequested)
                    {
                        Process.GetCurrentProcess().Kill();
                    }
                }, cancellationTokenSource.Token);

                base.Close();

                CefManager.Shutdown();
                //Application.Exit();
                Environment.Exit(0);

                cancellationTokenSource.Cancel();
            }
            else
            {
                Task.Run(async() =>
                {
                    try
                    {
                        await Task.Delay(5000);
                        this?.InvokeActionSafely(() =>
                        {
                            base.Close();
                            this.Browser?.Dispose();
                        });
                    }
                    catch
                    {
                    }
                });
            }
        }
Beispiel #4
0
        private static void GlobalSetting()
        {
            GlobalConfig.AppOptions = new AppOptions
            {
                Name            = "CefSample",
                Title           = "AppTitle",
                ResAssemblyName = "CefBox.WinForm.Sample.exe",
                ResNamespace    = "CefBox.WinForm.Sample.Res"
            };

            //set config file path if neccesary
            AppConfiguration.ConfigFilePath = Path.Combine(GlobalConfig.AppOptions.HomePath, "settings.ini");

            CefManager.Init(settngs =>
            {
                //add other settings if neccesary
            });
        }
Beispiel #5
0
        private void LoadCEF(CefOptions cefOptions, object extendParam = null)
        {
            var _contentPath = string.Empty;

            if (!string.IsNullOrEmpty(cefOptions.ContentPath) && cefOptions.ContentPath.StartsWith("chrome://"))
            {
                _contentPath = cefOptions.ContentPath;
            }
            else
            {
                _contentPath = cefOptions.IsRelativeContent ? Path.Combine(cefOptions.BasePath, cefOptions.ContentPath) : cefOptions.ContentPath;
            }

            if (!cefOptions.IsRelativeContent && !Uri.IsWellFormedUriString(_contentPath, UriKind.RelativeOrAbsolute))
            {
                throw new ArgumentException("invalid content path found", _contentPath);
            }

            var checkPath = _contentPath;
            var param     = string.Empty;
            var pathArray = _contentPath.Split('?');

            if (pathArray.Length > 1)
            {
                checkPath = pathArray[0];
                param     = $"?{pathArray[1]}";
            }

            //如果本地存在文件,需要将本地路径中的特殊字符转掉,通常发生在debug环境下
            if (File.Exists(checkPath))
            {
                _contentPath = checkPath.ToAppPath() + param;
            }

            if (this._localBrowser == null)
            {
                this.InitLocalBrowser(_contentPath, extendParam);
                CefManager.LoadBrowser(this._localBrowser, cefOptions);
            }
            else if (this._localBrowser.Address != _contentPath)
            {
                this._localBrowser.Load(_contentPath);
            }
        }
Beispiel #6
0
        protected override void OnStartup(StartupEventArgs args)
        {
            CefManager.Initialize();

            base.OnStartup(args);

            var wnd = new MainWindow();

            Current.MainWindow = wnd;

            wnd.DataContext = new MainWindowViewModel()
            {
                WebBrowser     = wnd.Browser,
                BrowserAddress = "",
            };

            Current.MainWindow.Show();
            Current.MainWindow.Closed += (s, e) => Current.Shutdown(0);
        }
Beispiel #7
0
        protected override void OnExit(ExitEventArgs e)
        {
            CefManager.Shutdown();

            base.OnExit(e);
        }
Beispiel #8
0
 private void Application_Exit(object sender, ExitEventArgs e)
 {
     CefManager.Close();
 }