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

Commit a37fe13

Browse files
committed
chore: fix electron example
running tests with electron will come soon closes #2011
1 parent f9bfa29 commit a37fe13

File tree

6 files changed

+22
-26
lines changed

6 files changed

+22
-26
lines changed

examples/run-in-electron/README.md

Lines changed: 1 addition & 5 deletions
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
```

examples/run-in-electron/main.js

Lines changed: 11 additions & 15 deletions
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.

examples/run-in-electron/package.json

Lines changed: 3 additions & 3 deletions
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
}

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

Lines changed: 2 additions & 2 deletions
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

examples/run-in-electron/renderer.js

Lines changed: 3 additions & 0 deletions
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.

test/core/pin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ describe('pin', function () {
189189
.catch(err => expect(err).to.match(/already pinned recursively/))
190190
})
191191

192-
it('can\'t pin item not in datastore', () => {
192+
it('can\'t pin item not in datastore', function () {
193+
this.timeout(5 * 1000)
193194
const falseHash = `${pins.root.slice(0, -2)}ss`
194195
return expectTimeout(pin.add(falseHash), 4000)
195196
})

0 commit comments

Comments
 (0)