Пример #1
0
        /// <summary>
        /// Starts an Electron process using the specified JavaScript file as the host entrypoint.
        /// </summary>
        public static void Run <TStartup>(string hostJsPath)
        {
            Launcher.StartElectronProcess(async() =>
            {
                var window = await Launcher.CreateWindowAsync(hostJsPath);
                JSRuntime.SetCurrentJSRuntime(Launcher.ElectronJSRuntime);

                var serviceCollection = new ServiceCollection();
                serviceCollection.AddSingleton <IUriHelper>(ElectronUriHelper.Instance);
                serviceCollection.AddSingleton <IJSRuntime>(Launcher.ElectronJSRuntime);

                var startup = new ConventionBasedStartup(Activator.CreateInstance(typeof(TStartup)));
                startup.ConfigureServices(serviceCollection);

                var services = serviceCollection.BuildServiceProvider();
                var builder  = new ElectronApplicationBuilder(services);
                startup.Configure(builder, services);

                ElectronUriHelper.Instance.InitializeState(
                    Launcher.InitialUriAbsolute,
                    Launcher.BaseUriAbsolute);

                var renderer = new ElectronRenderer(services, window);
                foreach (var rootComponent in builder.Entries)
                {
                    _ = renderer.AddComponentAsync(rootComponent.componentType, rootComponent.domElementSelector);
                }
            });
        }
        /// <summary>
        /// Starts an Electron process using the specified JavaScript file as the host entrypoint.
        /// </summary>
        public static void Run <TStartup>(string hostJsPath)
        {
            Launcher.StartElectronProcess(async() =>
            {
                var window = await Launcher.CreateWindowAsync(hostJsPath);

                var serviceCollection = new ServiceCollection();
                serviceCollection.AddLogging(configure => configure.AddConsole());
                serviceCollection.AddSingleton <NavigationManager>(ElectronNavigationManager.Instance);
                serviceCollection.AddSingleton <IJSRuntime>(Launcher.ElectronJSRuntime);
                serviceCollection.AddSingleton <INavigationInterception, ElectronNavigationInterception>();

                var startup = new ConventionBasedStartup(Activator.CreateInstance(typeof(TStartup)));
                startup.ConfigureServices(serviceCollection);

                var services = serviceCollection.BuildServiceProvider();
                var builder  = new ElectronApplicationBuilder(services);
                startup.Configure(builder, services);

                var loggerFactory = services.GetRequiredService <ILoggerFactory>();

                Launcher.ElectronRenderer = new ElectronRenderer(services, window, loggerFactory);
                Launcher.ElectronRenderer.UnhandledException += (sender, exception) =>
                {
                    Console.Error.WriteLine(exception);
                };

                foreach (var rootComponent in builder.Entries)
                {
                    _ = Launcher.ElectronRenderer.AddComponentAsync(rootComponent.componentType, rootComponent.domElementSelector);
                }
            });
        }