Esempio n. 1
0
        public WinFormsWindow(WindowConfiguration config, IUiFactory windowFactory)
        {
            if (windowFactory == null)
            {
                throw new ArgumentNullException(nameof(windowFactory));
            }

            this.config = config ?? throw new ArgumentNullException(nameof(config));

            bridge = new WebviewBridge();
            var contentProvider = new EmbeddedFileProvider(config.ContentAssembly, config.ContentFolder);

            if (!config.ForceWindowsLegacyWebview && IsEdgeAvailable())
            {
                webview = new WinFormsWebview(config, contentProvider, bridge);
            }
            else
            {
                string hostAddress;
                if (string.IsNullOrWhiteSpace(config.ExternalHost))
                {
                    server = new ContentServer(contentProvider);
                    server.Start();
                    hostAddress = server.HostAddress;
                }
                else
                {
                    hostAddress = config.ExternalHost;
                }

                webview = new WinFormsLegacyWebview(config, hostAddress, bridge);
            }

            webview.Control.Location = new Point(0, 0);
            webview.Control.Dock     = DockStyle.Fill;
            Controls.Add(webview.Control);

            Text      = config.Title;
            Width     = config.Width;
            Height    = config.Height;
            CanResize = config.CanResize;

            ColorTools.ParseHex(config.BackgroundColor, out byte r, out byte g, out byte b);
            BackColor = Color.FromArgb(r, g, b);

            if (config.EnableScriptInterface)
            {
                bridge.Init(this, webview, windowFactory);
            }

            if (config.UseBrowserTitle)
            {
                bridge.TitleChanged += Webview_TitleChanged;
            }

            SetIcon(config.Icon);
        }
Esempio n. 2
0
 /// <nodoc />
 public ServerServiceDefinition Bind() => ContentServer.BindService(_adapter);
Esempio n. 3
0
 /// <nodoc />
 public ServerServiceDefinition[] Bind() => new ServerServiceDefinition[]
 {
     ContentServer.BindService(GrpcAdapter)
 };