fix: type internal APIs that can return null properly (#29852)
This commit is contained in:
parent
461db8f1ab
commit
a545cd3790
6 changed files with 12 additions and 12 deletions
|
@ -67,7 +67,7 @@ ipcMainInternal.handle(IPC_MESSAGES.INSPECTOR_CONTEXT_MENU, function (event, ite
|
||||||
|
|
||||||
const template = isEditMenu ? getEditMenuItems() : convertToMenuTemplate(items, resolve);
|
const template = isEditMenu ? getEditMenuItems() : convertToMenuTemplate(items, resolve);
|
||||||
const menu = Menu.buildFromTemplate(template);
|
const menu = Menu.buildFromTemplate(template);
|
||||||
const window = event.sender.getOwnerBrowserWindow();
|
const window = event.sender.getOwnerBrowserWindow()!;
|
||||||
|
|
||||||
menu.popup({ window, callback: () => resolve() });
|
menu.popup({ window, callback: () => resolve() });
|
||||||
});
|
});
|
||||||
|
@ -94,7 +94,7 @@ ipcMainUtils.handleSync(IPC_MESSAGES.INSPECTOR_CONFIRM, async function (event, m
|
||||||
buttons: ['OK', 'Cancel'],
|
buttons: ['OK', 'Cancel'],
|
||||||
cancelId: 1
|
cancelId: 1
|
||||||
};
|
};
|
||||||
const window = event.sender.getOwnerBrowserWindow();
|
const window = event.sender.getOwnerBrowserWindow()!;
|
||||||
const { response } = await dialog.showMessageBox(window, options);
|
const { response } = await dialog.showMessageBox(window, options);
|
||||||
return response === 0;
|
return response === 0;
|
||||||
});
|
});
|
||||||
|
|
|
@ -193,7 +193,7 @@ const attachGuest = function (event: Electron.IpcMainInvokeEvent,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Inherit certain option values from embedder
|
// Inherit certain option values from embedder
|
||||||
const lastWebPreferences = embedder.getLastWebPreferences();
|
const lastWebPreferences = embedder.getLastWebPreferences()!;
|
||||||
for (const [name, value] of inheritedWebPreferences) {
|
for (const [name, value] of inheritedWebPreferences) {
|
||||||
if (lastWebPreferences[name as keyof Electron.WebPreferences] === value) {
|
if (lastWebPreferences[name as keyof Electron.WebPreferences] === value) {
|
||||||
(webPreferences as any)[name] = value;
|
(webPreferences as any)[name] = value;
|
||||||
|
|
|
@ -144,7 +144,7 @@ function emitDeprecatedNewWindowEvent ({ event, embedder, guest, windowOpenArgs,
|
||||||
postData?: PostData,
|
postData?: PostData,
|
||||||
}): boolean {
|
}): boolean {
|
||||||
const { url, frameName } = windowOpenArgs;
|
const { url, frameName } = windowOpenArgs;
|
||||||
const isWebViewWithPopupsDisabled = embedder.getType() === 'webview' && embedder.getLastWebPreferences().disablePopups;
|
const isWebViewWithPopupsDisabled = embedder.getType() === 'webview' && embedder.getLastWebPreferences()!.disablePopups;
|
||||||
const postBody = postData ? {
|
const postBody = postData ? {
|
||||||
data: postData,
|
data: postData,
|
||||||
...parseContentTypeFormat(postData)
|
...parseContentTypeFormat(postData)
|
||||||
|
@ -229,7 +229,7 @@ export function makeWebPreferences ({ embedder, secureOverrideWebPreferences = {
|
||||||
// have unvetted prefs, use parsedWebPreferences.
|
// have unvetted prefs, use parsedWebPreferences.
|
||||||
secureOverrideWebPreferences?: BrowserWindowConstructorOptions['webPreferences'],
|
secureOverrideWebPreferences?: BrowserWindowConstructorOptions['webPreferences'],
|
||||||
}) {
|
}) {
|
||||||
const parentWebPreferences = embedder.getLastWebPreferences();
|
const parentWebPreferences = embedder.getLastWebPreferences()!;
|
||||||
const securityWebPreferencesFromParent = (Object.keys(securityWebPreferences).reduce((map, key) => {
|
const securityWebPreferencesFromParent = (Object.keys(securityWebPreferences).reduce((map, key) => {
|
||||||
if (securityWebPreferences[key] === parentWebPreferences[key as keyof Electron.WebPreferences]) {
|
if (securityWebPreferences[key] === parentWebPreferences[key as keyof Electron.WebPreferences]) {
|
||||||
(map as any)[key] = parentWebPreferences[key as keyof Electron.WebPreferences];
|
(map as any)[key] = parentWebPreferences[key as keyof Electron.WebPreferences];
|
||||||
|
|
|
@ -28,7 +28,7 @@ const getGuestWindow = function (guestContents: WebContents) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const isChildWindow = function (sender: WebContents, target: WebContents) {
|
const isChildWindow = function (sender: WebContents, target: WebContents) {
|
||||||
return target.getLastWebPreferences().openerId === sender.id;
|
return target.getLastWebPreferences()!.openerId === sender.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
const isRelatedWindow = function (sender: WebContents, target: WebContents) {
|
const isRelatedWindow = function (sender: WebContents, target: WebContents) {
|
||||||
|
@ -43,7 +43,7 @@ const isScriptableWindow = function (sender: WebContents, target: WebContents) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const isNodeIntegrationEnabled = function (sender: WebContents) {
|
const isNodeIntegrationEnabled = function (sender: WebContents) {
|
||||||
return sender.getLastWebPreferences().nodeIntegration === true;
|
return sender.getLastWebPreferences()!.nodeIntegration === true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Checks whether |sender| can access the |target|:
|
// Checks whether |sender| can access the |target|:
|
||||||
|
@ -65,7 +65,7 @@ ipcMainInternal.on(
|
||||||
features: string
|
features: string
|
||||||
) => {
|
) => {
|
||||||
// This should only be allowed for senders that have nativeWindowOpen: false
|
// This should only be allowed for senders that have nativeWindowOpen: false
|
||||||
const lastWebPreferences = event.sender.getLastWebPreferences();
|
const lastWebPreferences = event.sender.getLastWebPreferences()!;
|
||||||
if (lastWebPreferences.nativeWindowOpen || lastWebPreferences.sandbox) {
|
if (lastWebPreferences.nativeWindowOpen || lastWebPreferences.sandbox) {
|
||||||
event.returnValue = null;
|
event.returnValue = null;
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
4
spec-main/ambient.d.ts
vendored
4
spec-main/ambient.d.ts
vendored
|
@ -2,8 +2,8 @@ declare let standardScheme: string;
|
||||||
|
|
||||||
declare namespace Electron {
|
declare namespace Electron {
|
||||||
interface WebContents {
|
interface WebContents {
|
||||||
getOwnerBrowserWindow(): BrowserWindow;
|
getOwnerBrowserWindow(): BrowserWindow | null;
|
||||||
getWebPreferences(): any;
|
getWebPreferences(): WebPreferences | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Session {
|
interface Session {
|
||||||
|
|
4
typings/internal-electron.d.ts
vendored
4
typings/internal-electron.d.ts
vendored
|
@ -56,8 +56,8 @@ declare namespace Electron {
|
||||||
|
|
||||||
interface WebContents {
|
interface WebContents {
|
||||||
_loadURL(url: string, options: ElectronInternal.LoadURLOptions): void;
|
_loadURL(url: string, options: ElectronInternal.LoadURLOptions): void;
|
||||||
getOwnerBrowserWindow(): Electron.BrowserWindow;
|
getOwnerBrowserWindow(): Electron.BrowserWindow | null;
|
||||||
getLastWebPreferences(): Electron.WebPreferences;
|
getLastWebPreferences(): Electron.WebPreferences | null;
|
||||||
_getPreloadPaths(): string[];
|
_getPreloadPaths(): string[];
|
||||||
equal(other: WebContents): boolean;
|
equal(other: WebContents): boolean;
|
||||||
browserWindowOptions: BrowserWindowConstructorOptions;
|
browserWindowOptions: BrowserWindowConstructorOptions;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue