refactor: prevent consistent early exception (#24191)
* refactor: prevent consistent early exception * Use _linkedBinding where possible * Remove dead electronBinding
This commit is contained in:
parent
4c77fe318d
commit
659e79fc08
78 changed files with 134 additions and 145 deletions
|
@ -4,8 +4,8 @@ import * as path from 'path';
|
|||
import { deprecate, Menu } from 'electron';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
const bindings = process.electronBinding('app');
|
||||
const commandLine = process.electronBinding('command_line');
|
||||
const bindings = process._linkedBinding('electron_browser_app');
|
||||
const commandLine = process._linkedBinding('electron_common_command_line');
|
||||
const { app, App } = bindings;
|
||||
|
||||
// Only one app object permitted.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const { autoUpdater, AutoUpdater } = process.electronBinding('auto_updater');
|
||||
const { autoUpdater, AutoUpdater } = process._linkedBinding('electron_browser_auto_updater');
|
||||
|
||||
// AutoUpdater is an EventEmitter.
|
||||
Object.setPrototypeOf(AutoUpdater.prototype, EventEmitter.prototype);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { EventEmitter } from 'events';
|
||||
|
||||
const { BrowserView } = process.electronBinding('browser_view');
|
||||
const { BrowserView } = process._linkedBinding('electron_browser_browser_view');
|
||||
|
||||
Object.setPrototypeOf(BrowserView.prototype, EventEmitter.prototype);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const electron = require('electron');
|
||||
const { TopLevelWindow, deprecate } = electron;
|
||||
const { BrowserWindow } = process.electronBinding('window');
|
||||
const { BrowserWindow } = process._linkedBinding('electron_browser_window');
|
||||
|
||||
Object.setPrototypeOf(BrowserWindow.prototype, TopLevelWindow.prototype);
|
||||
|
||||
|
@ -59,7 +59,7 @@ BrowserWindow.prototype._init = function () {
|
|||
}
|
||||
|
||||
// Notify the creation of the window.
|
||||
const event = process.electronBinding('event').createEmpty();
|
||||
const event = process._linkedBinding('electron_browser_event').createEmpty();
|
||||
app.emit('browser-window-created', event, this);
|
||||
|
||||
Object.defineProperty(this, 'devToolsWebContents', {
|
||||
|
|
|
@ -1 +1 @@
|
|||
export default process.electronBinding('content_tracing');
|
||||
export default process._linkedBinding('electron_browser_content_tracing');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { app, deprecate } from 'electron';
|
||||
|
||||
const binding = process.electronBinding('crash_reporter');
|
||||
const binding = process._linkedBinding('electron_browser_crash_reporter');
|
||||
|
||||
class CrashReporter {
|
||||
start (options: Electron.CrashReporterStartOptions) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
const { app, BrowserWindow, deprecate } = require('electron');
|
||||
const binding = process.electronBinding('dialog');
|
||||
const v8Util = process.electronBinding('v8_util');
|
||||
const binding = process._linkedBinding('electron_browser_dialog');
|
||||
const v8Util = process._linkedBinding('electron_common_v8_util');
|
||||
|
||||
const DialogType = {
|
||||
OPEN: 'OPEN',
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
export default process.electronBinding('global_shortcut').globalShortcut;
|
||||
const { globalShortcut } = process._linkedBinding('electron_browser_global_shortcut');
|
||||
export default globalShortcut;
|
||||
|
|
|
@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
|
|||
let _inAppPurchase;
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
const { inAppPurchase, InAppPurchase } = process.electronBinding('in_app_purchase');
|
||||
const { inAppPurchase, InAppPurchase } = process._linkedBinding('electron_browser_in_app_purchase');
|
||||
|
||||
// inAppPurchase is an EventEmitter.
|
||||
Object.setPrototypeOf(InAppPurchase.prototype, EventEmitter.prototype);
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
const { TopLevelWindow, MenuItem, webContents } = require('electron');
|
||||
const { sortMenuItems } = require('@electron/internal/browser/api/menu-utils');
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const v8Util = process.electronBinding('v8_util');
|
||||
const bindings = process.electronBinding('menu');
|
||||
const v8Util = process._linkedBinding('electron_common_v8_util');
|
||||
const bindings = process._linkedBinding('electron_browser_menu');
|
||||
|
||||
const { Menu } = bindings;
|
||||
let applicationMenu = null;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { MessagePortMain } from '@electron/internal/browser/message-port-main';
|
||||
const { createPair } = process.electronBinding('message_port');
|
||||
const { createPair } = process._linkedBinding('electron_browser_message_port');
|
||||
|
||||
export default class MessageChannelMain {
|
||||
port1: MessagePortMain;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { EventEmitter } from 'events';
|
||||
|
||||
const { NativeTheme, nativeTheme } = process.electronBinding('native_theme');
|
||||
const { NativeTheme, nativeTheme } = process._linkedBinding('electron_common_native_theme');
|
||||
|
||||
Object.setPrototypeOf(NativeTheme.prototype, EventEmitter.prototype);
|
||||
EventEmitter.call(nativeTheme as any);
|
||||
|
|
|
@ -2,7 +2,13 @@ import * as url from 'url';
|
|||
import { Readable, Writable } from 'stream';
|
||||
import { app } from 'electron';
|
||||
import { ClientRequestConstructorOptions, UploadProgress } from 'electron/main';
|
||||
const { net, Net, isValidHeaderName, isValidHeaderValue, createURLLoader } = process.electronBinding('net');
|
||||
const {
|
||||
net,
|
||||
Net,
|
||||
isValidHeaderName,
|
||||
isValidHeaderValue,
|
||||
createURLLoader
|
||||
} = process._linkedBinding('electron_browser_net');
|
||||
|
||||
const kSupportedProtocols = new Set(['http:', 'https:']);
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
const { Notification: ElectronNotification, isSupported } = process.electronBinding('notification');
|
||||
const {
|
||||
Notification: ElectronNotification,
|
||||
isSupported
|
||||
} = process._linkedBinding('electron_common_notification');
|
||||
|
||||
ElectronNotification.isSupported = isSupported;
|
||||
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import { EventEmitter } from 'events';
|
||||
import { app } from 'electron';
|
||||
|
||||
const { createPowerMonitor, getSystemIdleState, getSystemIdleTime } = process.electronBinding('power_monitor');
|
||||
const {
|
||||
createPowerMonitor,
|
||||
getSystemIdleState,
|
||||
getSystemIdleTime
|
||||
} = process._linkedBinding('electron_browser_power_monitor');
|
||||
|
||||
class PowerMonitor extends EventEmitter {
|
||||
constructor () {
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
export default process.electronBinding('power_save_blocker').powerSaveBlocker;
|
||||
const { powerSaveBlocker } = process._linkedBinding('electron_browser_power_save_blocker');
|
||||
export default powerSaveBlocker;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { app, session } from 'electron';
|
||||
|
||||
// Global protocol APIs.
|
||||
const protocol = process.electronBinding('protocol');
|
||||
const protocol = process._linkedBinding('electron_browser_protocol');
|
||||
|
||||
// Fallback protocol APIs of default session.
|
||||
Object.setPrototypeOf(protocol, new Proxy({}, {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import { createLazyInstance } from '../utils';
|
||||
const { EventEmitter } = require('events');
|
||||
const { Screen, createScreen } = process.electronBinding('screen');
|
||||
const { Screen, createScreen } = process._linkedBinding('electron_common_screen');
|
||||
|
||||
// Screen is an EventEmitter.
|
||||
Object.setPrototypeOf(Screen.prototype, EventEmitter.prototype);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const { fromPartition } = process.electronBinding('session');
|
||||
const { fromPartition } = process._linkedBinding('electron_browser_session');
|
||||
|
||||
export default {
|
||||
fromPartition,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { EventEmitter } from 'events';
|
||||
import { deprecate } from 'electron';
|
||||
const { systemPreferences, SystemPreferences } = process.electronBinding('system_preferences');
|
||||
const { systemPreferences, SystemPreferences } = process._linkedBinding('electron_browser_system_preferences');
|
||||
|
||||
// SystemPreferences is an EventEmitter.
|
||||
Object.setPrototypeOf(SystemPreferences.prototype, EventEmitter.prototype);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const electron = require('electron');
|
||||
const { EventEmitter } = require('events');
|
||||
const { TopLevelWindow } = process.electronBinding('top_level_window');
|
||||
const { TopLevelWindow } = process._linkedBinding('electron_browser_top_level_window');
|
||||
|
||||
Object.setPrototypeOf(TopLevelWindow.prototype, EventEmitter.prototype);
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
const { Tray } = process.electronBinding('tray');
|
||||
const { Tray } = process._linkedBinding('electron_browser_tray');
|
||||
|
||||
export default Tray;
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
const { View } = process.electronBinding('view');
|
||||
const { View } = process._linkedBinding('electron_browser_view');
|
||||
|
||||
export default View;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { View } from 'electron';
|
||||
|
||||
const { ImageView } = process.electronBinding('image_view');
|
||||
const { ImageView } = process._linkedBinding('electron_browser_image_view');
|
||||
|
||||
Object.setPrototypeOf(ImageView.prototype, View.prototype);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { View } from 'electron';
|
||||
|
||||
const { WebContentsView } = process.electronBinding('web_contents_view');
|
||||
const { WebContentsView } = process._linkedBinding('electron_browser_web_contents_view');
|
||||
|
||||
Object.setPrototypeOf(WebContentsView.prototype, View.prototype);
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ const defaultPrintingSetting = {
|
|||
};
|
||||
|
||||
// JavaScript implementations of WebContents.
|
||||
const binding = process.electronBinding('web_contents');
|
||||
const binding = process._linkedBinding('electron_browser_web_contents');
|
||||
const { WebContents } = binding;
|
||||
|
||||
Object.setPrototypeOf(NavigationController.prototype, EventEmitter.prototype);
|
||||
|
@ -562,7 +562,7 @@ WebContents.prototype._init = function () {
|
|||
app.emit('login', event, this, ...args);
|
||||
});
|
||||
|
||||
const event = process.electronBinding('event').createEmpty();
|
||||
const event = process._linkedBinding('electron_browser_event').createEmpty();
|
||||
app.emit('web-contents-created', event, this);
|
||||
|
||||
// Properties
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue