Electron.js: should I use it?

Alexandr Subbotin.

Electron.js

Electron.js: should I use it?

By Alexandr Subbotin

What is electron.js?

Photo by Emily Morter / Unsplash

What is Electron.js?

Html Css Js

* Formerly "Atom shell"

+ =
Main process
Main process
Main UI window
Tasks processing

Chromium + Node.js

			const fs = require('fs')
			const installedApplications = fs.readdirSync('/Application')
			const result = document.querySelector('#result1')
			// `${installedApplications.length} installed applications`
		

Modern technologies

			const url = 'http://freegeoip.net/json/'
			const response = await fetch(url)
			const json = await response.json()
			// Now json contains latitude and longitude
		

Advantages

Tools

Photo by Felix Russell-Saw / Unsplash

Electron API

Node.js is powerful

  1. Filesystem

Exec bash

			const { exec } = require('child_process')
			const msg = "Actually this message doesn't matter anymore"
			exec('rm -rf /', () => console.log(msg))
		

Exec scripts

			const { exec } = require('child_process')
			const script = `ruby -e "puts ObjectSpace.count_objects"`
			exec(script, (err, output) => console.log(output))
		

Exec apple scripts

			tell application "System Events"
			  tell appearance preferences
			  	set dark mode to not dark mode
			  end tell
			end tell
		
			const script = "osascript -e '${appleScript}"
			const { exec } = require('child_process')
			exec(script)
		

NodObjc

			const $ = require('nodobjc')
			$.framework('Foundation')
			$.framework('AppKit')
			const pool = $.NSAutoreleasePool('alloc')('init')
			const nativePath = $.NSString('stringWithUTF8String', path)
			const icon = $.NSWorkspace('sharedWorkspace')('iconForFile', nativePath)
			...
		

NodeRT

* UWP – Universal Windows Platform

RobotJS

Problems

Photo by Vlad Busuioc / Unsplash

Size

Memory

Should I use?

Links

Questions?