build: update some build dependencies (#44070)
* build: update some build dependencies (#43882) * build: update some build dependencies * build: fix eslint issues after updating * build: disable ts check on busted js example * build: update internal types for stricter event handling * restore url.parse behavior * fix typing issues * sigh * build: update easy deps * build: skip woa engines check * build: s/colors/chalk * build: node 20 on windows
This commit is contained in:
parent
2e84985439
commit
2f519a8f2e
50 changed files with 2354 additions and 1343 deletions
|
@ -251,33 +251,35 @@ export const roleList: Record<RoleId, Role> = {
|
|||
{ role: 'cut' },
|
||||
{ role: 'copy' },
|
||||
{ role: 'paste' },
|
||||
...(isMac ? [
|
||||
{ role: 'pasteAndMatchStyle' },
|
||||
{ role: 'delete' },
|
||||
{ role: 'selectAll' },
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: 'Substitutions',
|
||||
submenu: [
|
||||
{ role: 'showSubstitutions' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'toggleSmartQuotes' },
|
||||
{ role: 'toggleSmartDashes' },
|
||||
{ role: 'toggleTextReplacement' }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Speech',
|
||||
submenu: [
|
||||
{ role: 'startSpeaking' },
|
||||
{ role: 'stopSpeaking' }
|
||||
]
|
||||
}
|
||||
] as MenuItemConstructorOptions[] : [
|
||||
{ role: 'delete' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'selectAll' }
|
||||
] as MenuItemConstructorOptions[])
|
||||
...(isMac
|
||||
? [
|
||||
{ role: 'pasteAndMatchStyle' },
|
||||
{ role: 'delete' },
|
||||
{ role: 'selectAll' },
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: 'Substitutions',
|
||||
submenu: [
|
||||
{ role: 'showSubstitutions' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'toggleSmartQuotes' },
|
||||
{ role: 'toggleSmartDashes' },
|
||||
{ role: 'toggleTextReplacement' }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Speech',
|
||||
submenu: [
|
||||
{ role: 'startSpeaking' },
|
||||
{ role: 'stopSpeaking' }
|
||||
]
|
||||
}
|
||||
] as MenuItemConstructorOptions[]
|
||||
: [
|
||||
{ role: 'delete' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'selectAll' }
|
||||
] as MenuItemConstructorOptions[])
|
||||
]
|
||||
},
|
||||
// View submenu
|
||||
|
@ -301,12 +303,14 @@ export const roleList: Record<RoleId, Role> = {
|
|||
submenu: [
|
||||
{ role: 'minimize' },
|
||||
{ role: 'zoom' },
|
||||
...(isMac ? [
|
||||
{ type: 'separator' },
|
||||
{ role: 'front' }
|
||||
] as MenuItemConstructorOptions[] : [
|
||||
{ role: 'close' }
|
||||
] as MenuItemConstructorOptions[])
|
||||
...(isMac
|
||||
? [
|
||||
{ type: 'separator' },
|
||||
{ role: 'front' }
|
||||
] as MenuItemConstructorOptions[]
|
||||
: [
|
||||
{ role: 'close' }
|
||||
] as MenuItemConstructorOptions[])
|
||||
]
|
||||
},
|
||||
// Share submenu
|
||||
|
|
|
@ -117,10 +117,12 @@ class TouchBarColorPicker extends TouchBarItem<Electron.TouchBarColorPickerConst
|
|||
@LiveProperty<TouchBarColorPicker>(config => config.selectedColor)
|
||||
selectedColor!: string;
|
||||
|
||||
@ImmutableProperty<TouchBarColorPicker>(({ change: onChange }, setInternalProp) => typeof onChange === 'function' ? (details: { color: string }) => {
|
||||
setInternalProp('selectedColor', details.color);
|
||||
onChange(details.color);
|
||||
} : null)
|
||||
@ImmutableProperty<TouchBarColorPicker>(({ change: onChange }, setInternalProp) => typeof onChange === 'function'
|
||||
? (details: { color: string }) => {
|
||||
setInternalProp('selectedColor', details.color);
|
||||
onChange(details.color);
|
||||
}
|
||||
: null)
|
||||
onInteraction!: Function | null;
|
||||
}
|
||||
|
||||
|
@ -203,10 +205,12 @@ class TouchBarSlider extends TouchBarItem<Electron.TouchBarSliderConstructorOpti
|
|||
@LiveProperty<TouchBarSlider>(config => config.value)
|
||||
value!: number;
|
||||
|
||||
@ImmutableProperty<TouchBarSlider>(({ change: onChange }, setInternalProp) => typeof onChange === 'function' ? (details: { value: number }) => {
|
||||
setInternalProp('value', details.value);
|
||||
onChange(details.value);
|
||||
} : null)
|
||||
@ImmutableProperty<TouchBarSlider>(({ change: onChange }, setInternalProp) => typeof onChange === 'function'
|
||||
? (details: { value: number }) => {
|
||||
setInternalProp('value', details.value);
|
||||
onChange(details.value);
|
||||
}
|
||||
: null)
|
||||
onInteraction!: Function | null;
|
||||
}
|
||||
|
||||
|
@ -236,10 +240,12 @@ class TouchBarSegmentedControl extends TouchBarItem<Electron.TouchBarSegmentedCo
|
|||
@LiveProperty<TouchBarSegmentedControl>(config => config.mode)
|
||||
mode!: Electron.TouchBarSegmentedControl['mode'];
|
||||
|
||||
@ImmutableProperty<TouchBarSegmentedControl>(({ change: onChange }, setInternalProp) => typeof onChange === 'function' ? (details: { selectedIndex: number, isSelected: boolean }) => {
|
||||
setInternalProp('selectedIndex', details.selectedIndex);
|
||||
onChange(details.selectedIndex, details.isSelected);
|
||||
} : null)
|
||||
@ImmutableProperty<TouchBarSegmentedControl>(({ change: onChange }, setInternalProp) => typeof onChange === 'function'
|
||||
? (details: { selectedIndex: number, isSelected: boolean }) => {
|
||||
setInternalProp('selectedIndex', details.selectedIndex);
|
||||
onChange(details.selectedIndex, details.isSelected);
|
||||
}
|
||||
: null)
|
||||
onInteraction!: Function | null;
|
||||
}
|
||||
|
||||
|
@ -265,13 +271,15 @@ class TouchBarScrubber extends TouchBarItem<Electron.TouchBarScrubberConstructor
|
|||
@LiveProperty<TouchBarScrubber>(config => typeof config.continuous === 'undefined' ? true : config.continuous)
|
||||
continuous!: boolean;
|
||||
|
||||
@ImmutableProperty<TouchBarScrubber>(({ select: onSelect, highlight: onHighlight }) => typeof onSelect === 'function' || typeof onHighlight === 'function' ? (details: { type: 'select'; selectedIndex: number } | { type: 'highlight'; highlightedIndex: number }) => {
|
||||
if (details.type === 'select') {
|
||||
if (onSelect) onSelect(details.selectedIndex);
|
||||
} else {
|
||||
if (onHighlight) onHighlight(details.highlightedIndex);
|
||||
}
|
||||
} : null)
|
||||
@ImmutableProperty<TouchBarScrubber>(({ select: onSelect, highlight: onHighlight }) => typeof onSelect === 'function' || typeof onHighlight === 'function'
|
||||
? (details: { type: 'select'; selectedIndex: number } | { type: 'highlight'; highlightedIndex: number }) => {
|
||||
if (details.type === 'select') {
|
||||
if (onSelect) onSelect(details.selectedIndex);
|
||||
} else {
|
||||
if (onHighlight) onHighlight(details.highlightedIndex);
|
||||
}
|
||||
}
|
||||
: null)
|
||||
onInteraction!: Function | null;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { app, ipcMain, session, webFrameMain, dialog } from 'electron/main';
|
||||
import type { BrowserWindowConstructorOptions, LoadURLOptions, MessageBoxOptions, WebFrameMain } from 'electron/main';
|
||||
import type { BrowserWindowConstructorOptions, MessageBoxOptions } from 'electron/main';
|
||||
|
||||
import * as url from 'url';
|
||||
import * as path from 'path';
|
||||
|
@ -24,8 +24,6 @@ const getNextId = function () {
|
|||
return ++nextId;
|
||||
};
|
||||
|
||||
type PostData = LoadURLOptions['postData']
|
||||
|
||||
// Stock page sizes
|
||||
const PDFPageSizes: Record<string, ElectronInternal.MediaSize> = {
|
||||
Letter: {
|
||||
|
@ -403,7 +401,7 @@ WebContents.prototype.loadURL = function (url, options) {
|
|||
// the only one is with a bad scheme, perhaps ERR_INVALID_ARGUMENT
|
||||
// would be more appropriate.
|
||||
if (!error) {
|
||||
error = { errorCode: -2, errorDescription: 'ERR_FAILED', url: url };
|
||||
error = { errorCode: -2, errorDescription: 'ERR_FAILED', url };
|
||||
}
|
||||
finishListener();
|
||||
};
|
||||
|
@ -602,7 +600,7 @@ WebContents.prototype._init = function () {
|
|||
});
|
||||
|
||||
// Dispatch IPC messages to the ipc module.
|
||||
this.on('-ipc-message' as any, function (this: Electron.WebContents, event: Electron.IpcMainEvent, internal: boolean, channel: string, args: any[]) {
|
||||
this.on('-ipc-message', function (this: Electron.WebContents, event, internal, channel, args) {
|
||||
addSenderToEvent(event, this);
|
||||
if (internal) {
|
||||
ipcMainInternal.emit(channel, event, ...args);
|
||||
|
@ -616,7 +614,7 @@ WebContents.prototype._init = function () {
|
|||
}
|
||||
});
|
||||
|
||||
this.on('-ipc-invoke' as any, async function (this: Electron.WebContents, event: Electron.IpcMainInvokeEvent, internal: boolean, channel: string, args: any[]) {
|
||||
this.on('-ipc-invoke', async function (this: Electron.WebContents, event, internal, channel, args) {
|
||||
addSenderToEvent(event, this);
|
||||
const replyWithResult = (result: any) => event._replyChannel.sendReply({ result });
|
||||
const replyWithError = (error: Error) => {
|
||||
|
@ -638,7 +636,7 @@ WebContents.prototype._init = function () {
|
|||
}
|
||||
});
|
||||
|
||||
this.on('-ipc-message-sync' as any, function (this: Electron.WebContents, event: Electron.IpcMainEvent, internal: boolean, channel: string, args: any[]) {
|
||||
this.on('-ipc-message-sync', function (this: Electron.WebContents, event, internal, channel, args) {
|
||||
addSenderToEvent(event, this);
|
||||
addReturnValueToEvent(event);
|
||||
if (internal) {
|
||||
|
@ -656,7 +654,7 @@ WebContents.prototype._init = function () {
|
|||
}
|
||||
});
|
||||
|
||||
this.on('-ipc-ports' as any, function (this: Electron.WebContents, event: Electron.IpcMainEvent, internal: boolean, channel: string, message: any, ports: any[]) {
|
||||
this.on('-ipc-ports', function (this: Electron.WebContents, event: Electron.IpcMainEvent, internal: boolean, channel: string, message: any, ports: any[]) {
|
||||
addSenderToEvent(event, this);
|
||||
event.ports = ports.map(p => new MessagePortMain(p));
|
||||
const maybeWebFrame = getWebFrameForEvent(event);
|
||||
|
@ -674,7 +672,7 @@ WebContents.prototype._init = function () {
|
|||
}
|
||||
});
|
||||
|
||||
this.on('-before-unload-fired' as any, function (this: Electron.WebContents, event: Electron.Event, proceed: boolean) {
|
||||
this.on('-before-unload-fired', function (this: Electron.WebContents, event, proceed) {
|
||||
const type = this.getType();
|
||||
// These are the "interactive" types, i.e. ones a user might be looking at.
|
||||
// All other types should ignore the "proceed" signal and unload
|
||||
|
@ -691,12 +689,13 @@ WebContents.prototype._init = function () {
|
|||
|
||||
if (this.getType() !== 'remote') {
|
||||
// Make new windows requested by links behave like "window.open".
|
||||
this.on('-new-window' as any, (event: Electron.Event, url: string, frameName: string, disposition: Electron.HandlerDetails['disposition'],
|
||||
rawFeatures: string, referrer: Electron.Referrer, postData: PostData) => {
|
||||
const postBody = postData ? {
|
||||
data: postData,
|
||||
...parseContentTypeFormat(postData)
|
||||
} : undefined;
|
||||
this.on('-new-window', (event, url, frameName, disposition, rawFeatures, referrer, postData) => {
|
||||
const postBody = postData
|
||||
? {
|
||||
data: postData,
|
||||
...parseContentTypeFormat(postData)
|
||||
}
|
||||
: undefined;
|
||||
const details: Electron.HandlerDetails = {
|
||||
url,
|
||||
frameName,
|
||||
|
@ -733,11 +732,13 @@ WebContents.prototype._init = function () {
|
|||
let windowOpenOutlivesOpenerOption: boolean = false;
|
||||
let createWindow: Electron.CreateWindowFunction | undefined;
|
||||
|
||||
this.on('-will-add-new-contents' as any, (event: Electron.Event, url: string, frameName: string, rawFeatures: string, disposition: Electron.HandlerDetails['disposition'], referrer: Electron.Referrer, postData: PostData) => {
|
||||
const postBody = postData ? {
|
||||
data: postData,
|
||||
...parseContentTypeFormat(postData)
|
||||
} : undefined;
|
||||
this.on('-will-add-new-contents', (event, url, frameName, rawFeatures, disposition, referrer, postData) => {
|
||||
const postBody = postData
|
||||
? {
|
||||
data: postData,
|
||||
...parseContentTypeFormat(postData)
|
||||
}
|
||||
: undefined;
|
||||
const details: Electron.HandlerDetails = {
|
||||
url,
|
||||
frameName,
|
||||
|
@ -759,14 +760,16 @@ WebContents.prototype._init = function () {
|
|||
windowOpenOverriddenOptions = result.browserWindowConstructorOptions;
|
||||
createWindow = result.createWindow;
|
||||
if (!event.defaultPrevented) {
|
||||
const secureOverrideWebPreferences = windowOpenOverriddenOptions ? {
|
||||
// Allow setting of backgroundColor as a webPreference even though
|
||||
// it's technically a BrowserWindowConstructorOptions option because
|
||||
// we need to access it in the renderer at init time.
|
||||
backgroundColor: windowOpenOverriddenOptions.backgroundColor,
|
||||
transparent: windowOpenOverriddenOptions.transparent,
|
||||
...windowOpenOverriddenOptions.webPreferences
|
||||
} : undefined;
|
||||
const secureOverrideWebPreferences = windowOpenOverriddenOptions
|
||||
? {
|
||||
// Allow setting of backgroundColor as a webPreference even though
|
||||
// it's technically a BrowserWindowConstructorOptions option because
|
||||
// we need to access it in the renderer at init time.
|
||||
backgroundColor: windowOpenOverriddenOptions.backgroundColor,
|
||||
transparent: windowOpenOverriddenOptions.transparent,
|
||||
...windowOpenOverriddenOptions.webPreferences
|
||||
}
|
||||
: undefined;
|
||||
const { webPreferences: parsedWebPreferences } = parseFeatures(rawFeatures);
|
||||
const webPreferences = makeWebPreferences({
|
||||
embedder: this,
|
||||
|
@ -782,9 +785,7 @@ WebContents.prototype._init = function () {
|
|||
});
|
||||
|
||||
// Create a new browser window for "window.open"
|
||||
this.on('-add-new-contents' as any, (event: Electron.Event, webContents: Electron.WebContents, disposition: string,
|
||||
_userGesture: boolean, _left: number, _top: number, _width: number, _height: number, url: string, frameName: string,
|
||||
referrer: Electron.Referrer, rawFeatures: string, postData: PostData) => {
|
||||
this.on('-add-new-contents', (event, webContents, disposition, _userGesture, _left, _top, _width, _height, url, frameName, referrer, rawFeatures, postData) => {
|
||||
const overriddenOptions = windowOpenOverriddenOptions || undefined;
|
||||
const outlivesOpener = windowOpenOutlivesOpenerOption;
|
||||
const windowOpenFunction = createWindow;
|
||||
|
@ -822,7 +823,7 @@ WebContents.prototype._init = function () {
|
|||
app.emit('login', event, this, ...args);
|
||||
});
|
||||
|
||||
this.on('ready-to-show' as any, () => {
|
||||
this.on('ready-to-show', () => {
|
||||
const owner = this.getOwnerBrowserWindow();
|
||||
if (owner && !owner.isDestroyed()) {
|
||||
process.nextTick(() => {
|
||||
|
@ -841,7 +842,7 @@ WebContents.prototype._init = function () {
|
|||
|
||||
const originCounts = new Map<string, number>();
|
||||
const openDialogs = new Set<AbortController>();
|
||||
this.on('-run-dialog' as any, async (info: {frame: WebFrameMain, dialogType: 'prompt' | 'confirm' | 'alert', messageText: string, defaultPromptText: string}, callback: (success: boolean, user_input: string) => void) => {
|
||||
this.on('-run-dialog', async (info, callback) => {
|
||||
const originUrl = new URL(info.frame.url);
|
||||
const origin = originUrl.protocol === 'file:' ? originUrl.href : originUrl.origin;
|
||||
if ((originCounts.get(origin) ?? 0) < 0) return callback(false, '');
|
||||
|
@ -862,15 +863,17 @@ WebContents.prototype._init = function () {
|
|||
message: info.messageText,
|
||||
checkboxLabel: checkbox,
|
||||
signal: abortController.signal,
|
||||
...(info.dialogType === 'confirm') ? {
|
||||
buttons: ['OK', 'Cancel'],
|
||||
defaultId: 0,
|
||||
cancelId: 1
|
||||
} : {
|
||||
buttons: ['OK'],
|
||||
defaultId: -1, // No default button
|
||||
cancelId: 0
|
||||
}
|
||||
...(info.dialogType === 'confirm')
|
||||
? {
|
||||
buttons: ['OK', 'Cancel'],
|
||||
defaultId: 0,
|
||||
cancelId: 1
|
||||
}
|
||||
: {
|
||||
buttons: ['OK'],
|
||||
defaultId: -1, // No default button
|
||||
cancelId: 0
|
||||
}
|
||||
};
|
||||
openDialogs.add(abortController);
|
||||
const promise = parent && !prefs.offscreen ? dialog.showMessageBox(parent, options) : dialog.showMessageBox(options);
|
||||
|
@ -884,7 +887,7 @@ WebContents.prototype._init = function () {
|
|||
}
|
||||
});
|
||||
|
||||
this.on('-cancel-dialogs' as any, () => {
|
||||
this.on('-cancel-dialogs', () => {
|
||||
for (const controller of openDialogs) { controller.abort(); }
|
||||
openDialogs.clear();
|
||||
});
|
||||
|
|
|
@ -14,33 +14,35 @@ export const setDefaultApplicationMenu = () => {
|
|||
|
||||
const helpMenu: Electron.MenuItemConstructorOptions = {
|
||||
role: 'help',
|
||||
submenu: app.isPackaged ? [] : [
|
||||
{
|
||||
label: 'Learn More',
|
||||
click: async () => {
|
||||
await shell.openExternal('https://electronjs.org');
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Documentation',
|
||||
click: async () => {
|
||||
const version = process.versions.electron;
|
||||
await shell.openExternal(`https://github.com/electron/electron/tree/v${version}/docs#readme`);
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Community Discussions',
|
||||
click: async () => {
|
||||
await shell.openExternal('https://discord.gg/electronjs');
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Search Issues',
|
||||
click: async () => {
|
||||
await shell.openExternal('https://github.com/electron/electron/issues');
|
||||
}
|
||||
}
|
||||
]
|
||||
submenu: app.isPackaged
|
||||
? []
|
||||
: [
|
||||
{
|
||||
label: 'Learn More',
|
||||
click: async () => {
|
||||
await shell.openExternal('https://electronjs.org');
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Documentation',
|
||||
click: async () => {
|
||||
const version = process.versions.electron;
|
||||
await shell.openExternal(`https://github.com/electron/electron/tree/v${version}/docs#readme`);
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Community Discussions',
|
||||
click: async () => {
|
||||
await shell.openExternal('https://discord.gg/electronjs');
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Search Issues',
|
||||
click: async () => {
|
||||
await shell.openExternal('https://github.com/electron/electron/issues');
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const macAppMenu: Electron.MenuItemConstructorOptions = { role: 'appMenu' };
|
||||
|
|
|
@ -7,23 +7,29 @@ import { IPC_MESSAGES } from '@electron/internal//common/ipc-messages';
|
|||
|
||||
const convertToMenuTemplate = function (items: ContextMenuItem[], handler: (id: number) => void) {
|
||||
return items.map(function (item) {
|
||||
const transformed: Electron.MenuItemConstructorOptions = item.type === 'subMenu' ? {
|
||||
type: 'submenu',
|
||||
label: item.label,
|
||||
enabled: item.enabled,
|
||||
submenu: convertToMenuTemplate(item.subItems, handler)
|
||||
} : item.type === 'separator' ? {
|
||||
type: 'separator'
|
||||
} : item.type === 'checkbox' ? {
|
||||
type: 'checkbox',
|
||||
label: item.label,
|
||||
enabled: item.enabled,
|
||||
checked: item.checked
|
||||
} : {
|
||||
type: 'normal',
|
||||
label: item.label,
|
||||
enabled: item.enabled
|
||||
};
|
||||
const transformed: Electron.MenuItemConstructorOptions = item.type === 'subMenu'
|
||||
? {
|
||||
type: 'submenu',
|
||||
label: item.label,
|
||||
enabled: item.enabled,
|
||||
submenu: convertToMenuTemplate(item.subItems, handler)
|
||||
}
|
||||
: item.type === 'separator'
|
||||
? {
|
||||
type: 'separator'
|
||||
}
|
||||
: item.type === 'checkbox'
|
||||
? {
|
||||
type: 'checkbox',
|
||||
label: item.label,
|
||||
enabled: item.enabled,
|
||||
checked: item.checked
|
||||
}
|
||||
: {
|
||||
type: 'normal',
|
||||
label: item.label,
|
||||
enabled: item.enabled
|
||||
};
|
||||
|
||||
if (item.id != null) {
|
||||
transformed.click = () => handler(item.id);
|
||||
|
|
|
@ -237,7 +237,7 @@ const watchEmbedder = function (embedder: Electron.WebContents) {
|
|||
}
|
||||
}
|
||||
};
|
||||
embedder.on('-window-visibility-change' as any, onVisibilityChange);
|
||||
embedder.on('-window-visibility-change', onVisibilityChange);
|
||||
|
||||
embedder.once('will-destroy' as any, () => {
|
||||
// Usually the guestInstances is cleared when guest is destroyed, but it
|
||||
|
@ -249,7 +249,7 @@ const watchEmbedder = function (embedder: Electron.WebContents) {
|
|||
}
|
||||
}
|
||||
// Clear the listeners.
|
||||
embedder.removeListener('-window-visibility-change' as any, onVisibilityChange);
|
||||
embedder.removeListener('-window-visibility-change', onVisibilityChange);
|
||||
watchedEmbedders.delete(embedder);
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue