Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nativeImage remote serialization #23543

Merged
merged 4 commits into from
May 18, 2020
Merged

Conversation

codebytere
Copy link
Member

Description of Change

Closes #23444.

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.

Tested with https://gist.github.com/d8f1bcee2aa65c85b9cf3c8e4d34ad82.

cc @nornagon @MarshallOfSound

Checklist

Release Notes

Notes: Fixed an issue where nativeImages might throw conversion errors in the renderer process.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label May 12, 2020
Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but needs a test!

@codebytere codebytere requested a review from nornagon May 12, 2020 20:17
@@ -259,6 +262,8 @@ 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':
return electron.nativeImage.createFromBitmap(meta.value.buffer, meta.value.size as any);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scaleFactor option should also be passed, and we should add a way to pass the isTemplateImage information.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to do a different serialization of native images here we should also update type-utils.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nornagon i was planning to handle that in a subsequent pr to prevent too much scope creep 🤔 i can do it here if preferable though.

@codebytere codebytere force-pushed the fix-nativeimage-serialization branch 4 times, most recently from f073717 to 500160a Compare May 13, 2020 05:24
@codebytere codebytere force-pushed the fix-nativeimage-serialization branch 5 times, most recently from dc3795f to 136177b Compare May 13, 2020 17:35
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label May 13, 2020
@codebytere codebytere force-pushed the fix-nativeimage-serialization branch from 136177b to d5b088b Compare May 14, 2020 02:03
@codebytere codebytere force-pushed the fix-nativeimage-serialization branch from d5b088b to 17ebafa Compare May 14, 2020 02:04
shell/common/api/electron_api_native_image.cc Outdated Show resolved Hide resolved
spec-main/api-remote-spec.ts Outdated Show resolved Hide resolved
spec-main/api-remote-spec.ts Outdated Show resolved Hide resolved
spec-main/api-remote-spec.ts Outdated Show resolved Hide resolved
spec-main/api-remote-spec.ts Outdated Show resolved Hide resolved
@codebytere codebytere force-pushed the fix-nativeimage-serialization branch from ae666e8 to 7d5e375 Compare May 14, 2020 21:23
@trop
Copy link
Contributor

trop bot commented May 18, 2020

I was unable to backport this PR to "8-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented May 18, 2020

I have automatically backported this PR to "9-x-y", please check out #23635

@codebytere codebytere deleted the fix-nativeimage-serialization branch May 18, 2020 17:12
codebytere added a commit that referenced this pull request May 27, 2020
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.
@trop
Copy link
Contributor

trop bot commented May 27, 2020

@codebytere has manually backported this PR to "9-x-y", please check out #23796

codebytere added a commit that referenced this pull request May 27, 2020
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.
@trop
Copy link
Contributor

trop bot commented May 27, 2020

@codebytere has manually backported this PR to "8-x-y", please check out #23797

codebytere added a commit that referenced this pull request Jun 8, 2020
* 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.

* refactor: correctly serialize nativeImage/buffer with typeUtils (#23666)

* refactor: correctly serialize nativeImage/buffer with typeUtils

* test: add serialization specs

* fix: construct from dataURL

* test: test for dataURL specificity

* refactor: use typeutils for nativeImage serialization

* fix: ensure nativeImage serialization main->renderer

* chore: fix FTBFS

Co-authored-by: Charles Kerr <charles@charleskerr.com>
@ckerr ckerr mentioned this pull request Jun 8, 2020
6 tasks
@trop
Copy link
Contributor

trop bot commented Jun 8, 2020

@ckerr has manually backported this PR to "7-3-x", please check out #24021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot use Icon in MenuItem: "Could not call remote method 'buildFromTemplate'" error
4 participants