diff --git a/build/webpack/webpack.config.base.js b/build/webpack/webpack.config.base.js index c257c3d913f4..c8364b1f8cdb 100644 --- a/build/webpack/webpack.config.base.js +++ b/build/webpack/webpack.config.base.js @@ -66,7 +66,7 @@ if (defines['ENABLE_VIEWS_API'] === 'false') { const alias = {} for (const ignoredModule of ignoredModules) { - alias[ignoredModule] = path.resolve(electronRoot, 'lib/common/dummy.js') + alias[ignoredModule] = path.resolve(electronRoot, 'lib/common/dummy.ts') } module.exports = ({ diff --git a/filenames.auto.gni b/filenames.auto.gni index bae1d68171af..afcacee9f261 100644 --- a/filenames.auto.gni +++ b/filenames.auto.gni @@ -136,11 +136,11 @@ auto_filenames = { sandbox_bundle_deps = [ "lib/browser/api/module-names.ts", - "lib/common/api/clipboard.js", + "lib/common/api/clipboard.ts", "lib/common/api/deprecate.ts", "lib/common/api/module-list.ts", - "lib/common/api/native-image.js", - "lib/common/api/shell.js", + "lib/common/api/native-image.ts", + "lib/common/api/shell.ts", "lib/common/define-properties.ts", "lib/common/electron-binding-setup.ts", "lib/common/type-utils.ts", @@ -189,15 +189,15 @@ auto_filenames = { "lib/browser/api/auto-updater/auto-updater-native.js", "lib/browser/api/auto-updater/auto-updater-win.js", "lib/browser/api/auto-updater/squirrel-update-win.js", - "lib/browser/api/browser-view.js", + "lib/browser/api/browser-view.ts", "lib/browser/api/browser-window.js", - "lib/browser/api/content-tracing.js", + "lib/browser/api/content-tracing.ts", "lib/browser/api/crash-reporter.ts", "lib/browser/api/desktop-capturer.ts", "lib/browser/api/dialog.js", "lib/browser/api/exports/electron.ts", - "lib/browser/api/global-shortcut.js", - "lib/browser/api/in-app-purchase.js", + "lib/browser/api/global-shortcut.ts", + "lib/browser/api/in-app-purchase.ts", "lib/browser/api/ipc-main.ts", "lib/browser/api/menu-item-roles.js", "lib/browser/api/menu-item.js", @@ -208,19 +208,19 @@ auto_filenames = { "lib/browser/api/native-theme.ts", "lib/browser/api/net-log.js", "lib/browser/api/net.ts", - "lib/browser/api/notification.js", + "lib/browser/api/notification.ts", "lib/browser/api/power-monitor.ts", - "lib/browser/api/power-save-blocker.js", + "lib/browser/api/power-save-blocker.ts", "lib/browser/api/protocol.ts", "lib/browser/api/screen.ts", - "lib/browser/api/session.js", + "lib/browser/api/session.ts", "lib/browser/api/system-preferences.ts", "lib/browser/api/top-level-window.js", "lib/browser/api/touch-bar.js", - "lib/browser/api/tray.js", - "lib/browser/api/view.js", - "lib/browser/api/views/image-view.js", - "lib/browser/api/web-contents-view.js", + "lib/browser/api/tray.ts", + "lib/browser/api/view.ts", + "lib/browser/api/views/image-view.ts", + "lib/browser/api/web-contents-view.ts", "lib/browser/api/web-contents.js", "lib/browser/chrome-extension-shim.js", "lib/browser/default-menu.ts", @@ -238,11 +238,11 @@ auto_filenames = { "lib/browser/remote/server.ts", "lib/browser/rpc-server.js", "lib/browser/utils.ts", - "lib/common/api/clipboard.js", + "lib/common/api/clipboard.ts", "lib/common/api/deprecate.ts", "lib/common/api/module-list.ts", - "lib/common/api/native-image.js", - "lib/common/api/shell.js", + "lib/common/api/native-image.ts", + "lib/common/api/shell.ts", "lib/common/define-properties.ts", "lib/common/electron-binding-setup.ts", "lib/common/init.ts", @@ -260,11 +260,11 @@ auto_filenames = { renderer_bundle_deps = [ "lib/browser/api/module-names.ts", - "lib/common/api/clipboard.js", + "lib/common/api/clipboard.ts", "lib/common/api/deprecate.ts", "lib/common/api/module-list.ts", - "lib/common/api/native-image.js", - "lib/common/api/shell.js", + "lib/common/api/native-image.ts", + "lib/common/api/shell.ts", "lib/common/define-properties.ts", "lib/common/electron-binding-setup.ts", "lib/common/init.ts", @@ -302,11 +302,11 @@ auto_filenames = { worker_bundle_deps = [ "lib/browser/api/module-names.ts", - "lib/common/api/clipboard.js", + "lib/common/api/clipboard.ts", "lib/common/api/deprecate.ts", "lib/common/api/module-list.ts", - "lib/common/api/native-image.js", - "lib/common/api/shell.js", + "lib/common/api/native-image.ts", + "lib/common/api/shell.ts", "lib/common/define-properties.ts", "lib/common/electron-binding-setup.ts", "lib/common/init.ts", diff --git a/lib/browser/api/browser-view.js b/lib/browser/api/browser-view.ts similarity index 66% rename from lib/browser/api/browser-view.js rename to lib/browser/api/browser-view.ts index 2a57f5709d90..0f661d28f599 100644 --- a/lib/browser/api/browser-view.js +++ b/lib/browser/api/browser-view.ts @@ -1,11 +1,10 @@ -'use strict'; +import { EventEmitter } from 'events'; -const { EventEmitter } = require('events'); const { BrowserView } = process.electronBinding('browser_view'); Object.setPrototypeOf(BrowserView.prototype, EventEmitter.prototype); -BrowserView.fromWebContents = (webContents) => { +BrowserView.fromWebContents = (webContents: Electron.WebContents) => { for (const view of BrowserView.getAllViews()) { if (view.webContents.equal(webContents)) return view; } @@ -13,4 +12,4 @@ BrowserView.fromWebContents = (webContents) => { return null; }; -module.exports = BrowserView; +export default BrowserView; diff --git a/lib/browser/api/content-tracing.js b/lib/browser/api/content-tracing.js deleted file mode 100644 index 9aa9792954ba..000000000000 --- a/lib/browser/api/content-tracing.js +++ /dev/null @@ -1,2 +0,0 @@ -'use strict'; -module.exports = process.electronBinding('content_tracing'); diff --git a/lib/browser/api/content-tracing.ts b/lib/browser/api/content-tracing.ts new file mode 100644 index 000000000000..ce6ae5f42251 --- /dev/null +++ b/lib/browser/api/content-tracing.ts @@ -0,0 +1 @@ +export default process.electronBinding('content_tracing'); diff --git a/lib/browser/api/global-shortcut.js b/lib/browser/api/global-shortcut.js deleted file mode 100644 index b43431a0775f..000000000000 --- a/lib/browser/api/global-shortcut.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; - -module.exports = process.electronBinding('global_shortcut').globalShortcut; diff --git a/lib/browser/api/global-shortcut.ts b/lib/browser/api/global-shortcut.ts new file mode 100644 index 000000000000..283eb02a976b --- /dev/null +++ b/lib/browser/api/global-shortcut.ts @@ -0,0 +1 @@ +export default process.electronBinding('global_shortcut').globalShortcut; diff --git a/lib/browser/api/in-app-purchase.js b/lib/browser/api/in-app-purchase.ts similarity index 65% rename from lib/browser/api/in-app-purchase.js rename to lib/browser/api/in-app-purchase.ts index 77243f1a7f2b..6a76c53e01a0 100644 --- a/lib/browser/api/in-app-purchase.js +++ b/lib/browser/api/in-app-purchase.ts @@ -1,22 +1,24 @@ -'use strict'; +import { EventEmitter } from 'events'; -const { deprecate } = require('electron'); +let _inAppPurchase; if (process.platform === 'darwin') { - const { EventEmitter } = require('events'); const { inAppPurchase, InAppPurchase } = process.electronBinding('in_app_purchase'); // inAppPurchase is an EventEmitter. Object.setPrototypeOf(InAppPurchase.prototype, EventEmitter.prototype); EventEmitter.call(inAppPurchase); - module.exports = inAppPurchase; + _inAppPurchase = inAppPurchase; } else { - module.exports = { - purchaseProduct: (productID, quantity, callback) => { + _inAppPurchase = new EventEmitter(); + Object.assign(_inAppPurchase, { + purchaseProduct: () => { throw new Error('The inAppPurchase module can only be used on macOS'); }, canMakePayments: () => false, getReceiptURL: () => '' - }; + }); } + +export default _inAppPurchase; diff --git a/lib/browser/api/notification.js b/lib/browser/api/notification.js deleted file mode 100644 index 4619b1223fb1..000000000000 --- a/lib/browser/api/notification.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -const { Notification, isSupported } = process.electronBinding('notification'); - -Notification.isSupported = isSupported; - -module.exports = Notification; diff --git a/lib/browser/api/notification.ts b/lib/browser/api/notification.ts new file mode 100644 index 000000000000..edbe8927d23f --- /dev/null +++ b/lib/browser/api/notification.ts @@ -0,0 +1,5 @@ +const { Notification: ElectronNotification, isSupported } = process.electronBinding('notification'); + +ElectronNotification.isSupported = isSupported; + +export default ElectronNotification; diff --git a/lib/browser/api/power-save-blocker.js b/lib/browser/api/power-save-blocker.js deleted file mode 100644 index 928a8605cdcf..000000000000 --- a/lib/browser/api/power-save-blocker.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; - -module.exports = process.electronBinding('power_save_blocker').powerSaveBlocker; diff --git a/lib/browser/api/power-save-blocker.ts b/lib/browser/api/power-save-blocker.ts new file mode 100644 index 000000000000..e23b42014d9a --- /dev/null +++ b/lib/browser/api/power-save-blocker.ts @@ -0,0 +1 @@ +export default process.electronBinding('power_save_blocker').powerSaveBlocker; diff --git a/lib/browser/api/session.js b/lib/browser/api/session.js deleted file mode 100644 index fee2680bd272..000000000000 --- a/lib/browser/api/session.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -const { EventEmitter } = require('events'); -const { app, deprecate } = require('electron'); -const { fromPartition } = process.electronBinding('session'); - -// Public API. -Object.defineProperties(exports, { - defaultSession: { - enumerable: true, - get () { return fromPartition(''); } - }, - fromPartition: { - enumerable: true, - value: fromPartition - } -}); diff --git a/lib/browser/api/session.ts b/lib/browser/api/session.ts new file mode 100644 index 000000000000..9792b744aca4 --- /dev/null +++ b/lib/browser/api/session.ts @@ -0,0 +1,8 @@ +const { fromPartition } = process.electronBinding('session'); + +export default { + fromPartition, + get defaultSession () { + return fromPartition(''); + } +}; diff --git a/lib/browser/api/tray.js b/lib/browser/api/tray.ts similarity index 57% rename from lib/browser/api/tray.js rename to lib/browser/api/tray.ts index 4781e538f94f..1309ae2c6c79 100644 --- a/lib/browser/api/tray.js +++ b/lib/browser/api/tray.ts @@ -1,5 +1,3 @@ -'use strict'; - const { Tray } = process.electronBinding('tray'); -module.exports = Tray; +export default Tray; diff --git a/lib/browser/api/view.js b/lib/browser/api/view.ts similarity index 57% rename from lib/browser/api/view.js rename to lib/browser/api/view.ts index f49b513bab0c..7239c6cb3db2 100644 --- a/lib/browser/api/view.js +++ b/lib/browser/api/view.ts @@ -1,5 +1,3 @@ -'use strict'; - const { View } = process.electronBinding('view'); -module.exports = View; +export default View; diff --git a/lib/browser/api/views/image-view.js b/lib/browser/api/views/image-view.ts similarity index 57% rename from lib/browser/api/views/image-view.js rename to lib/browser/api/views/image-view.ts index 04881a0dbc58..004573c892a6 100644 --- a/lib/browser/api/views/image-view.js +++ b/lib/browser/api/views/image-view.ts @@ -1,8 +1,7 @@ -const electron = require('electron'); +import { View } from 'electron'; -const { View } = electron; const { ImageView } = process.electronBinding('image_view'); Object.setPrototypeOf(ImageView.prototype, View.prototype); -module.exports = ImageView; +export default ImageView; diff --git a/lib/browser/api/web-contents-view.js b/lib/browser/api/web-contents-view.ts similarity index 55% rename from lib/browser/api/web-contents-view.js rename to lib/browser/api/web-contents-view.ts index dab9ef76c863..a830c4b936e9 100644 --- a/lib/browser/api/web-contents-view.js +++ b/lib/browser/api/web-contents-view.ts @@ -1,10 +1,7 @@ -'use strict'; +import { View } from 'electron'; -const electron = require('electron'); - -const { View } = electron; const { WebContentsView } = process.electronBinding('web_contents_view'); Object.setPrototypeOf(WebContentsView.prototype, View.prototype); -module.exports = WebContentsView; +export default WebContentsView; diff --git a/lib/common/api/clipboard.js b/lib/common/api/clipboard.ts similarity index 80% rename from lib/common/api/clipboard.js rename to lib/common/api/clipboard.ts index eb8371b041c4..368cfa63840d 100644 --- a/lib/common/api/clipboard.js +++ b/lib/common/api/clipboard.ts @@ -1,13 +1,11 @@ -'use strict'; - const clipboard = process.electronBinding('clipboard'); if (process.type === 'renderer') { const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils'); const typeUtils = require('@electron/internal/common/type-utils'); - const makeRemoteMethod = function (method) { - return (...args) => { + const makeRemoteMethod = function (method: keyof Electron.Clipboard) { + return (...args: any[]) => { args = typeUtils.serialize(args); const result = ipcRendererUtils.invokeSync('ELECTRON_BROWSER_CLIPBOARD_SYNC', method, ...args); return typeUtils.deserialize(result); @@ -16,7 +14,7 @@ if (process.type === 'renderer') { if (process.platform === 'linux') { // On Linux we could not access clipboard in renderer process. - for (const method of Object.keys(clipboard)) { + for (const method of Object.keys(clipboard) as (keyof Electron.Clipboard)[]) { clipboard[method] = makeRemoteMethod(method); } } else if (process.platform === 'darwin') { @@ -26,4 +24,4 @@ if (process.type === 'renderer') { } } -module.exports = clipboard; +export default clipboard; diff --git a/lib/common/api/native-image.js b/lib/common/api/native-image.ts similarity index 59% rename from lib/common/api/native-image.js rename to lib/common/api/native-image.ts index e65060b3bc9c..3ea547999a58 100644 --- a/lib/common/api/native-image.js +++ b/lib/common/api/native-image.ts @@ -1,5 +1,3 @@ -'use strict'; - const { nativeImage } = process.electronBinding('native_image'); -module.exports = nativeImage; +export default nativeImage; diff --git a/lib/common/api/shell.js b/lib/common/api/shell.js deleted file mode 100644 index c9f7b6c0e4e2..000000000000 --- a/lib/common/api/shell.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; - -module.exports = process.electronBinding('shell'); diff --git a/lib/common/api/shell.ts b/lib/common/api/shell.ts new file mode 100644 index 000000000000..d4e03a4c1704 --- /dev/null +++ b/lib/common/api/shell.ts @@ -0,0 +1 @@ +export default process.electronBinding('shell'); diff --git a/lib/common/dummy.js b/lib/common/dummy.ts similarity index 100% rename from lib/common/dummy.js rename to lib/common/dummy.ts diff --git a/spec-main/ambient.d.ts b/spec-main/ambient.d.ts index bd63f7b111a1..ca1cd5713852 100644 --- a/spec-main/ambient.d.ts +++ b/spec-main/ambient.d.ts @@ -25,7 +25,6 @@ declare namespace Electron { constructor(args: {show: boolean}) setContentView(view: View): void } - class View {} class WebContentsView { constructor(options: BrowserWindowConstructorOptions) } diff --git a/typings/internal-electron.d.ts b/typings/internal-electron.d.ts index f485a4348ba2..01de1608d972 100644 --- a/typings/internal-electron.d.ts +++ b/typings/internal-electron.d.ts @@ -87,6 +87,8 @@ declare namespace Electron { namespace Main { const deprecate: ElectronInternal.DeprecationUtil; } + + class View {} } declare namespace ElectronInternal {