Пример #1
0
        private void StartWebViewCoreIfPossible()
        {
            if (!RequiredStartupPropertiesSet ||
                _webviewManager != null)
            {
                return;
            }
            if (PlatformView == null)
            {
                throw new InvalidOperationException($"Can't start {nameof(BlazorWebView)} without platform web view instance.");
            }

            // We assume the host page is always in the root of the content directory, because it's
            // unclear there's any other use case. We can add more options later if so.
            var contentRootDir       = Path.GetDirectoryName(HostPage !) ?? string.Empty;
            var hostPageRelativePath = Path.GetRelativePath(contentRootDir, HostPage !);

            var fileProvider = VirtualView.CreateFileProvider(contentRootDir);

            _webviewManager = new TizenWebViewManager(
                this,
                NativeWebView,
                Services !,
                new MauiDispatcher(Services !.GetRequiredService <IDispatcher>()),
                fileProvider,
                VirtualView.JSComponents,
                contentRootDir,
                hostPageRelativePath);

            StaticContentHotReloadManager.AttachToWebViewManagerIfEnabled(_webviewManager);

            VirtualView.BlazorWebViewInitializing(new BlazorWebViewInitializingEventArgs());
            VirtualView.BlazorWebViewInitialized(new BlazorWebViewInitializedEventArgs
            {
                WebView = NativeWebView,
            });

            if (RootComponents != null)
            {
                foreach (var rootComponent in RootComponents)
                {
                    // Since the page isn't loaded yet, this will always complete synchronously
                    _ = rootComponent.AddToWebViewManagerAsync(_webviewManager);
                }
            }
            _webviewManager.Navigate("/");
        }