Javascript electron
Table of Content
Introduction
Native node modules
Recommended to use electron-build (e.g. bycrypt)
Debugging
mainWindow.webContents.openDevTools()
App object
Prevent app from quitting
Browser window
setup
use loadFile
instead of loadURL
Load content
Get user data (information of the user logged in)
app.getPath('userData')
Showing window gracefully
Or...
parent & child
frameless window
browser window properties and methods (options)
State management on windows
electron-window-state
package
Web contents (broweser window)
Instance vs static
Prevent window creation
Before event
Login
Did navigate
Context menu
Execute javascript
wc.executeJavascript()
Session
- Session share sessions
Default session is also used
Custom session
clear session
clear on instance
ses.clearStorageData()
Cookies
Download item
Use html attribute property download
on a a
tag
Dialog
accelerators & global shortcuts
Menu
- menu is like a system bar
- could be exported to a separate file
- roles (already integrated menu actions)
- shortcuts are only triggered when app is in focus
Context menu
Tray
Power Monitor
Screen
- used only when app is ready
Renderer process
Browser window proxy
- we can control window properties
Web frame
- zoom
- spelling and grammar
- resources
Desktop capturer
IPC communication
- inter process communication
main.js
renderer.js
Remote module
- risky exposing node js to users
- performance penalty
- accessing electron node modules in renderer process
main.js
renderer.js
Disabled remote and calling electron modules from renderer
main.js
renderer.js
Shared api
Process
- available at main process
- available at renderer process when node integration is true
- available process methods
- hang()
- crash()
Shell
use default applications for resource usage
- openExternal
- openPath
- showItemInFolder
- moveItemToTrash
Native images
main.js
renderer.js
Clipboard
Features & techniques
offscreen rendering
- The "paint" event will fire each time a section of the webContents is rendered to a BrowserWindow. This happens regardless of the webContents being visible or not and is useful for handling off-screen content rendering.
main.js
Network detection
- exclusive to the renderer process
- there are events that report if app is online or offline
Notifications
- clicking the notification focuses the app
Preload scripts
preload.js
main.js
Progress bar
- loading bar for an app depending on the operating system
mainWindow.setProgressBar(-1)
remove the progress bar
Application distribution
Electron builder
CloudConvert is an online file converter. We support nearly all audio, video, document, ebook, archive, image, spreadsheet, and presentation formats. To get started, use the button below and select files to convert from your computer. Cloud convert
Code signing
Code Signing Certificates allow you to add digital signatures to your executables, enable software developers to include information about themselves and the integrity of their code with their software. The end users that download digitally signed 32-bit or 64-bit executable files (.exe, .ocx, .dll, .cab, and more) can be confident that the code really comes from you and has not been altered or corrupted since it was signed. Comodo ssl store Apple Developer
Publishing releases
Electron builder: A complete solution to package and build a ready for distribution Electron app for macOS, Windows and Linux with “auto update” support out of the box.
AutoUpdater module
MacOs
Notarize
Hardened runtime
The Hardened Runtime, along with System Integrity Protection (SIP), protects the runtime integrity of your software by preventing certain classes of exploits, like code injection, dynamically linked library (DLL) hijacking, and process memory space tampering. To enable the Hardened Runtime for your app, navigate in Xcode to your target’s Signing & Capabilities information and click the + button. In the window that appears, choose Hardened Runtime.