ElectronNET: cross platform GUI for .NET 5

Repo Man

I have been playing a bit with Cincom VisualWorks for a lot of nostalgic reasons and appreciating how good it is. However, no matter how cool and personally productive it is, as a tool for making programs for other people it has some shortcomings. If I'm going to build a cross-platform app that gets distributed to customers, I probably want to use something a little more mainstream. .NET Core is my weapon of choice and where the rest of my code base is, but it still doesn't have a cross-platform GUI solution. Electron is what VSCode uses so let's see if we can get that working with .NET. That means being a good old repo man (i.e. hitting up the repositories, not so much repossessing cars ha ha). I followed the instructions here and got ElectronNET set up on Windows 11 and on Debian Buster.

On Windows, the demo worked out of the box. On Debian, I got this error message:

[23059:0826/093421.418802:FATAL:setuid_sandbox_host.cc(158)] The SUID sandbox helper binary was found, but is not configured correctly. Rather than run without sandboxing I'm aborting now. You need to make sure that /home/drubie/Documents/GitHub/SmartShepherdServer/BlazorApp/obj/Host/node_modules/electron/dist/chrome-sandbox is owned by root and has mode 4755.

Never broke into a car, never hotwired a car. Never broke into a truck. 'I shall not cause harm to any vehicle nor the personal contents thereof, nor through inaction let the personal contents thereof come to harm' It's what I call the Repo Code, kid!

You might think "so what, just follow the instructions" but wow, you really need to change the ownership of that file to root and then PUT THE SETUID BIT ON IT. That is bad. For young players, that means that when the chrome_sandbox executable is kicked off, it assumes all the power of the all-powerful administrative account of my box. I don't like it. It's a google program and they do have something of an explanation here.

However, once I changed the permissions, the demo started right up:

Note - this is about a thousand times easier than trying to get Photino running, and .NET Maui doesn't do Linux yet, so ElectronNET is about the only game in town. Using Blazor should also make it reasonably easy for me to make progress. For the record, Photino was relatively easy to get working on Windows but on Linux the WebKitGTK window stubbornly refused to open a local file using the file: protocol, so I binned it without investigating very far.

It happens sometimes, people just explode. Natural causes.

Kicking of an external process isn't the single line that you use in Smalltalk, it's quite verbose:

private String RunCommand(String cmd, String args)
        {
            Process runProcess = new Process();
            runProcess.StartInfo.FileName = cmd;
            runProcess.StartInfo.Arguments = args;

            // Set UseShellExecute to false for redirection.
            runProcess.StartInfo.UseShellExecute = false;
            runProcess.StartInfo.RedirectStandardOutput = true;
            // Start the process.
            runProcess.Start();

            runProcess.WaitForExit();

            return runProcess.StandardOutput.ReadToEnd().ToString();
        }
        public String ListTablesRaw()
        {
            return RunCommand("aws", "dynamodb list-tables");
        
        }
Compared to VisualWorks Smalltalk (including a conversion to a Dictionary with the Json converter).
listTables
	"list all the tables in my current dynamodb setup"

	^Xtreams.JSON decode: (ExternalProcess fork: 'aws' arguments: #('dynamodb' 'list-tables'))

I am sighing a little. Smalltalk is neat.

Painfully, the .NET core debugger in VSCode won't reliably attach to the Blazor app when it's feeding an Electron display. However, if you launch the Blazor app as usual (i.e. without electron) you can debug it while it displays in Chrome, then test in Electron (type "electronize start"). Not the end of the world by any means.

But about an hour after I kicked off the tool installs configured the environment, I ended up with this:

Using the "System.Text.Json" parser and a little bit of process start magic, it comes alive. I think it helps that I'm more familiar with C# and Blazor than my rusty VisualWorks skills. It isn't terribly fast but it doesn't need to be. Will port the rest of my commands over to this app and see how it looks. One big difference is that you can get away with being lazy in Smalltalk and just dump the data out to the screen, which I guess I could do here (and probably should) but it would be better if the information coming out was clickable / copyable). Still, something of a success I think. Time from nothing to working on a simple example was roughly comparable to VisualWorks. It's fairly painful to go back to editing entire files instead of iterating at the individual method level and .NET Core doesn't really allow free-form experiments (a major shame) but if somebody smarter than me wants to set up something based on Roslyn that worked a bit like Smalltalk I think you might have something interesting. I am somewhat concerned that the chrome-sandbox would need to be shipped with a packaged executable and also require the setuid bit on it, which would be a major no no for most customers on Linux or Mac.

Popular posts from this blog

Tailscale ate my network (and I love it)

Stupid stunts with WSL2 , Python3 and AWS ECS

Time machine: Solaris 2.6 on QEMU