build: ensure that electron/lib/browser can only use browser or common imports (#24512)
* build: ensure that electron/lib/browser can only use browser or common imports * chore: fix linting
This commit is contained in:
parent
1719f073c1
commit
b02748e607
28 changed files with 92 additions and 65 deletions
|
@ -1,7 +1,7 @@
|
|||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
import { deprecate, Menu } from 'electron';
|
||||
import { deprecate, Menu } from 'electron/main';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
const bindings = process._linkedBinding('electron_browser_app');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { app } from 'electron';
|
||||
import { app } from 'electron/main';
|
||||
import { EventEmitter } from 'events';
|
||||
import * as squirrelUpdate from './squirrel-update-win';
|
||||
import * as squirrelUpdate from '@electron/internal/browser/api/auto-updater/squirrel-update-win';
|
||||
|
||||
class AutoUpdater extends EventEmitter {
|
||||
updateAvailable: boolean = false;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { EventEmitter } from 'events';
|
||||
import type { BaseWindow as TLWT } from 'electron';
|
||||
import type { BaseWindow as TLWT } from 'electron/main';
|
||||
const { BaseWindow } = process._linkedBinding('electron_browser_base_window') as { BaseWindow: typeof TLWT };
|
||||
|
||||
Object.setPrototypeOf(BaseWindow.prototype, EventEmitter.prototype);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BaseWindow, WebContents, Event, BrowserView, TouchBar } from 'electron';
|
||||
import type { BrowserWindow as BWT } from 'electron';
|
||||
import { BaseWindow, WebContents, Event, BrowserView, TouchBar } from 'electron/main';
|
||||
import type { BrowserWindow as BWT } from 'electron/main';
|
||||
const { BrowserWindow } = process._linkedBinding('electron_browser_window') as { BrowserWindow: typeof BWT };
|
||||
|
||||
Object.setPrototypeOf(BrowserWindow.prototype, BaseWindow.prototype);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { app, deprecate } from 'electron';
|
||||
import { app, deprecate } from 'electron/main';
|
||||
|
||||
const binding = process._linkedBinding('electron_browser_crash_reporter');
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { app, BrowserWindow } from 'electron';
|
||||
import { OpenDialogOptions, OpenDialogReturnValue, MessageBoxOptions, SaveDialogOptions, SaveDialogReturnValue, MessageBoxReturnValue, CertificateTrustDialogOptions } from 'electron/main';
|
||||
import { app, BrowserWindow } from 'electron/main';
|
||||
import type { OpenDialogOptions, OpenDialogReturnValue, MessageBoxOptions, SaveDialogOptions, SaveDialogReturnValue, MessageBoxReturnValue, CertificateTrustDialogOptions } from 'electron/main';
|
||||
const dialogBinding = process._linkedBinding('electron_browser_dialog');
|
||||
|
||||
const DialogType = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { app, BrowserWindow, WebContents, MenuItemConstructorOptions } from 'electron';
|
||||
import { app, BrowserWindow, WebContents, MenuItemConstructorOptions } from 'electron/main';
|
||||
|
||||
const isMac = process.platform === 'darwin';
|
||||
const isWindows = process.platform === 'win32';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as roles from './menu-item-roles';
|
||||
import { Menu, Event, BrowserWindow, WebContents } from 'electron';
|
||||
import * as roles from '@electron/internal/browser/api/menu-item-roles';
|
||||
import { Menu, Event, BrowserWindow, WebContents } from 'electron/main';
|
||||
|
||||
let nextCommandId = 0;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { BaseWindow, MenuItem, webContents, Menu as MenuType, BrowserWindow, MenuItemConstructorOptions } from 'electron';
|
||||
import { sortMenuItems } from './menu-utils';
|
||||
import { BaseWindow, MenuItem, webContents, Menu as MenuType, BrowserWindow, MenuItemConstructorOptions } from 'electron/main';
|
||||
import { sortMenuItems } from '@electron/internal/browser/api/menu-utils';
|
||||
|
||||
const v8Util = process._linkedBinding('electron_common_v8_util');
|
||||
const bindings = process._linkedBinding('electron_browser_menu');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// TODO(deepak1556): Deprecate and remove standalone netLog module,
|
||||
// it is now a property of session module.
|
||||
import { app, session } from 'electron';
|
||||
import { app, session } from 'electron/main';
|
||||
|
||||
const startLogging: typeof session.defaultSession.netLog.startLogging = async (path, options) => {
|
||||
if (!app.isReady()) return;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as url from 'url';
|
||||
import { Readable, Writable } from 'stream';
|
||||
import { app } from 'electron';
|
||||
import { ClientRequestConstructorOptions, UploadProgress } from 'electron/main';
|
||||
import { app } from 'electron/main';
|
||||
import type { ClientRequestConstructorOptions, UploadProgress } from 'electron/main';
|
||||
const {
|
||||
isValidHeaderName,
|
||||
isValidHeaderValue,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { EventEmitter } from 'events';
|
||||
import { app } from 'electron';
|
||||
import { app } from 'electron/main';
|
||||
|
||||
const {
|
||||
createPowerMonitor,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { app, session } from 'electron';
|
||||
import { app, session } from 'electron/main';
|
||||
|
||||
// Global protocol APIs.
|
||||
const protocol = process._linkedBinding('electron_browser_protocol');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
import { createLazyInstance } from '../utils';
|
||||
import { createLazyInstance } from '@electron/internal/browser/utils';
|
||||
const { EventEmitter } = require('events');
|
||||
const { Screen, createScreen } = process._linkedBinding('electron_common_screen');
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { EventEmitter } from 'events';
|
||||
import { deprecate } from 'electron';
|
||||
import { deprecate } from 'electron/main';
|
||||
const { systemPreferences, SystemPreferences } = process._linkedBinding('electron_browser_system_preferences');
|
||||
|
||||
// SystemPreferences is an EventEmitter.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { View } from 'electron';
|
||||
import { View } from 'electron/main';
|
||||
|
||||
const { ImageView } = process._linkedBinding('electron_browser_image_view');
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { View } from 'electron';
|
||||
import { View } from 'electron/main';
|
||||
|
||||
const { WebContentsView } = process._linkedBinding('electron_browser_web_contents_view');
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import { app, ipcMain, session, deprecate } from 'electron';
|
||||
import type { MenuItem, MenuItemConstructorOptions, WebContentsInternal } from 'electron';
|
||||
import { app, ipcMain, session, deprecate } from 'electron/main';
|
||||
import type { MenuItem, MenuItemConstructorOptions } from 'electron/main';
|
||||
|
||||
import * as url from 'url';
|
||||
import * as path from 'path';
|
||||
import { internalWindowOpen } from '../guest-window-manager';
|
||||
import { NavigationController } from '../navigation-controller';
|
||||
import { ipcMainInternal } from '../ipc-main-internal';
|
||||
import * as ipcMainUtils from '../ipc-main-internal-utils';
|
||||
import { parseFeatures } from '../../common/parse-features-string';
|
||||
import { MessagePortMain } from '../message-port-main';
|
||||
import { internalWindowOpen } from '@electron/internal/browser/guest-window-manager';
|
||||
import { NavigationController } from '@electron/internal/browser/navigation-controller';
|
||||
import { ipcMainInternal } from '@electron/internal/browser/ipc-main-internal';
|
||||
import * as ipcMainUtils from '@electron/internal/browser/ipc-main-internal-utils';
|
||||
import { parseFeatures } from '@electron/internal/common/parse-features-string';
|
||||
import { MessagePortMain } from '@electron/internal/browser/message-port-main';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
// session is not used here, the purpose is to make sure session is initalized
|
||||
|
@ -122,7 +122,7 @@ const defaultPrintingSetting = {
|
|||
|
||||
// JavaScript implementations of WebContents.
|
||||
const binding = process._linkedBinding('electron_browser_web_contents');
|
||||
const { WebContents } = binding as { WebContents: { prototype: WebContentsInternal } };
|
||||
const { WebContents } = binding as { WebContents: { prototype: Electron.WebContentsInternal } };
|
||||
|
||||
Object.setPrototypeOf(WebContents.prototype, EventEmitter.prototype);
|
||||
|
||||
|
@ -203,7 +203,7 @@ for (const method of webFrameMethods) {
|
|||
};
|
||||
}
|
||||
|
||||
const waitTillCanExecuteJavaScript = async (webContents: WebContentsInternal) => {
|
||||
const waitTillCanExecuteJavaScript = async (webContents: Electron.WebContentsInternal) => {
|
||||
if (webContents.getURL() && !webContents.isLoadingMainFrame()) return;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
|
@ -483,7 +483,7 @@ WebContents.prototype._init = function () {
|
|||
this.setMaxListeners(0);
|
||||
|
||||
// Dispatch IPC messages to the ipc module.
|
||||
this.on('-ipc-message' as any, function (this: WebContentsInternal, event: any, internal: boolean, channel: string, args: any[]) {
|
||||
this.on('-ipc-message' as any, function (this: Electron.WebContentsInternal, event: any, internal: boolean, channel: string, args: any[]) {
|
||||
if (internal) {
|
||||
addReplyInternalToEvent(event);
|
||||
ipcMainInternal.emit(channel, event, ...args);
|
||||
|
@ -508,7 +508,7 @@ WebContents.prototype._init = function () {
|
|||
}
|
||||
});
|
||||
|
||||
this.on('-ipc-message-sync' as any, function (this: WebContentsInternal, event: any, internal: boolean, channel: string, args: any[]) {
|
||||
this.on('-ipc-message-sync' as any, function (this: Electron.WebContentsInternal, event: any, internal: boolean, channel: string, args: any[]) {
|
||||
addReturnValueToEvent(event);
|
||||
if (internal) {
|
||||
addReplyInternalToEvent(event);
|
||||
|
@ -546,7 +546,7 @@ WebContents.prototype._init = function () {
|
|||
});
|
||||
|
||||
// The devtools requests the webContents to reload.
|
||||
this.on('devtools-reload-page', function (this: WebContentsInternal) {
|
||||
this.on('devtools-reload-page', function (this: Electron.WebContentsInternal) {
|
||||
this.reload();
|
||||
});
|
||||
|
||||
|
@ -569,7 +569,7 @@ WebContents.prototype._init = function () {
|
|||
|
||||
// Create a new browser window for the native implementation of
|
||||
// "window.open", used in sandbox and nativeWindowOpen mode.
|
||||
this.on('-add-new-contents' as any, (event: any, webContents: WebContentsInternal, disposition: string,
|
||||
this.on('-add-new-contents' as any, (event: any, webContents: Electron.WebContentsInternal, disposition: string,
|
||||
userGesture: boolean, left: number, top: number, width: number, height: number, url: string, frameName: string,
|
||||
referrer: string, rawFeatures: string, postData: string) => {
|
||||
if ((disposition !== 'foreground-tab' && disposition !== 'new-window' &&
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue