Skip to content

Commit

Permalink
Add Services submenu on macOS (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
caesar authored and sindresorhus committed Jun 3, 2019
1 parent 28662f3 commit 295e19d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ declare namespace contextMenu {
@default 'Inspect Element'
*/
readonly inspect?: string;

/**
@default 'Services'
*/
readonly services?: string;
}

interface ActionOptions {
Expand All @@ -61,6 +66,7 @@ declare namespace contextMenu {
interface Actions {
readonly separator: () => MenuItem;
readonly inspect: () => MenuItem;
readonly services: () => MenuItem;
readonly cut: (options: ActionOptions) => MenuItem;
readonly copy: (options: ActionOptions) => MenuItem;
readonly paste: (options: ActionOptions) => MenuItem;
Expand Down Expand Up @@ -116,6 +122,13 @@ declare namespace contextMenu {
*/
readonly showInspectElement?: boolean;

/**
Show the system `Services` submenu on macOS.
@default false
*/
readonly showServices?: boolean;

/**
Show the `Look Up [selection]` menu item when right-clicking text on macOS.
Expand Down
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ const create = (win, options) => {
}
}
}),
services: () => ({
id: 'services',
label: 'Services',
role: 'services',
visible: process.platform === 'darwin' && (props.isEditable || hasText)
}),
separator: () => ({type: 'separator'}),
saveImage: decorateMenuItem({
id: 'save',
Expand Down Expand Up @@ -155,6 +161,7 @@ const create = (win, options) => {
defaultActions.copyLink(),
defaultActions.separator(),
options.showInspectElement && defaultActions.inspect(),
options.showServices && defaultActions.services(),
defaultActions.separator()
];

Expand Down
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ Default: [Only in development](https://github.com/sindresorhus/electron-is-dev)

Force enable or disable the `Inspect Element` menu item.

#### showServices

Type: `boolean`<br>
Default: `false`

Show the system `Services` submenu when right-clicking text on macOS.

Note: Due to [a bug in the Electron implementation](https://github.com/electron/electron/issues/18476), this menu is not identical to the "Services" submenu in the context menus of native apps. Instead, it looks the same as the "Services" menu in the main App Menu. For this reason, it is currently disabled by default.

#### showLookUpSelection

Type: `boolean`<br>
Expand Down Expand Up @@ -151,6 +160,7 @@ The following options are ignored when `menu` is used:
- `showCopyImageAddress`
- `showSaveImageAs`
- `showInspectElement`
- `showServices`

Default actions:

Expand All @@ -164,6 +174,7 @@ Default actions:
- `copyImageAddress`
- `copyLink`
- `inspect`
- `services`

Example:

Expand Down

0 comments on commit 295e19d

Please sign in to comment.