Build your cross-platform, natively executable web app in 3 minutes! #dotnetconf

 Much kudos to John Juback (@jjuback)


You'll need

  • Visual Studio Code


In a console/terminal window, type

mkdir Processes

cd Processes

dotnet new webapp

code .


In Processes.csproj, add

  <ItemGroup>
    <PackageReference
      Include="ElectronNET.API"
      Version="9.31.2"/>
  </ItemGroup>

In Program.cs, add

  using ElectronNET.API; on line 9


                    webBuilder.UseElectron(args);
                    webBuilder.UseEnvironment("Development");

on line 24

In Startup.cs, add

  using ElectronNET.API; on line 11

            if (HybridSupport.IsElectronActive) {
                CreateWindow();
            }   

on line 56

        private async void CreateWindow() {
            var window = await Electron.WindowManager.CreateWindowAsync();
            window.OnClosed += () => {
                Electron.App.Quit();
            };
        }

on line 61

In Visual Studio Code's terminal window, run


dotnet tool install ElectronNET.CLI -g

electronize init

In Index.cshtml.cs, add


using System.Diagnostics; on line 8

public List<Process> Processes { get; set; } on line 15

            Processes = Process
                .GetProcesses()
                .Where(p => !String.IsNullOrEmpty(p.ProcessName))
                .ToList(); on line 25

In Index.cshtml, add


<table id="myTable" class="table table-sm table-striped">
    <thead class="thead-dark">
        <tr class="d-flex">
            <th scope="col" class="col-sm-2"> Id </th>
            <th scope="col" class="col-sm-6"> Process Name </th>
            <th scope="col" class="col-sm-4 text-right"> Physical Memory </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model.Processes)
        {
            <tr class="d-flex">
                <td class="col-sm-2"> @item.Id </td>
                <td class="col-sm-6"> @try{@item.MainModule.ModuleName}catch{@item.ProcessName} </td>
                <td class="col-sm-4 text-right"> @item.WorkingSet64 </td>
            </tr>
        }
    </tbody>
</table>

In Visual Studio Code's terminal window, run


electronize start


... and you're off and running!

Comments

Popular posts from this blog

Auto Mapper and Record Types - will they blend?

Unit testing your Azure functions - part 2: Queues and Blobs

Testing WCF services with user credentials and binary endpoints