Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
electron-reload
Advanced tools
This is (hopefully) the simplest way to load contents of all active BrowserWindow
s within electron when the source files are changed.
npm install electron-reload
Just initialize this module with desired glob or file path to watch and let it refresh electron browser windows as targets are changed:
'use strict';
const {app, BrowserWindow} = require('electron');
const electronReload = require('electron-reload')
// Standard stuff
app.on('ready', () => {
let mainWindow = new BrowserWindow({width: 800, height: 600});
mainWindow.loadUrl(`file://${__dirname}/index.html`);
// the rest...
});
Note that the above code only refreshes WebContent
s of all BrowserWindow
s. So if you want to have a hard reset (starting a new electron process) you can just pass the path to the electron executable in the options
object:
const path = require('path')
require('electron-reload')(__dirname, {
electron: path.join(__dirname, 'node_modules', '.bin', 'electron')
});
If your app overrides some of the default quit
or close
actions (e.g. closing the last app window hides the window instead of quitting the app) then the default electron-reload
hard restart could leave you with multiple instances of your app running. In these cases you can change the default hard restart action from app.quit()
to app.exit()
by specifying the hard reset method in the electron-reload options:
const path = require('path')
require('electron-reload')(__dirname, {
electron: path.join(__dirname, 'node_modules', '.bin', 'electron'),
hardResetMethod: 'exit'
});
electron_reload(paths, options)
paths
: a file, directory or glob pattern to watch
options
(optional) containing:
chokidar
optionselectron
property pointing to electron executables.electronArgv
string array with command line options passed to the Electron executable. Only used when hard resetting.appArgv
: string array with command line options passed to the Electron app. Only used when hard resetting.forceHardReset
: enables hard reset for every file change and not only the main fileoptions
will default to {ignored: /node_modules|[\/\\]\./, argv: []}
.
Simply put, I was tired and confused by all other available modules which are so complicated* for such an uncomplicated task!
* e.g. start a local HTTP server, publish change events through a WebSocket, etc.!
If you want to have least effort when developing electron packages, take a look at neutron!
chokidar
from v2 to v3 (lighter/faster installation)node run lint
) and fix CI linting issues (see #62)index.js
as fallback if main
is not defined in package.json
browserWindows[]
indexingapp.exit()
in addition to app.quit()
for hard resetsextend
with Object.assign
app
(e.g. require(electron).app
)browser-window-created
eventFAQs
Simplest way to reload an electron app on file changes!
The npm package electron-reload receives a total of 10,962 weekly downloads. As such, electron-reload popularity was classified as popular.
We found that electron-reload demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.