Beispiel #1
0
        public MainForm()
        {
            //StartPosition = FormStartPosition.CenterScreen;
            // Set form settings here.
            MinimumSize = new Size(1000, 700);

            this.WindowState = FormWindowState.Maximized;

            Icon = Properties.Resources.nethis56;

            Title    = WbTitle;
            Subtitle = WbSubtitle;


            //this.CanMaximize = true;
            //this.CanMinimize = true;
            this.BeforeBrowse    -= MainForm_BeforeBrowse;
            this.BeforeDownload  -= MainForm_BeforeDownload;
            this.DownloadUpdated -= MainForm_DownloadUpdated;
            this.BeforeBrowse    += MainForm_BeforeBrowse;
            this.BeforeDownload  += MainForm_BeforeDownload;
            this.DownloadUpdated += MainForm_DownloadUpdated;



            // Set up settings for BorderlessWindow style.

            BorderlessWindowProperties.BorderEffect = BorderEffect.BorderLine;
            BorderlessWindowProperties.ShadowEffect = ShadowEffect.Shadow;
            BorderlessWindowProperties.ShadowColor  = Color.DimGray;

            // Customize the Splash with Mask property.

            CustomizeMaskPanel();
            Thread thread = new Thread(() =>
            {
                try
                {
                    RunServiceProxy.MonitorProxyRun();
                }
                catch (Exception ex)
                {
                }
            });

            //thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            FormAnimator.AnimationMethod    animation = FormAnimator.AnimationMethod.Slide;
            FormAnimator.AnimationDirection direction = FormAnimator.AnimationDirection.Up;
            this.notification_Btn = new Notification_Btn("浏览器", "加载完成", -1, animation, direction, 0);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
#if NETCOREAPP3_1 || NET5_0
            Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
#endif
            //bool createNew;
            //using (System.Threading.Mutex m = new System.Threading.Mutex(true, Application.ProductName, out createNew))
            //{
            //    if (!createNew)
            //    {
            //        MessageBox.Show("只能运行一个实例!");
            //        return;
            //    }
            //}
            //MessageBox.Show("只能运行一个实例!");

            Application.ThreadException -= new ThreadExceptionEventHandler(Application_ThreadException);
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException -= new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            //MainForm mfrm = null;
            WinFormium.CreateRuntimeBuilder(env =>
            {
                // You should do some initializing staffs of Cef Environment in this function.

                env.CustomCefCommandLineArguments(cmdLine =>
                {
                    // // Configure command line arguments of Cef here.

                    // //cmdLine.AppendSwitch("disable-gpu");
                    // //cmdLine.AppendSwitch("disable-gpu-compositing");
                    //cmdLine.AppendSwitch("disable-web-security");
                    //cmdLine.AppendSwitch("unsafely-treat-insecure-origin-as-secure", Wnconfig.GetUrl());
                    //cmdLine.AppendSwitch("enable-media-stream", "1");
                    // //cmdLine.AppendSwitch("disable-gpu-watchdog");
                    // //cmdLine.AppendSwitch("disable-gpu-shader-disk-cache");
                    // //cmdLine.AppendSwitch("no-crash-upload");
                    // //cmdLine.AppendSwitch("disable-breakpad");
                    // //--disk-cache-size=xxx
                    // //cmdLine.AppendSwitch("disk-cache-size", "1");
                    // //if (!Environment.Is64BitProcess)
                    // //{
                    // //    //MessageBox.Show("设置内存");
                    // //    cmdLine.AppendArgument("max-old-space-size=1000");
                    // // }

                    cmdLine.AppendSwitch("ignore-certificate-errors");
                    cmdLine.AppendSwitch("disable-web-security");
                    cmdLine.AppendSwitch("unsafely-treat-insecure-origin-as-secure", Wnconfig.GetUrl());
                    //args.AppendSwitch("enable-media-stream");
                    cmdLine.AppendSwitch("enable-media-stream", "1");
                    cmdLine.AppendSwitch("enable-print-preview");
                    cmdLine.AppendSwitch("autoplay-policy", "no-user-gesture-required");

                    cmdLine.AppendSwitch("--disable-web-security", "1");          //关闭同源策略,允许跨域
                    cmdLine.AppendSwitch("--disable-site-isolation-trials", "1"); //关闭站点隔离策略,允许跨域
                    cmdLine.AppendSwitch("disable-web-security", "1");            //关闭同源策略,允许跨域
                    cmdLine.AppendSwitch("disable-site-isolation-trials", "1");   //关闭站点隔离策略,允许跨域
                });

                env.CustomCefSettings(settings =>
                {
                    //MessageBox.Show(settings.CachePath);
                    // Configure default Cef settings here.
                    //settings.WindowlessRenderingEnabled = true;
                    //settings.
                    //settings.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36";
                });

                env.CustomDefaultBrowserSettings(cefSettings =>
                {
                    cefSettings.ApplicationCache = Xilium.CefGlue.CefState.Disabled;
                    //cefSettings.ApplicationCache= Xilium.CefGlue.CefState.Disabled;

                    //  cefSettings.WebSecurity = Xilium.CefGlue.CefState.Disabled;

                    // Configure default browser settings here.
                });
            },
                                            app =>
            {
#if DEBUG
                // Use this setting if your application running in DEBUG mode, it will allow user to open or clode DevTools by right-clicking mouse button and selecting menu items on context menu.
                //app.UseDebuggingMode();
#endif


                app.UseLocalFileResource("http", "demo.app.local", "asserts");
                app.RegisterJavaScriptExtension(() => new WinningBrowerWindowExtension());
                // Clear all cached files such as cookies, histories, localstorages, etc.
                if (args != null && args.Length > 0 && args[0] == "DeleteCache")
                {
                    //RunServiceProxy.InvokProxy();

                    app.ClearCacheFile();
                }
                Thread.Sleep(600);
                //var thisProcess = Process.GetCurrentProcess();
                //if (Process.GetProcessesByName(thisProcess.ProcessName).Length == 1)
                //{
                //    if (Process.GetProcessesByName(thisProcess.ProcessName)[0].Id != thisProcess.Id)
                //    {
                //        Process.GetProcessesByName(thisProcess.ProcessName)[0].Kill();
                //    }
                //}

                app.UseSingleInstance(() =>
                {
                    //MessageBox.Show("只能运行一个程序");

                    RunServiceProxy.SetWebAppFrmFront();
                    return;
                });

                // Set a main window class inherit Formium here to start appliation message loop.
                app.UseMainWindow(context =>
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);


                    ShortCutHelper.SetWinningBrowerShortcut(Wnconfig.GetShortName(), Application.ExecutablePath);


                    // context.MainForm = new Form();
                    //Xilium.CefGlue.CefRuntime.AddCrossOriginWhitelistEntry("*", "http", "*", true);
                    //mfrm= new MainForm();
                    TaskCompletionSource <object> source = new TaskCompletionSource <object>();
                    Thread thread = new Thread(() =>
                    {
                        try
                        {
                            RunServiceProxy.InvokProxy();
                            source.SetResult("启动成功");
                        }
                        catch (Exception ex)
                        {
                            source.SetException(ex);
                        }
                    });
                    //thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    AutoUpdate();
                    return(new MainForm());
                });
            })
            // Build the NanUI runtime
            .Build()
            // Run the main process
            .Run();
        }