Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 3a218e4

Browse files
committed
chore: fix electron example
running tests with electron will come soon closes #2011
1 parent 9b19afd commit 3a218e4

File tree

5 files changed

+20
-25
lines changed

5 files changed

+20
-25
lines changed

run-in-electron/README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,5 @@ To try it by yourself, do:
66

77
```
88
> npm install
9-
> ./node_modules/.bin/electron-rebuild
10-
# or
11-
> ./build.sh
12-
#
13-
# You can also try to use `npm start` to see where electron errors
9+
> npm start
1410
```

run-in-electron/main.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
'use strict'
22

3-
const electron = require('electron')
4-
const app = electron.app
5-
const BrowserWindow = electron.BrowserWindow
6-
7-
const IPFS = require('ipfs')
8-
const path = require('path')
9-
const url = require('url')
3+
const { app, BrowserWindow } = require('electron')
104

115
let mainWindow
126

137
function createWindow () {
14-
mainWindow = new BrowserWindow({ width: 800, height: 600 })
8+
mainWindow = new BrowserWindow({ width: 800,
9+
height: 600,
10+
webPreferences: {
11+
nodeIntegration: true
12+
} })
1513

1614
// and load the index.html of the app.
17-
mainWindow.loadURL(url.format({
18-
pathname: path.join(__dirname, 'index.html'),
19-
protocol: 'file:',
20-
slashes: true
21-
}))
15+
mainWindow.loadFile('index.html')
2216

2317
// Open the DevTools.
2418
mainWindow.webContents.openDevTools()
@@ -32,9 +26,8 @@ function createWindow () {
3226
app.on('ready', () => {
3327
createWindow()
3428

35-
// Spawn your IPFS node \o/
29+
const IPFS = require('ipfs')
3630
const node = new IPFS()
37-
3831
node.on('ready', () => {
3932
node.id((err, id) => {
4033
if (err) {
@@ -43,6 +36,9 @@ app.on('ready', () => {
4336
console.log(id)
4437
})
4538
})
39+
node.on('error', (err) => {
40+
return console.log(err)
41+
})
4642
})
4743

4844
// Quit when all windows are closed.

run-in-electron/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "main.js",
66
"scripts": {
77
"start": "electron .",
8-
"postinstall": "electron-rebuild"
8+
"postinstall": "./rebuild.sh"
99
},
1010
"keywords": [
1111
"Electron",
@@ -15,8 +15,8 @@
1515
"author": "David Dias <[email protected]>",
1616
"license": "MIT",
1717
"devDependencies": {
18-
"electron": "^2.0.0",
19-
"electron-rebuild": "^1.7.2",
18+
"electron": "^4.2.0",
19+
"electron-rebuild": "^1.8.4",
2020
"ipfs": "ipfs/js-ipfs"
2121
}
2222
}

run-in-electron/build.sh renamed to run-in-electron/rebuild.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Electron's version.
2-
export npm_config_target=2.0.0
2+
export npm_config_target=4.2.0
33
# The architecture of Electron, can be ia32 or x64.
44
export npm_config_arch=x64
55
export npm_config_target_arch=x64
@@ -10,4 +10,4 @@ export npm_config_runtime=electron
1010
# Tell node-pre-gyp to build module from source code.
1111
export npm_config_build_from_source=true
1212
# Install all dependencies, and store cache to ~/.electron-gyp.
13-
HOME=~/.electron-gyp npm install
13+
HOME=~/.electron-gyp npm rebuild

run-in-electron/renderer.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file is required by the index.html file and will
2+
// be executed in the renderer process for that window.
3+
// All of the Node.js APIs are available in this process.

0 commit comments

Comments
 (0)