forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for share menu on macOS (electron#25629)
- Loading branch information
Showing
17 changed files
with
316 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
## Class: ShareMenu | ||
|
||
> Create share menu on macOS. | ||
Process: [Main](../glossary.md#main-process) | ||
|
||
The `ShareMenu` class creates [Share Menu][share-menu] on macOS, which can be | ||
used to share information from the current context to apps, social media | ||
accounts, and other services. | ||
|
||
For including the share menu as a submenu of other menus, please use the | ||
`shareMenu` role of [`MenuItem`](menu-item.md). | ||
|
||
### `new ShareMenu(sharingItem)` | ||
|
||
* `sharingItem` SharingItem - The item to share. | ||
|
||
Creates a new share menu. | ||
|
||
### Instance Methods | ||
|
||
The `shareMenu` object has the following instance methods: | ||
|
||
#### `shareMenu.popup([options])` | ||
|
||
* `options` PopupOptions (optional) | ||
* `browserWindow` [BrowserWindow](browser-window.md) (optional) - Default is the focused window. | ||
* `x` Number (optional) - Default is the current mouse cursor position. | ||
Must be declared if `y` is declared. | ||
* `y` Number (optional) - Default is the current mouse cursor position. | ||
Must be declared if `x` is declared. | ||
* `positioningItem` Number (optional) _macOS_ - The index of the menu item to | ||
be positioned under the mouse cursor at the specified coordinates. Default | ||
is -1. | ||
* `callback` Function (optional) - Called when menu is closed. | ||
|
||
Pops up this menu as a context menu in the [`BrowserWindow`](browser-window.md). | ||
|
||
#### `shareMenu.closePopup([browserWindow])` | ||
|
||
* `browserWindow` [BrowserWindow](browser-window.md) (optional) - Default is the focused window. | ||
|
||
Closes the context menu in the `browserWindow`. | ||
|
||
[share-menu]: https://developer.apple.com/design/human-interface-guidelines/macos/extensions/share-extensions/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# SharingItem Object | ||
|
||
* `texts` String[] (optional) - An array of text to share. | ||
* `filePaths` String[] (optional) - An array of files to share. | ||
* `urls` String[] (optional) - An array of URLs to share. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { BrowserWindow, Menu, SharingItem, PopupOptions } from 'electron/main'; | ||
|
||
class ShareMenu { | ||
private menu: Menu; | ||
|
||
constructor (sharingItem: SharingItem) { | ||
this.menu = new (Menu as any)({ sharingItem }); | ||
} | ||
|
||
popup (options?: PopupOptions) { | ||
this.menu.popup(options); | ||
} | ||
|
||
closePopup (browserWindow?: BrowserWindow) { | ||
this.menu.closePopup(browserWindow); | ||
} | ||
} | ||
|
||
export default ShareMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.