electron / electron

:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS

Home Page:https://electronjs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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):
Screenshot 2019-05-26 at 20 44 02

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):
Screenshot 2019-05-26 at 21 16 28

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.

Another thing. When Services is in a context menu, it should be hidden if there are no applicable services. This is how native apps work. Right now, it still shows:

Screen Shot 2019-05-30 at 11 42 35

It should also never show the "Services Preferences…" menu item when in a context menu.

If there are 4 or less applicable services, they should be shown right in the context menu, and not in a Services submenu:

Screen Shot 2019-05-30 at 11 50 29

(From Safari)

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.

https://stackoverflow.com/questions/28786776/how-does-right-clicking-text-and-selecting-a-service-work

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.