Refactor electron exports to keep module list in separate files
This commit is contained in:
parent
14b548f27a
commit
44bd93589a
8 changed files with 79 additions and 236 deletions
|
@ -22,6 +22,7 @@
|
|||
'lib/browser/api/menu.js',
|
||||
'lib/browser/api/menu-item.js',
|
||||
'lib/browser/api/menu-item-roles.js',
|
||||
'lib/browser/api/module-list.js',
|
||||
'lib/browser/api/navigation-controller.js',
|
||||
'lib/browser/api/net.js',
|
||||
'lib/browser/api/power-monitor.js',
|
||||
|
@ -47,6 +48,7 @@
|
|||
'lib/common/api/deprecations.js',
|
||||
'lib/common/api/is-promise.js',
|
||||
'lib/common/api/exports/electron.js',
|
||||
'lib/common/api/module-list.js',
|
||||
'lib/common/api/native-image.js',
|
||||
'lib/common/api/shell.js',
|
||||
'lib/common/init.js',
|
||||
|
@ -66,6 +68,7 @@
|
|||
'lib/renderer/api/exports/electron.js',
|
||||
'lib/renderer/api/ipc-renderer.js',
|
||||
'lib/renderer/api/ipc-renderer-setup.js',
|
||||
'lib/renderer/api/module-list.js',
|
||||
'lib/renderer/api/remote.js',
|
||||
'lib/renderer/api/screen.js',
|
||||
'lib/renderer/api/web-frame.js',
|
||||
|
|
|
@ -1,131 +1,13 @@
|
|||
const common = require('../../../common/api/exports/electron')
|
||||
// since browser module list is also used in renderer, keep it separate.
|
||||
const moduleList = require('../module-list')
|
||||
|
||||
// Import common modules.
|
||||
common.defineProperties(exports)
|
||||
|
||||
Object.defineProperties(exports, {
|
||||
// Browser side modules, please sort alphabetically.
|
||||
// Any modules added here must also be added to the browserModules array
|
||||
// in remote.js
|
||||
app: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../app')
|
||||
}
|
||||
},
|
||||
autoUpdater: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../auto-updater')
|
||||
}
|
||||
},
|
||||
BrowserWindow: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../browser-window')
|
||||
}
|
||||
},
|
||||
contentTracing: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../content-tracing')
|
||||
}
|
||||
},
|
||||
dialog: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../dialog')
|
||||
}
|
||||
},
|
||||
globalShortcut: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../global-shortcut')
|
||||
}
|
||||
},
|
||||
ipcMain: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../ipc-main')
|
||||
}
|
||||
},
|
||||
Menu: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../menu')
|
||||
}
|
||||
},
|
||||
MenuItem: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../menu-item')
|
||||
}
|
||||
},
|
||||
net: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../net')
|
||||
}
|
||||
},
|
||||
powerMonitor: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../power-monitor')
|
||||
}
|
||||
},
|
||||
powerSaveBlocker: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../power-save-blocker')
|
||||
}
|
||||
},
|
||||
protocol: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../protocol')
|
||||
}
|
||||
},
|
||||
screen: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../screen')
|
||||
}
|
||||
},
|
||||
session: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../session')
|
||||
}
|
||||
},
|
||||
systemPreferences: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../system-preferences')
|
||||
}
|
||||
},
|
||||
TouchBar: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../touch-bar')
|
||||
}
|
||||
},
|
||||
Tray: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../tray')
|
||||
}
|
||||
},
|
||||
webContents: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../web-contents')
|
||||
}
|
||||
},
|
||||
|
||||
// The internal modules, invisible unless you know their names.
|
||||
NavigationController: {
|
||||
get: function () {
|
||||
return require('../navigation-controller')
|
||||
}
|
||||
}
|
||||
})
|
||||
for (const module of moduleList) {
|
||||
Object.defineProperty(exports, module.name, {
|
||||
enumerable: !module.private,
|
||||
get: () => require(`../${module.file}`)
|
||||
})
|
||||
}
|
||||
|
|
24
lib/browser/api/module-list.js
Normal file
24
lib/browser/api/module-list.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Browser side modules, please sort alphabetically.
|
||||
module.exports = [
|
||||
{name: 'app', file: 'app'},
|
||||
{name: 'autoUpdater', file: 'auto-updater'},
|
||||
{name: 'BrowserWindow', file: 'browser-window'},
|
||||
{name: 'contentTracing', file: 'content-tracing'},
|
||||
{name: 'dialog', file: 'dialog'},
|
||||
{name: 'globalShortcut', file: 'global-shortcut'},
|
||||
{name: 'ipcMain', file: 'ipc-main'},
|
||||
{name: 'Menu', file: 'menu'},
|
||||
{name: 'MenuItem', file: 'menu-item'},
|
||||
{name: 'net', file: 'net'},
|
||||
{name: 'powerMonitor', file: 'power-monitor'},
|
||||
{name: 'powerSaveBlocker', file: 'power-save-blocker'},
|
||||
{name: 'protocol', file: 'protocol'},
|
||||
{name: 'screen', file: 'screen'},
|
||||
{name: 'session', file: 'session'},
|
||||
{name: 'systemPreferences', file: 'system-preferences'},
|
||||
{name: 'TouchBar', file: 'touch-bar'},
|
||||
{name: 'Tray', file: 'tray'},
|
||||
{name: 'webContents', file: 'web-contents'},
|
||||
// The internal modules, invisible unless you know their names.
|
||||
{name: 'NavigationController', file: 'navigation-controller', private: true}
|
||||
]
|
|
@ -1,53 +1,13 @@
|
|||
const moduleList = require('../module-list')
|
||||
|
||||
// Attaches properties to |exports|.
|
||||
exports.defineProperties = function (exports) {
|
||||
return Object.defineProperties(exports, {
|
||||
// Common modules, please sort with alphabet order.
|
||||
clipboard: {
|
||||
// Must be enumerable, otherwise it woulde be invisible to remote module.
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../clipboard')
|
||||
}
|
||||
},
|
||||
crashReporter: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../crash-reporter')
|
||||
}
|
||||
},
|
||||
nativeImage: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../native-image')
|
||||
}
|
||||
},
|
||||
shell: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../shell')
|
||||
}
|
||||
},
|
||||
|
||||
// The internal modules, invisible unless you know their names.
|
||||
CallbacksRegistry: {
|
||||
get: function () {
|
||||
return require('../callbacks-registry')
|
||||
}
|
||||
},
|
||||
deprecate: {
|
||||
get: function () {
|
||||
return require('../deprecate')
|
||||
}
|
||||
},
|
||||
deprecations: {
|
||||
get: function () {
|
||||
return require('../deprecations')
|
||||
}
|
||||
},
|
||||
isPromise: {
|
||||
get: function () {
|
||||
return require('../is-promise')
|
||||
}
|
||||
const descriptors = {}
|
||||
for (const module of moduleList) {
|
||||
descriptors[module.name] = {
|
||||
enumerable: !module.private,
|
||||
get: () => require(`../${module.file}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
return Object.defineProperties(exports, descriptors)
|
||||
}
|
||||
|
|
12
lib/common/api/module-list.js
Normal file
12
lib/common/api/module-list.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
// 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.
|
||||
{name: 'CallbacksRegistry', file: 'callbacks-registry', private: true},
|
||||
{name: 'deprecate', file: 'deprecate', private: true},
|
||||
{name: 'deprecations', file: 'deprecations', private: true},
|
||||
{name: 'isPromise', file: 'is-promise', private: true}
|
||||
]
|
|
@ -1,38 +1,12 @@
|
|||
const common = require('../../../common/api/exports/electron')
|
||||
const moduleList = require('../module-list')
|
||||
|
||||
// Import common modules.
|
||||
common.defineProperties(exports)
|
||||
|
||||
Object.defineProperties(exports, {
|
||||
// Renderer side modules, please sort with alphabet order.
|
||||
desktopCapturer: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../desktop-capturer')
|
||||
}
|
||||
},
|
||||
ipcRenderer: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../ipc-renderer')
|
||||
}
|
||||
},
|
||||
remote: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../remote')
|
||||
}
|
||||
},
|
||||
screen: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../screen')
|
||||
}
|
||||
},
|
||||
webFrame: {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return require('../web-frame')
|
||||
}
|
||||
}
|
||||
})
|
||||
for (const module of moduleList) {
|
||||
Object.defineProperty(exports, module.name, {
|
||||
enumerable: !module.private,
|
||||
get: () => require(`../${module.file}`)
|
||||
})
|
||||
}
|
||||
|
|
8
lib/renderer/api/module-list.js
Normal file
8
lib/renderer/api/module-list.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Renderer side modules, please sort alphabetically.
|
||||
module.exports = [
|
||||
{name: 'desktopCapturer', file: 'desktop-capturer'},
|
||||
{name: 'ipcRenderer', file: 'ipc-renderer'},
|
||||
{name: 'remote', file: 'remote'},
|
||||
{name: 'screen', file: 'screen'},
|
||||
{name: 'webFrame', file: 'web-frame'}
|
||||
]
|
|
@ -340,32 +340,12 @@ const addBuiltinProperty = (name) => {
|
|||
})
|
||||
}
|
||||
|
||||
// Add each browser module name as a property
|
||||
// This list should match the exports in browser/api/exports/electron.js
|
||||
const browserModules = [
|
||||
'app',
|
||||
'autoUpdater',
|
||||
'BrowserWindow',
|
||||
'contentTracing',
|
||||
'dialog',
|
||||
'globalShortcut',
|
||||
'ipcMain',
|
||||
'Menu',
|
||||
'MenuItem',
|
||||
'net',
|
||||
'powerMonitor',
|
||||
'powerSaveBlocker',
|
||||
'protocol',
|
||||
'screen',
|
||||
'session',
|
||||
'systemPreferences',
|
||||
'TouchBar',
|
||||
'Tray',
|
||||
'webContents'
|
||||
]
|
||||
browserModules.forEach(addBuiltinProperty)
|
||||
const browserModules =
|
||||
require('../../common/api/module-list').concat(
|
||||
require('../../browser/api/module-list'))
|
||||
|
||||
// Add each common module name as a property
|
||||
const commonModules = {}
|
||||
require('../../common/api/exports/electron').defineProperties(commonModules)
|
||||
Object.getOwnPropertyNames(commonModules).forEach(addBuiltinProperty)
|
||||
// And add a helper receiver for each one.
|
||||
browserModules
|
||||
.filter((m) => !m.private)
|
||||
.map((m) => m.name)
|
||||
.forEach(addBuiltinProperty)
|
||||
|
|
Loading…
Reference in a new issue