fix: nativeImage remote serialization (#23543)
We weren't serializing nativeImages properly in the remote module, leading to gin conversion errors when trying to, for example, create a new context menu in the renderer with icons using nativeImage. This fixes that by adding a new special case to handle them.
This commit is contained in:
parent
eb341b383d
commit
ee0f67d541
5 changed files with 100 additions and 14 deletions
|
@ -5,6 +5,7 @@ import { EventEmitter } from 'events';
|
|||
import objectsRegistry from './objects-registry';
|
||||
import { ipcMainInternal } from '../ipc-main-internal';
|
||||
import { isPromise, isSerializableObject } from '@electron/internal/common/type-utils';
|
||||
import { Size } from 'electron/main';
|
||||
|
||||
const v8Util = process.electronBinding('v8_util');
|
||||
const eventBinding = process.electronBinding('event');
|
||||
|
@ -242,6 +243,9 @@ type MetaTypeFromRenderer = {
|
|||
id: number,
|
||||
location: string,
|
||||
length: number
|
||||
} | {
|
||||
type: 'nativeimage',
|
||||
value: { size: Size, buffer: Buffer, scaleFactor: number }[]
|
||||
}
|
||||
|
||||
const fakeConstructor = (constructor: Function, name: string) =>
|
||||
|
@ -259,6 +263,19 @@ const fakeConstructor = (constructor: Function, name: string) =>
|
|||
const unwrapArgs = function (sender: electron.WebContents, frameId: number, contextId: string, args: any[]) {
|
||||
const metaToValue = function (meta: MetaTypeFromRenderer): any {
|
||||
switch (meta.type) {
|
||||
case 'nativeimage': {
|
||||
const image = electron.nativeImage.createEmpty();
|
||||
for (const rep of meta.value) {
|
||||
const { buffer, size, scaleFactor } = rep;
|
||||
image.addRepresentation({
|
||||
buffer,
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
scaleFactor
|
||||
});
|
||||
}
|
||||
return image;
|
||||
}
|
||||
case 'value':
|
||||
return meta.value;
|
||||
case 'remote-object':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue