Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update with-electron example #4386

Merged
merged 1 commit into from May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/with-electron/main/index.js
Expand Up @@ -13,7 +13,11 @@ app.on('ready', async () => {

const mainWindow = new BrowserWindow({
width: 800,
height: 600
height: 600,
webPreferences: {
nodeIntegration: false,
preload: join(__dirname, 'preload.js')
}
})

const url = isDev
Expand Down
7 changes: 7 additions & 0 deletions examples/with-electron/main/preload.js
@@ -0,0 +1,7 @@
const { ipcRenderer } = require('electron')

// Since we disabled nodeIntegration we can reintroduce
// needed node functionality here
process.once('loaded', () => {
global.ipcRenderer = ipcRenderer
})
6 changes: 3 additions & 3 deletions examples/with-electron/package.json
Expand Up @@ -18,14 +18,14 @@
]
},
"devDependencies": {
"electron": "^1.6.11",
"electron-builder": "^19.19.1",
"electron": "^2.0.0",
"electron-builder": "^20.13.4",
"next": "latest",
"react": "^16.1.1",
"react-dom": "^16.1.1"
},
"dependencies": {
"electron-is-dev": "0.3.0",
"electron-next": "3.0.8"
"electron-next": "3.1.4"
}
}
4 changes: 0 additions & 4 deletions examples/with-electron/renderer/next.config.js
@@ -1,8 +1,4 @@
module.exports = {
webpack (config, { dev }) {
config.target = 'electron-renderer'
return config
},
exportPathMap () {
// Let Next.js know where to find the entry page
// when it's exporting the static bundle for the use
Expand Down
7 changes: 3 additions & 4 deletions examples/with-electron/renderer/pages/start.js
@@ -1,5 +1,4 @@
import { Component } from 'react'
import { ipcRenderer } from 'electron'

export default class extends Component {
state = {
Expand All @@ -9,12 +8,12 @@ export default class extends Component {

componentDidMount () {
// start listening the channel message
ipcRenderer.on('message', this.handleMessage)
global.ipcRenderer.on('message', this.handleMessage)
}

componentWillUnmount () {
// stop listening the channel message
ipcRenderer.removeListener('message', this.handleMessage)
global.ipcRenderer.removeListener('message', this.handleMessage)
}

handleMessage = (event, message) => {
Expand All @@ -28,7 +27,7 @@ export default class extends Component {

handleSubmit = event => {
event.preventDefault()
ipcRenderer.send('message', this.state.input)
global.ipcRenderer.send('message', this.state.input)
this.setState({ message: null })
}

Expand Down