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:
Shelley Vohr 2020-05-18 09:29:24 -07:00 committed by GitHub
parent eb341b383d
commit ee0f67d541
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 100 additions and 14 deletions

View file

@ -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',