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

Commit

Permalink
chore: fix electron example
Browse files Browse the repository at this point in the history
running tests with electron will come soon

closes #2011
  • Loading branch information
hugomrdias committed May 3, 2019
1 parent f9bfa29 commit a37fe13
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 26 deletions.
6 changes: 1 addition & 5 deletions examples/run-in-electron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@ To try it by yourself, do:

```
> npm install
> ./node_modules/.bin/electron-rebuild
# or
> ./build.sh
#
# You can also try to use `npm start` to see where electron errors
> npm start
```
26 changes: 11 additions & 15 deletions examples/run-in-electron/main.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
'use strict'

const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow

const IPFS = require('ipfs')
const path = require('path')
const url = require('url')
const { app, BrowserWindow } = require('electron')

let mainWindow

function createWindow () {
mainWindow = new BrowserWindow({ width: 800, height: 600 })
mainWindow = new BrowserWindow({ width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
} })

// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
mainWindow.loadFile('index.html')

// Open the DevTools.
mainWindow.webContents.openDevTools()
Expand All @@ -32,9 +26,8 @@ function createWindow () {
app.on('ready', () => {
createWindow()

// Spawn your IPFS node \o/
const IPFS = require('ipfs')
const node = new IPFS()

node.on('ready', () => {
node.id((err, id) => {
if (err) {
Expand All @@ -43,6 +36,9 @@ app.on('ready', () => {
console.log(id)
})
})
node.on('error', (err) => {
return console.log(err)
})
})

// Quit when all windows are closed.
Expand Down
6 changes: 3 additions & 3 deletions examples/run-in-electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "main.js",
"scripts": {
"start": "electron .",
"postinstall": "electron-rebuild"
"postinstall": "./rebuild.sh"
},
"keywords": [
"Electron",
Expand All @@ -15,8 +15,8 @@
"author": "David Dias <[email protected]>",
"license": "MIT",
"devDependencies": {
"electron": "^2.0.0",
"electron-rebuild": "^1.7.2",
"electron": "^4.2.0",
"electron-rebuild": "^1.8.4",
"ipfs": "ipfs/js-ipfs"
}
}
4 changes: 2 additions & 2 deletions examples/run-in-electron/build.sh → examples/run-in-electron/rebuild.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Electron's version.
export npm_config_target=2.0.0
export npm_config_target=4.2.0
# The architecture of Electron, can be ia32 or x64.
export npm_config_arch=x64
export npm_config_target_arch=x64
Expand All @@ -10,4 +10,4 @@ export npm_config_runtime=electron
# Tell node-pre-gyp to build module from source code.
export npm_config_build_from_source=true
# Install all dependencies, and store cache to ~/.electron-gyp.
HOME=~/.electron-gyp npm install
HOME=~/.electron-gyp npm rebuild
3 changes: 3 additions & 0 deletions examples/run-in-electron/renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
3 changes: 2 additions & 1 deletion test/core/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ describe('pin', function () {
.catch(err => expect(err).to.match(/already pinned recursively/))
})

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

0 comments on commit a37fe13

Please sign in to comment.