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
|
@ -2,6 +2,7 @@
|
|||
|
||||
const v8Util = process.electronBinding('v8_util');
|
||||
const { hasSwitch } = process.electronBinding('command_line');
|
||||
const { NativeImage } = process.electronBinding('native_image');
|
||||
|
||||
const { CallbacksRegistry } = require('@electron/internal/renderer/remote/callbacks-registry');
|
||||
const { isPromise, isSerializableObject } = require('@electron/internal/common/type-utils');
|
||||
|
@ -35,7 +36,15 @@ function wrapArgs (args, visited = new Set()) {
|
|||
};
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
if (value instanceof NativeImage) {
|
||||
const images = [];
|
||||
for (const scaleFactor of value.getScaleFactors()) {
|
||||
const size = value.getSize(scaleFactor);
|
||||
const buffer = value.toBitmap({ scaleFactor });
|
||||
images.push({ buffer, scaleFactor, size });
|
||||
}
|
||||
return { type: 'nativeimage', value: images };
|
||||
} else if (Array.isArray(value)) {
|
||||
visited.add(value);
|
||||
const meta = {
|
||||
type: 'array',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue