Esempio n. 1
0
        static void Main(string[] args)
        {
            var html    = @"<html><body><h1>Eval</h1><div id='content'></div></body></html>";
            var webview = new WebviewBuilder("Eval", Content.FromHtml(html))
                          .WithSize(new Size(1024, 768))
                          .WithInvokeCallback((view, payload) => Console.WriteLine($"Hello {payload}"))
                          .Debug()
                          .Build();

            TimeSpan duration = TimeSpan.FromMilliseconds(1000);
            DateTime timeout  = DateTime.Now;

            int tick = 0;

            while (webview.Loop() == 0)
            {
                if (DateTime.Now > timeout)
                {
                    timeout = DateTime.Now + duration;
                    webview.Eval(@"document.getElementById('content').textContent = 'Time:" + DateTime.Now.ToString() + "'");
                }

                if (tick % 100 == 0)
                {
                    webview.Eval($@"external.invoke('world @ {tick}')");
                }

                GC.Collect();

                webview.Title = $"Eval - tick:{tick++.ToString()}";
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Run the host with the given webview.
        /// <para>
        ///  This runs both the main loop of the ASP .NET Core app and the main
        ///  loop of the <see cref="Webview" />. When the view is closed the
        ///  server is stopped
        /// </para>
        /// </summary>
        /// <param name="host">The host to run.</param>
        /// <param name="builder">The builder to connect to the app.</param>
        public static void RunWebview(this IWebHost host, WebviewBuilder builder)
        {
            host.Start();
            var content = new WebHostContent(host);

            builder.WithContent(content).Build().Run();
            host.StopAsync();
        }
Esempio n. 3
0
        public static void RunWebview(this IWebHost host, WebviewBuilder builder)
        {
            host.Start();
            var      features = host.ServerFeatures.Get <IServerAddressesFeature>();
            string   address  = features.Addresses.FirstOrDefault();
            IContent content  = Content.FromUri(new Uri(address));

            builder.WithContent(content).Build().Run();
            host.StopAsync();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var html    = @"<html><body><h1>Eval</h1><div id='content'></div></body></html>";
            var webview = new WebviewBuilder("Eval", Content.FromHtml(html))
                          .WithSize(new Size(1024, 768))
                          .Debug()
                          .Build();

            TimeSpan duration = TimeSpan.FromMilliseconds(1000);
            DateTime timeout  = DateTime.Now;

            int tick = 0;

            while (webview.Loop() == 0)
            {
                if (DateTime.Now > timeout)
                {
                    timeout = DateTime.Now + duration;
                    webview.Eval(@"document.getElementById('content').textContent = 'Time:" + DateTime.Now.ToString() + "'");
                }

                webview.Title = $"Eval - tick:{tick++.ToString()}";
            }
        }