123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using CefSharp;
- using CefSharp.Wpf;
- using FISLib;
- using FISSDKDemoV2.Manager;
- using FISSDKDemoV2.Model.GC;
- using FISSDKDemoV2.Model.Log;
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Windows;
- using System.Windows.Threading;
- namespace FISSDKDemoV2
- {
- /// <summary>
- /// App.xaml 的交互逻辑
- /// </summary>
- public partial class App : Application
- {
- protected override void OnStartup(StartupEventArgs e)
- {
- CheckedOpenRepeatedly();
- var rootPath = "D:";
- if (!Directory.Exists(rootPath))
- {
- rootPath = Path.GetPathRoot(AppDomain.CurrentDomain.BaseDirectory);
- }
- var fisLogPath = Path.Combine(rootPath, "FISLogFolder");
- Logger.RegisterEngine(new DefaultLogEngine(fisLogPath));
- GCLogger.RegisterEngine(new GCLogEngine(fisLogPath));
- GcAdapter.Instance.RegisterForFullGCNotification(99, 99);
- AppDomain.CurrentDomain.UnhandledException += OnDomainOnUnhandledException;
- Current.DispatcherUnhandledException += OnDispatcherUnhandledException;
- InitCefSharp();
- base.OnStartup(e);
- }
- private void InitCefSharp()
- {
- try
- {
- var settings = new CefSettings
- {
- Locale = "zh-CN",
- LogSeverity = LogSeverity.Disable,
- IgnoreCertificateErrors = true,
- BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CefSharp", "x64", "CefSharp.BrowserSubprocess.exe"),
- };
- //允许媒体自动播放,而无需用户交互。
- settings.CefCommandLineArgs.Add("autoplay-policy", "no-user-gesture-required");
- //启用打印预览功能
- settings.CefCommandLineArgs.Add("--enable-print-preview", "1");
- //允许使用媒体流(例如麦克风和摄像头)。
- settings.CefCommandLineArgs.Add("enable-media-stream", "1");
- //允许屏幕捕捉,这通常用于屏幕共享或录制。
- settings.CefCommandLineArgs.Add("enable-usermedia-screen-capturing", "1");
- //允许语音输入
- settings.CefCommandLineArgs.Add("enable-speech-input", "1");
- //禁用Web安全策略,允许跨源请求,但这可能会带来安全风险
- settings.CefCommandLineArgs.Add("--disable-web-security", "1");
- //允许HTTP屏幕捕获
- settings.CefCommandLineArgs.Add("allow-http-screen-capture", "1");
- //自动选择桌面捕捉源为整个屏幕
- settings.CefCommandLineArgs.Add("--auto-select-desktop-capture-source", "Entire screen");
- //使用假的UI来请求媒体流(例如摄像头和麦克风),而不显示真实的权限请求对话框
- settings.CefCommandLineArgs.Add("--use-fake-ui-for-media-stream", "1");
- //启用专有编解码器,这可以支持更多的视频格式
- settings.CefCommandLineArgs.Add("proprietary_codecs", "1");
- //启用剪贴板访问
- settings.CefCommandLineArgs.Add("--enable-clipboard", "1");
- //使用Chrome版本的FFmpeg,这可以支持更多的媒体格式
- settings.CefCommandLineArgs.Add("ffmpeg_branding", "Chrome");
- // 允许CEF访问剪贴板
- settings.CefCommandLineArgs.Add("allow-cef-access-to-clipboard", "1");
- //允许从文件访问文件,通常用于本地HTML页面可以读取其他本地文件。
- settings.CefCommandLineArgs.Add("allow-file-access-from-files", "1");
- settings.CefCommandLineArgs.Add("unsafely-treat-insecure-origin-as-secure", "http://192.168.6.103:8081,http://192.168.6.62:8081,http://192.168.6.71:8081,http://192.168.6.117:8081");
- //CefSharpSettings.LegacyJavascriptBindingEnabled = true;
- CefSharpSettings.ShutdownOnExit = false;
- #if DEBUG
- settings.RemoteDebuggingPort = 8088;
- #endif
- Cef.Initialize(settings);
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"CefInit Error:{ex}");
- PageManager.Instance.ShowMessageBoxInMainWindow(FISDeviceLogCategory.Error, $"CefInit Error:{ex}");
- }
- }
- private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
- {
- Logger.WriteLineError($"OnDispatcherUnhandledException:{e.Exception}");
- e.Handled = true;
- PageManager.Instance.ShowMessageBoxInMainWindow(FISDeviceLogCategory.Error, $"OnDispatcherUnhandledException{e.Exception}");
- }
- private void OnDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- Logger.WriteLineError($"OnDomainOnUnhandledException:{e.ExceptionObject}");
- PageManager.Instance.ShowMessageBoxInMainWindow(FISDeviceLogCategory.Error, $"OnDomainOnUnhandledException:{e.ExceptionObject}");
- }
- /// <summary>
- /// 判断是否重复打开
- /// </summary>
- private void CheckedOpenRepeatedly()
- {
- var thisProcess = Process.GetCurrentProcess();
- if (Process.GetProcessesByName(thisProcess.ProcessName).Where(x => x.ProcessName == thisProcess.ProcessName).Count() > 1)
- {
- PageManager.Instance.ShowMessageBoxInMainWindow(FISDeviceLogCategory.Warn, $"已有相同程序正在运行中,此程序即将退出。");
- thisProcess.Kill();
- }
- }
- }
- }
|