
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
electron-util
Advanced tools
Useful utilities for developing Electron apps and modules
You can use this module directly in both the main and renderer process.
$ npm install electron-util
const {appReady, is} = require('electron-util');
(async () => {
await appReady;
console.log(is.macos && is.main);
//=> true
})();
Type: Object
Access some Electron APIs in both main and renderer process without having to care about which one you're in:
Type: Object
Check for various things:
macos
- Running on macOSlinux
- Running on Linuxwindows
- Running on Windowsmain
- Running on the main processrenderer
- Running on the renderer processdevelopment
- Running in development, not in productionusingAsar
- The app is using ASARmacAppStore
- The app is an Mac App Store buildwindowsStore
- The app is a Windows Store AppX buildType: Promise
Resolves when the app is ready.
Type: string
Path to the root of the app.
Type: string
Example: 1.7.9
Electron version.
Type: string
Example: 62.0.3202
Chrome version in Electron.
Type: Function
Accepts an object with the keys as either macos
, windows
, linux
, or default
, and picks the appropriate key depending on the current platform. If no platform key is matched, the default
key is used if it exists. If the value is a function, it will be executed, and the returned value will be used.
init({
enableUnicorn: util.platform({
macos: true,
windows: false,
linux: () => false
})
});
Type: Function
Returns the active window.
Load a file into the given window using a file path relative to the root of the app.
loadFile(win, 'index.html');
You use this instead of the verbose win.loadURL(`file://…`);
Type: Function
Run some JavaScript in the active or given window.
Returns a promise for the result of the executed code or a rejected promise if the result is a rejected promise.
Type: Function
ASAR is great, but it has limitations when it comes to executing binaries. For example, child_process.spawn()
is not automatically handled. So you would have to unpack the binary, for example, with the asarUnpack
option in electron-builder
. This creates a problem as the path to the binary changes, but your path.join(__dirname, 'binary')
is not changed. To make it work you need to fix the path. That's the purpose of this method.
Before:
/Users/sindresorhus/Kap.app/Contents/Resources/app.asar/node_modules/foo/binary
After:
/Users/sindresorhus/Kap.app/Contents/Resources/app.asar.unpack/node_modules/foo/binary
This is for non-Electron code that might be included in an Electron app. For example, if you want to add special support for Electron in a vanilla Node.js module.
const electronUtil = require('electron-util/node');
if (electronUtil.isElectron) {
// Electron workaround
} else {
// Normal code
}
Type: boolean
Check if you're running in an Electron app.
Type: string
Example: 1.7.9
Electron version. Returns 0.0.0
when not in an Electron app.
Type: boolean
Check if the Electron app you're running in is using ASAR.
Same as the above Electron version.
MIT © Sindre Sorhus
FAQs
Useful utilities for Electron apps and modules
The npm package electron-util receives a total of 7,286 weekly downloads. As such, electron-util popularity was classified as popular.
We found that electron-util 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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.