Skip to content

Commit

Permalink
chore: tsify more of lib (electron#23721)
Browse files Browse the repository at this point in the history
* chore: tsify more of lib

* Update lib/browser/api/session.ts

Co-authored-by: Jeremy Apthorp <jeremya@chromium.org>

Co-authored-by: Jeremy Apthorp <jeremya@chromium.org>
  • Loading branch information
MarshallOfSound and nornagon committed May 22, 2020
1 parent 762f7bc commit 9bc5e98
Show file tree
Hide file tree
Showing 25 changed files with 66 additions and 94 deletions.
2 changes: 1 addition & 1 deletion build/webpack/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand Down
46 changes: 23 additions & 23 deletions filenames.auto.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
'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;
}

return null;
};

module.exports = BrowserView;
export default BrowserView;
2 changes: 0 additions & 2 deletions lib/browser/api/content-tracing.js

This file was deleted.

1 change: 1 addition & 0 deletions lib/browser/api/content-tracing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default process.electronBinding('content_tracing');
3 changes: 0 additions & 3 deletions lib/browser/api/global-shortcut.js

This file was deleted.

1 change: 1 addition & 0 deletions lib/browser/api/global-shortcut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default process.electronBinding('global_shortcut').globalShortcut;
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 0 additions & 7 deletions lib/browser/api/notification.js

This file was deleted.

5 changes: 5 additions & 0 deletions lib/browser/api/notification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { Notification: ElectronNotification, isSupported } = process.electronBinding('notification');

ElectronNotification.isSupported = isSupported;

export default ElectronNotification;
3 changes: 0 additions & 3 deletions lib/browser/api/power-save-blocker.js

This file was deleted.

1 change: 1 addition & 0 deletions lib/browser/api/power-save-blocker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default process.electronBinding('power_save_blocker').powerSaveBlocker;
17 changes: 0 additions & 17 deletions lib/browser/api/session.js

This file was deleted.

8 changes: 8 additions & 0 deletions lib/browser/api/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { fromPartition } = process.electronBinding('session');

export default {
fromPartition,
get defaultSession () {
return fromPartition('');
}
};
4 changes: 1 addition & 3 deletions lib/browser/api/tray.js → lib/browser/api/tray.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const { Tray } = process.electronBinding('tray');

module.exports = Tray;
export default Tray;
4 changes: 1 addition & 3 deletions lib/browser/api/view.js → lib/browser/api/view.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const { View } = process.electronBinding('view');

module.exports = View;
export default View;
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 4 additions & 6 deletions lib/common/api/clipboard.js → lib/common/api/clipboard.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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') {
Expand All @@ -26,4 +24,4 @@ if (process.type === 'renderer') {
}
}

module.exports = clipboard;
export default clipboard;
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const { nativeImage } = process.electronBinding('native_image');

module.exports = nativeImage;
export default nativeImage;
3 changes: 0 additions & 3 deletions lib/common/api/shell.js

This file was deleted.

1 change: 1 addition & 0 deletions lib/common/api/shell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default process.electronBinding('shell');
File renamed without changes.
1 change: 0 additions & 1 deletion spec-main/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ declare namespace Electron {
constructor(args: {show: boolean})
setContentView(view: View): void
}
class View {}
class WebContentsView {
constructor(options: BrowserWindowConstructorOptions)
}
Expand Down
2 changes: 2 additions & 0 deletions typings/internal-electron.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ declare namespace Electron {
namespace Main {
const deprecate: ElectronInternal.DeprecationUtil;
}

class View {}
}

declare namespace ElectronInternal {
Expand Down

0 comments on commit 9bc5e98

Please sign in to comment.