The `services` MenuItem role displays incorrectly in context menus
caesar opened this issue · comments
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:
- 5.0.2
- Operating System:
- macOS 10.14.5
- Last Known Working Electron version:
- none
Expected Behavior
When used in a context menu (or anywhere other than the main Application menu), a submenu with role: services
should look like a normal menu, without icons or headings, like in native Mac apps.
Screenshot from Safari (expected behaviour):
Actual Behavior
A MenuItem with role: services
always displays a menu like that used in the main Application menu, with icons and headings.
Screenshot from Electron (actual behaviour):
To Reproduce
Create a MenuItem with role: service
in a context menu (or anywhere other than in the main menubar).
A cursory look at this tells me we're not distinguishing between NSServices
, which are the services a specific app enables, and the bespoke servicesMenu
. For now, the best short term fix might be to only enable the servicesMenu
on non-context menus, but perhaps eventually we can look into the ability to self-populate NSServices.
@codebytere Actually I don't think it's related to NSServices
, which are the services provided by the current app. This menu should be listing services from other apps.
As you say, the problem is that the context menu item is being wrongly designated as a servicesMenu
. I haven't been able to find what should be used instead, despite some fairly deep digging through Apple's docs.
I did find NSSharingServicePicker
, which is the equivalent for the "Share" menu…
I'm not sure it's actually necessary to disable role: services
outside the Application menu – does it actually do any harm if it's used in other places? Not sure.
Good observations @sindresorhus!
This is looking like it's probably really hard to implement in Electron if it has to be done from scratch, but maybe we can look at Chromium's implementation?
@caesar @sindresorhus i don't believe chromium has a custom impl atm, or at least one one that we could ourselves use as a template :(
@codebytere They do have Services in their context menu (or at least Chrome does), I wonder how that is achieved?
I confess zero familiarity with the Chromium codebase…
As far as I know, the Services
menu item is automatically added to the context menu depending on what the NSView
responds to in the validRequestorForSendType
method.
Hmmm, so can Chromium's implementation of validRequestorForSendType
be used in / ported to Electron?
Potentially relevant Chromium commit: chromium/chromium@eef99c2
I'll see what i can do! thanks for digging in, folks :D
Thank you for taking the time to report this issue and helping to make Electron better.
The version of Electron you reported this on has been superseded by newer releases.
If you're still experiencing this issue in Electron 6.x.y or later, please add a comment specifying the version you're testing with and any other new information that a maintainer trying to reproduce the issue should know.
I'm setting the blocked/need-info
label for the above reasons. This issue will be closed 7 days from now if there is no response.
Thanks in advance! Your help is appreciated.
Thank you for your issue!
We haven't gotten a response to our questions in our comment above. With only the information that is currently in the issue, we don't have enough information to take action. I'm going to close this but don't hesitate to reach out if you have or find the answers we need, we'll be happy to reopen the issue.