Skip to content

Cannot use Icon in MenuItem: "Could not call remote method 'buildFromTemplate'" error #23444

Closed

Description

@dropsonic

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    • 8.0.2 (also checked on 8.2.5.)
  • Operating System:
    • Windows 10 Pro (1903)
  • Last Known Working Electron version:

Expected Behavior

The menu is created without any errors

Actual Behavior

Error:

render.js:48 Uncaught (in promise) Error: Could not call remote method 'buildFromTemplate'. Check that the method signature is correct. Underlying error: Error processing argument at index 1, conversion failure from 
Underlying stack: TypeError: Error processing argument at index 1, conversion failure from 
    at Menu../lib/browser/api/menu.js.Menu.insert (electron/js2c/browser_init.js:1855:23)
    at Menu../lib/browser/api/menu.js.Menu.append (electron/js2c/browser_init.js:1835:15)
    at electron/js2c/browser_init.js:1913:12
    at Array.forEach (<anonymous>)
    at Function../lib/browser/api/menu.js.Menu.buildFromTemplate (electron/js2c/browser_init.js:1909:10)
    at electron/js2c/browser_init.js:6745:67
    at IpcMainImpl.<anonymous> (electron/js2c/browser_init.js:6610:27)
    at IpcMainImpl.emit (events.js:210:5)
    at WebContents.<anonymous> (electron/js2c/browser_init.js:3873:23)
    at WebContents.emit (events.js:210:5)

    at electron/js2c/browser_init.js:6748:21
    at IpcMainImpl.<anonymous> (electron/js2c/browser_init.js:6610:27)
    at IpcMainImpl.emit (events.js:210:5)
    at WebContents.<anonymous> (electron/js2c/browser_init.js:3873:23)
    at WebContents.emit (events.js:210:5)
getVideoSources @ render.js:48
async function (async)
getVideoSources @ render.js:32

To Reproduce

$ git clone https://github.com/dropsonic/223-electron-screen-recorder.git -b master
$ npm install
$ npm start

Press 'Choose a Video Source' button.

The code:

async function getVideoSources() {
	const inputSources = await desktopCapturer.getSources({
		types: [ 'window', 'screen' ],
		fetchWindowIcons: true
	});

	const videoOptionsMenu = Menu.buildFromTemplate(
		inputSources.map((source) => {
			return {
				label: source.name,
				icon: source.appIcon,
				click: () => selectSource(source)
			};
		})
	);

	videoOptionsMenu.popup();
}

Screenshots

image

Additional Information

I've also tried to set nativeImage.createEmpty() as an icon but got the same error.

Activity

  1. codebytere commented on May 12, 2020

    @codebytere
    Member

    @dropsonic in the short term, remove the icons from the MenuItems and that'll fix it. This seems to be caused by a conversion error borne of the fact that the sources returned from desktopCapturer.getSources contain invalid appIcons. I'll try to look further into it.

  2. dropsonic commented on May 12, 2020

    @dropsonic
    Author

    @codebytere it looks like it is not related to desktopCapturer.getSources because if I use nativeImage.createEmpty() as an icon I get the same error.

  3. codebytere commented on May 12, 2020

    @codebytere
    Member

    @dropsonic yep, exactly. The invalidity is that some of them are empty.

  4. dropsonic commented on May 12, 2020

    @dropsonic
    Author

    @codebytere oh, now I see. So it means that if I define icons for menu items, I have to define a valid icon for each item?

    icon: !source.appIcon || source.appIcon.isEmpty() ? undefined : source.appIcon, doesn't help either.

    According to the log, desktopCapturer.getSources returns several items with non-empty images, some items with empty images (appIcon.isEmpty() returns true) and some items with null appIcon.

  5. codebytere commented on May 12, 2020

    @codebytere
    Member

    @dropsonic i think the root of this issue may lie with us :) I'll do some digging and see what i find.

  6. codebytere commented on May 12, 2020

    @codebytere
    Member

    @dropsonic i've determined the underlying issue and opened a PR. Feel free to follow the above linked PR to track it to a release once it's merged :)

  7. dropsonic commented on May 13, 2020

    @dropsonic
    Author

    @codebytere wow, that was blazingly fast. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions