
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
electron-connect
Advanced tools
Utility tool to develop applications with Electron.
Using this in your Node.js scripts (e.g. gulpfile.js
), you can livereload your Electron app.
It provides the following features:
Use npm:
npm install electron
npm install electron-connect --save-dev
electron-connect
has server and client components. They communicate with each other using WebSocket.
The server component manages Electron process and broadcasts reload event to client, and client components reload renderer's resources.
Here is an example creating a server in gulpfile.
'use strict';
var gulp = require('gulp');
var electron = require('electron-connect').server.create();
gulp.task('serve', function () {
// Start browser process
electron.start();
// Restart browser process
gulp.watch('app.js', electron.restart);
// Reload renderer process
gulp.watch(['index.js', 'index.html'], electron.reload);
});
A client can be created in either browser process or renderer process.
Note:
Please make sure it is not done in both.
<html>
<body>
<!-- build:remove -->
<!-- Connect to server process -->
<script>require('electron-connect').client.create()</script>
<!-- end:build -->
</body>
</html>
Do you want to use this tool for only develop environment ?
You can remove the <script>
block in your gulpfile using gulp-useref.
'use strict';
var app = require('app');
var BrowserWindow = require('browser-window');
var client = require('electron-connect').client;
app.on('ready', function () {
var mainWindow = new BrowserWindow({
width: 400,
height: 300
});
mainWindow.loadUrl('file://' + __dirname + '/index.html');
// Connect to server process
client.create(mainWindow);
});
If you want details, see example/simple.
options
Objectelectron
Object. An electron
module. Set it If you want to use your forked Electron.useGlobalElectron
Boolean. If set, electron-connect uses electron
module installed globally (default: false
).path
String. A path to your package.json
file (default: process.cwd()
).port
Number. WebSocket server port (default: 30080
).spawnOpt
Object. Options for spawn.logLevel
Number. The granularity of the electron-connect logging in your prompt. 0
- warning only, 1
- warning and info only, 2
- all logs (default: 1
).stopOnClose
Boolean. If set, closing last remaining window stops the electron application.Returns a new ProcessManager
object.
If neither electron
nor useGlobalElectron
option is set, electron-connect searches for electron
module automatically.
electron
installed locally.electron
installed globally.New in version 0.5.x and onwards :
Now, ProcessManager's start()
, restart()
and stop()
methods invoke callback
with an argument that indicates the state
of the electron process, which could be one of the following string values -
started
restarting
restarted
stopped
See example/stop-on-close, where you can find sample code that uses stopOnClose
option and stopped
state to shutdown gulp process gracefully.
args
String or Array. Additional arguments used when create a process.callback
FunctionStarts a server and Electron application process.
args
String or Array. Additional arguments used when create a process.callback
FunctionKills Electron process if it exsists, and starts new one.
This method is useful for callback of your browserProcess sourcecodes' change event.
ids
String or Array. A list of id of target client.Emit reload event to target clients. Broadcasts reload event to all connected Client
object if ids
not set.
This method does not kill any Electron processes.
This method is useful for callback of your rendererProcess sourcecodes' change event.
callback
FunctionKills Electron process and stops server.
eventName
Stringcallback
FunctionRegisters an eventhandler that gets invoked when an event is emitted by Client.sendMessage
.
eventName
String. A message type.data
Object. A message data.Broadcasts an event to all clients.
browserWindow
Object. Optional, in rendererProcess only. Required, when client is created in browserProcess.options
Objectport
Number. WebSocket server port (default: 30080
) that client should connect to.sendBounds
BooleanlogLevel
Number. See server.create([options]).logLevel.callback
FunctionCreates a new Client
object associated with browserWindow
and connects to ProcessManager
.
The browserWindow
should be an Electron browser-window instance.
Once a client is created and connected to the server, client can receive events (e.g. reload).
If sendBounds
is set (default true
), client sends a bounds object when browserWindow
moves or resizes.
And when ProcessManager.restart()
is called, client recovers the bounds stored at server.
An identifier of this client. It is a same value browserWindow.id
.
eventName
Stringcallback
FunctionRegisters an eventhandler that gets invoked, when an event is emitted by ProcessManager.broadcast
.
eventName
String. A message type.data
Object. A message data.Emits an event to ProcessManager
.
MIT
FAQs
Livereload tools for Electron development
We found that electron-connect 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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.