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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #292 Electron v15 upgrade #293

Merged
merged 1 commit into from Oct 6, 2021
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
7 changes: 5 additions & 2 deletions lib/exportJob.js
Expand Up @@ -329,6 +329,7 @@ class ExportJob extends EventEmitter {
_launchBrowserWindow () {
const browserConfig = this._getBrowserConfiguration(this.args)
this.emit('window.open.start', {})
this.debug('Electron browserConfig:', JSON.stringify(browserConfig))
let win = new electron.BrowserWindow(browserConfig)
this.window = win
this.emit('window.open.end', {
Expand Down Expand Up @@ -555,6 +556,7 @@ class ExportJob extends EventEmitter {
// event.detail will only exist if a CustomEvent was emitted
const cmd = `document.body.addEventListener('${eventName}',
function(event) {
console.log('sending message over channel: ${IPC_MAIN_CHANNEL_RENDER}', '${this.jobId}', event.detail)
ipcApi.send('${IPC_MAIN_CHANNEL_RENDER}', '${this.jobId}', event.detail)
// #169 - allows clients to send event until we acknowledge receipt
document.body.dispatchEvent(new Event('${eventName}-acknowledged'))
Expand All @@ -571,8 +573,9 @@ class ExportJob extends EventEmitter {
// Or if the window was closed because it was hung for too long
this.once('window.termination', () => clearTimeout(timeout))

window.webContents.executeJavaScript(`ipcApi.initialize()`)
window.webContents.executeJavaScript(cmd)
window.webContents.executeJavaScript(`window.ipcApi.initialize()`).then(() => {
return window.webContents.executeJavaScript(cmd).catch(err => this.error(err))
}).catch(err => this.error(err))
}

/**
Expand Down
7 changes: 3 additions & 4 deletions lib/preload.js
@@ -1,7 +1,7 @@
// Get some logs when things go horribly wrong
require('./sentry')
const _ = require('lodash')
const { ipcRenderer } = require('electron')
const { ipcRenderer, contextBridge } = require('electron')

const privateApi = {
// Have to assign ipcRenderer here or it will not be available
Expand Down Expand Up @@ -37,8 +37,7 @@ function sendStats (options = {}) {
})
}

// eslint-disable-next-line no-undef
ipcApi = {
contextBridge.exposeInMainWorld('ipcApi', {

/**
* Initializes the renderer process so this API can be used.
Expand Down Expand Up @@ -66,4 +65,4 @@ ipcApi = {
eventStats (messageId, windowId, event) {
sendStats({ messageId, windowId, event })
}
}
})