refactor: use separate ipc-renderer-internal / ipc-main-internal APIs for Electron internals (#13940)
This commit is contained in:
parent
f7122610cc
commit
b50f86ef43
49 changed files with 322 additions and 133 deletions
|
@ -3,7 +3,6 @@
|
|||
// Common modules, please sort alphabetically
|
||||
module.exports = [
|
||||
{ name: 'clipboard', file: 'clipboard' },
|
||||
{ name: 'crashReporter', file: 'crash-reporter' },
|
||||
{ name: 'nativeImage', file: 'native-image' },
|
||||
{ name: 'shell', file: 'shell' },
|
||||
// The internal modules, invisible unless you know their names.
|
||||
|
|
|
@ -1,17 +1,8 @@
|
|||
'use strict'
|
||||
|
||||
const electron = require('electron')
|
||||
const binding = process.atomBinding('crash_reporter')
|
||||
|
||||
const sendSync = function (channel, ...args) {
|
||||
if (process.type === 'browser') {
|
||||
const event = {}
|
||||
electron.ipcMain.emit(channel, event, ...args)
|
||||
return event.returnValue
|
||||
} else {
|
||||
return electron.ipcRenderer.sendSync(channel, ...args)
|
||||
}
|
||||
}
|
||||
const errorUtils = require('@electron/internal/common/error-utils')
|
||||
|
||||
class CrashReporter {
|
||||
contructor () {
|
||||
|
@ -19,6 +10,20 @@ class CrashReporter {
|
|||
this.crashesDirectory = null
|
||||
}
|
||||
|
||||
sendSync (channel, ...args) {
|
||||
throw new Error('Not implemented')
|
||||
}
|
||||
|
||||
invoke (command, ...args) {
|
||||
const [ error, result ] = this.sendSync(command, ...args)
|
||||
|
||||
if (error) {
|
||||
throw errorUtils.deserialize(error)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
start (options) {
|
||||
if (options == null) options = {}
|
||||
|
||||
|
@ -46,7 +51,7 @@ class CrashReporter {
|
|||
throw new Error('submitURL is a required option to crashReporter.start')
|
||||
}
|
||||
|
||||
const ret = sendSync('ELECTRON_CRASH_REPORTER_INIT', {
|
||||
const ret = this.invoke('ELECTRON_CRASH_REPORTER_INIT', {
|
||||
submitURL,
|
||||
productName
|
||||
})
|
||||
|
@ -114,4 +119,4 @@ class CrashReporter {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = new CrashReporter()
|
||||
module.exports = CrashReporter
|
Loading…
Add table
Add a link
Reference in a new issue