Skip to content

Instantly share code, notes, and snippets.

@ssreekanth
Last active May 27, 2016 00:03
Show Gist options
  • Save ssreekanth/78d589034a88447c0f1e5efff57a88db to your computer and use it in GitHub Desktop.
Save ssreekanth/78d589034a88447c0f1e5efff57a88db to your computer and use it in GitHub Desktop.
electron-connect working example - with '--enable-logging' args passed to electron-connect's start() and restart() calls in gulpfile.js. Refer Quramy/electron-connect#42
'use strict';
const electron = require('electron');
const {app} = electron;
const {BrowserWindow} = electron;
const {client} = require('electron-connect');
let mainWindow;
app.on('window-all-closed', function () {
app.quit();
});
app.on('ready', function () {
console.log(process.argv.join(', '));
console.log('Hello, browser process');
mainWindow = new BrowserWindow({
width: 400,
height: 300
});
mainWindow.loadURL('file://' + __dirname + '/index.html');
mainWindow.on('closed', function() {
mainWindow = null;
});
client.create(mainWindow);
});
'use strict';
var gulp = require('gulp');
var electron = require('electron-connect').server.create();
gulp.task('serve', function () {
// Start browser process
electron.start("--enable-logging");
// Restart browser process
gulp.watch('app.js', function() {
electron.restart("--enable-logging");
});
// Reload renderer process
gulp.watch(['index.js', 'index.html'], electron.reload);
});
gulp.task('default', ['serve']);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple example app</title>
</head>
<body>
<h1>Hello, Electron</h1>
<script>
console.log('Hello, renderer window!');
console.log('electron version: ' + process.versions.electron);
</script>
</body>
</html>
{
"name": "electron-connect-simple-example",
"version": "0.0.1",
"main": "./app.js",
"scripts": {
"start": "gulp serve"
},
"devDependencies": {
"electron-connect": "^0.4.2",
"electron-prebuilt": "^1.2.0",
"gulp": "^3.9.1"
}
}
@ssreekanth
Copy link
Author

ssreekanth commented May 26, 2016

Run

$ npm install
$ npm start

You could see all the console.log messages from both renderer and browser processes appearing on the console. You could also try opening/saving app.js to see electron app restart working just fine with all the logs appearing on the console.

Output shown below -

> electron-connect-simple-example@0.0.1 start /Users/sampleuser/simple-example
> gulp serve

(node:90461) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
[16:39:13] Using gulpfile ~//simple-example/gulpfile.js
[16:39:14] Starting 'serve'...
[16:39:14] Finished 'serve' after 13 ms
[2016-05-26T23:39:14.019Z] [electron-connect] [server] started electron process: 90462
[2016-05-26T23:39:14.020Z] [electron-connect] [server] created and listening on 30080
/Users/sampleuser/simple-example/node_modules/electron-prebuilt/dist/Electron.app/Contents/MacOS/Electron, /Users/sampleuser/simple-example, --enable-logging
Hello, browser process
[2016-05-26T23:39:14.431Z] [electron-connect] [server] client (window_id: 1) started.
[2016-05-26T23:39:14.433Z] [electron-connect] [client: 1] connected server
[90462:0526/163914:INFO:CONSOLE(10)] "Hello, renderer window!", source: file:///Users/sampleuser/simple-example/index.html (10)
[90462:0526/163914:INFO:CONSOLE(11)] "electron version: 1.2.0", source: file:///Users/sampleuser/simple-example/index.html (11)
[2016-05-26T23:40:02.760Z] [electron-connect] [server] restarting electron process
[2016-05-26T23:40:02.760Z] [electron-connect] [server] killing electron process tree: 90462
[2016-05-26T23:40:02.801Z] [electron-connect] [server] started electron process: 90485
[2016-05-26T23:40:02.818Z] [electron-connect] [server] client (window_id: 1) closed.
/Users/sampleuser/simple-example/node_modules/electron-prebuilt/dist/Electron.app/Contents/MacOS/Electron, /Users/sampleuser/simple-example, --enable-logging
Hello, browser process
[2016-05-26T23:40:03.201Z] [electron-connect] [server] client (window_id: 1) started.
[2016-05-26T23:40:03.204Z] [electron-connect] [client: 1] connected server
[90485:0526/164003:INFO:CONSOLE(10)] "Hello, renderer window!", source: file:///Users/sampleuser/simple-example/index.html (10)
[90485:0526/164003:INFO:CONSOLE(11)] "electron version: 1.2.0", source: file:///Users/sampleuser/simple-example/index.html (11)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment