Git Product home page Git Product logo

electronnet.blazor's Introduction

ElectronNET.Blazor

A library to help Blazor and Electron.NET work better together.

Acknowledgements

Special thanks to the Electron.NET team for building an amazing resource, and to Maher Jendoubi for setting me down the path to making this work with his article on adding Electron.NET to BlazingPizza.

How to Use

Electron.NET can be applied to any Blazor app that uses the "Blazor (ASP.NET Core Hosted)" template. This is because there has to be something that serves up the web page to the Chrome instance, and .NET Core MVC apps are just compiled EXEs anyway. Standalone apps won't work because there won't be any built-in way to serve up the resources.

Installation Instructions:

  1. Add the https://www.nuget.org/packages/ElectronNET.Blazor NuGet package to your project.

  2. Modify the Program.cs of your Server app to look like this:

        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();
            host.Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder
                        .UseElectron(args)
                        .UseStartup<Startup>();
                });

    }
  1. Modify the Startup.cs file of your Server app to look like this (pay attention, the registration order is important):
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseResponseCompression();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBlazorDebugging();
            }

            app.UseElectronNETStaticFiles<Client.Startup>();

            app.UseClientSideBlazorFiles<Client.Startup>();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapDefaultControllerRoute();
                endpoints.MapFallbackToClientSideElectronNET<Client.Startup>("index.html");
            });

            Task.Run(async () => await Electron.WindowManager.CreateWindowAsync());
        }
  1. Open Windows Explorer, navigate to the root folder of your solution, then hold down the Shift key while right-clicking that folder, and select "Open Powershell window here".

  2. Run the following command:

dotnet tool install ElectronNET.CLI -g
  1. Run the following command:
electronize init
  1. Open the Project Properties of your Server project, open the Debug tab, and under "Environment Variables", add an IS_ELECTRON variable with the value of true.

    image

  2. Next to the green arrow that starts debugging, make sure the "Electron.NET App" profile is selected, and then hit the green button.

    image

  3. PROFIT!!!

electronnet.blazor's People

Contributors

gep13 avatar robertmclaws avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.