Skip to content

Commit 295e19d

Browse files
caesarsindresorhus
authored andcommitted
Add Services submenu on macOS (#73)
1 parent 28662f3 commit 295e19d

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

index.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ declare namespace contextMenu {
4949
@default 'Inspect Element'
5050
*/
5151
readonly inspect?: string;
52+
53+
/**
54+
@default 'Services'
55+
*/
56+
readonly services?: string;
5257
}
5358

5459
interface ActionOptions {
@@ -61,6 +66,7 @@ declare namespace contextMenu {
6166
interface Actions {
6267
readonly separator: () => MenuItem;
6368
readonly inspect: () => MenuItem;
69+
readonly services: () => MenuItem;
6470
readonly cut: (options: ActionOptions) => MenuItem;
6571
readonly copy: (options: ActionOptions) => MenuItem;
6672
readonly paste: (options: ActionOptions) => MenuItem;
@@ -116,6 +122,13 @@ declare namespace contextMenu {
116122
*/
117123
readonly showInspectElement?: boolean;
118124

125+
/**
126+
Show the system `Services` submenu on macOS.
127+
128+
@default false
129+
*/
130+
readonly showServices?: boolean;
131+
119132
/**
120133
Show the `Look Up [selection]` menu item when right-clicking text on macOS.
121134

index.js

+7
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ const create = (win, options) => {
8383
}
8484
}
8585
}),
86+
services: () => ({
87+
id: 'services',
88+
label: 'Services',
89+
role: 'services',
90+
visible: process.platform === 'darwin' && (props.isEditable || hasText)
91+
}),
8692
separator: () => ({type: 'separator'}),
8793
saveImage: decorateMenuItem({
8894
id: 'save',
@@ -155,6 +161,7 @@ const create = (win, options) => {
155161
defaultActions.copyLink(),
156162
defaultActions.separator(),
157163
options.showInspectElement && defaultActions.inspect(),
164+
options.showServices && defaultActions.services(),
158165
defaultActions.separator()
159166
];
160167

readme.md

+11
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ Default: [Only in development](https://github.com/sindresorhus/electron-is-dev)
9393

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

96+
#### showServices
97+
98+
Type: `boolean`<br>
99+
Default: `false`
100+
101+
Show the system `Services` submenu when right-clicking text on macOS.
102+
103+
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.
104+
96105
#### showLookUpSelection
97106

98107
Type: `boolean`<br>
@@ -151,6 +160,7 @@ The following options are ignored when `menu` is used:
151160
- `showCopyImageAddress`
152161
- `showSaveImageAs`
153162
- `showInspectElement`
163+
- `showServices`
154164

155165
Default actions:
156166

@@ -164,6 +174,7 @@ Default actions:
164174
- `copyImageAddress`
165175
- `copyLink`
166176
- `inspect`
177+
- `services`
167178

168179
Example:
169180

0 commit comments

Comments
 (0)