docs: Make tray.md follow docs style guide
This commit is contained in:
parent
11f242a241
commit
9d63199c37
1 changed files with 29 additions and 37 deletions
|
@ -5,17 +5,17 @@
|
||||||
```javascript
|
```javascript
|
||||||
const {app, Menu, Tray} = require('electron')
|
const {app, Menu, Tray} = require('electron')
|
||||||
|
|
||||||
let appIcon = null
|
let tray = null
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
appIcon = new Tray('/path/to/my/icon')
|
tray = new Tray('/path/to/my/icon')
|
||||||
const contextMenu = Menu.buildFromTemplate([
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
{label: 'Item1', type: 'radio'},
|
{label: 'Item1', type: 'radio'},
|
||||||
{label: 'Item2', type: 'radio'},
|
{label: 'Item2', type: 'radio'},
|
||||||
{label: 'Item3', type: 'radio', checked: true},
|
{label: 'Item3', type: 'radio', checked: true},
|
||||||
{label: 'Item4', type: 'radio'}
|
{label: 'Item4', type: 'radio'}
|
||||||
]);
|
]);
|
||||||
appIcon.setToolTip('This is my application.')
|
tray.setToolTip('This is my application.')
|
||||||
appIcon.setContextMenu(contextMenu)
|
tray.setContextMenu(contextMenu)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -49,21 +49,18 @@ rely on the `click` event and always attach a context menu to the tray icon.
|
||||||
|
|
||||||
Creates a new tray icon associated with the `image`.
|
Creates a new tray icon associated with the `image`.
|
||||||
|
|
||||||
## Events
|
### Instance Events
|
||||||
|
|
||||||
The `Tray` module emits the following events:
|
The `Tray` module emits the following events:
|
||||||
|
|
||||||
**Note:** Some events are only available on specific operating systems and are
|
#### Event: 'click'
|
||||||
labeled as such.
|
|
||||||
|
|
||||||
### Event: 'click'
|
|
||||||
|
|
||||||
* `event` Event
|
* `event` Event
|
||||||
* `altKey` Boolean
|
* `altKey` Boolean
|
||||||
* `shiftKey` Boolean
|
* `shiftKey` Boolean
|
||||||
* `ctrlKey` Boolean
|
* `ctrlKey` Boolean
|
||||||
* `metaKey` Boolean
|
* `metaKey` Boolean
|
||||||
* `bounds` Object - the bounds of tray icon.
|
* `bounds` Object _macOS_ _Windows_ - the bounds of tray icon.
|
||||||
* `x` Integer
|
* `x` Integer
|
||||||
* `y` Integer
|
* `y` Integer
|
||||||
* `width` Integer
|
* `width` Integer
|
||||||
|
@ -71,9 +68,7 @@ labeled as such.
|
||||||
|
|
||||||
Emitted when the tray icon is clicked.
|
Emitted when the tray icon is clicked.
|
||||||
|
|
||||||
**Note:** The `bounds` payload is only implemented on macOS and Windows.
|
#### Event: 'right-click' _macOS_ _Windows_
|
||||||
|
|
||||||
### Event: 'right-click' _macOS_ _Windows_
|
|
||||||
|
|
||||||
* `event` Event
|
* `event` Event
|
||||||
* `altKey` Boolean
|
* `altKey` Boolean
|
||||||
|
@ -88,7 +83,7 @@ Emitted when the tray icon is clicked.
|
||||||
|
|
||||||
Emitted when the tray icon is right clicked.
|
Emitted when the tray icon is right clicked.
|
||||||
|
|
||||||
### Event: 'double-click' _macOS_ _Windows_
|
#### Event: 'double-click' _macOS_ _Windows_
|
||||||
|
|
||||||
* `event` Event
|
* `event` Event
|
||||||
* `altKey` Boolean
|
* `altKey` Boolean
|
||||||
|
@ -103,85 +98,82 @@ Emitted when the tray icon is right clicked.
|
||||||
|
|
||||||
Emitted when the tray icon is double clicked.
|
Emitted when the tray icon is double clicked.
|
||||||
|
|
||||||
### Event: 'balloon-show' _Windows_
|
#### Event: 'balloon-show' _Windows_
|
||||||
|
|
||||||
Emitted when the tray balloon shows.
|
Emitted when the tray balloon shows.
|
||||||
|
|
||||||
### Event: 'balloon-click' _Windows_
|
#### Event: 'balloon-click' _Windows_
|
||||||
|
|
||||||
Emitted when the tray balloon is clicked.
|
Emitted when the tray balloon is clicked.
|
||||||
|
|
||||||
### Event: 'balloon-closed' _Windows_
|
#### Event: 'balloon-closed' _Windows_
|
||||||
|
|
||||||
Emitted when the tray balloon is closed because of timeout or user manually
|
Emitted when the tray balloon is closed because of timeout or user manually
|
||||||
closes it.
|
closes it.
|
||||||
|
|
||||||
### Event: 'drop' _macOS_
|
#### Event: 'drop' _macOS_
|
||||||
|
|
||||||
Emitted when any dragged items are dropped on the tray icon.
|
Emitted when any dragged items are dropped on the tray icon.
|
||||||
|
|
||||||
### Event: 'drop-files' _macOS_
|
#### Event: 'drop-files' _macOS_
|
||||||
|
|
||||||
* `event`
|
* `event`
|
||||||
* `files` Array - the file path of dropped files.
|
* `files` Array - the file path of dropped files.
|
||||||
|
|
||||||
Emitted when dragged files are dropped in the tray icon.
|
Emitted when dragged files are dropped in the tray icon.
|
||||||
|
|
||||||
### Event: 'drag-enter' _macOS_
|
#### Event: 'drag-enter' _macOS_
|
||||||
|
|
||||||
Emitted when a drag operation enters the tray icon.
|
Emitted when a drag operation enters the tray icon.
|
||||||
|
|
||||||
### Event: 'drag-leave' _macOS_
|
#### Event: 'drag-leave' _macOS_
|
||||||
|
|
||||||
Emitted when a drag operation exits the tray icon.
|
Emitted when a drag operation exits the tray icon.
|
||||||
|
|
||||||
### Event: 'drag-end' _macOS_
|
#### Event: 'drag-end' _macOS_
|
||||||
|
|
||||||
Emitted when a drag operation ends on the tray or ends at another location.
|
Emitted when a drag operation ends on the tray or ends at another location.
|
||||||
|
|
||||||
## Methods
|
### Instance Methods
|
||||||
|
|
||||||
The `Tray` module has the following methods:
|
The `Tray` class has the following methods:
|
||||||
|
|
||||||
**Note:** Some methods are only available on specific operating systems and are
|
#### `tray.destroy()`
|
||||||
labeled as such.
|
|
||||||
|
|
||||||
### `Tray.destroy()`
|
|
||||||
|
|
||||||
Destroys the tray icon immediately.
|
Destroys the tray icon immediately.
|
||||||
|
|
||||||
### `Tray.setImage(image)`
|
#### `tray.setImage(image)`
|
||||||
|
|
||||||
* `image` [NativeImage](native-image.md)
|
* `image` [NativeImage](native-image.md)
|
||||||
|
|
||||||
Sets the `image` associated with this tray icon.
|
Sets the `image` associated with this tray icon.
|
||||||
|
|
||||||
### `Tray.setPressedImage(image)` _macOS_
|
#### `tray.setPressedImage(image)` _macOS_
|
||||||
|
|
||||||
* `image` [NativeImage](native-image.md)
|
* `image` [NativeImage](native-image.md)
|
||||||
|
|
||||||
Sets the `image` associated with this tray icon when pressed on macOS.
|
Sets the `image` associated with this tray icon when pressed on macOS.
|
||||||
|
|
||||||
### `Tray.setToolTip(toolTip)`
|
#### `tray.setToolTip(toolTip)`
|
||||||
|
|
||||||
* `toolTip` String
|
* `toolTip` String
|
||||||
|
|
||||||
Sets the hover text for this tray icon.
|
Sets the hover text for this tray icon.
|
||||||
|
|
||||||
### `Tray.setTitle(title)` _macOS_
|
#### `tray.setTitle(title)` _macOS_
|
||||||
|
|
||||||
* `title` String
|
* `title` String
|
||||||
|
|
||||||
Sets the title displayed aside of the tray icon in the status bar.
|
Sets the title displayed aside of the tray icon in the status bar.
|
||||||
|
|
||||||
### `Tray.setHighlightMode(highlight)` _macOS_
|
#### `tray.setHighlightMode(highlight)` _macOS_
|
||||||
|
|
||||||
* `highlight` Boolean
|
* `highlight` Boolean
|
||||||
|
|
||||||
Sets whether the tray icon's background becomes highlighted (in blue)
|
Sets whether the tray icon's background becomes highlighted (in blue)
|
||||||
when the tray icon is clicked. Defaults to true.
|
when the tray icon is clicked. Defaults to true.
|
||||||
|
|
||||||
### `Tray.displayBalloon(options)` _Windows_
|
#### `tray.displayBalloon(options)` _Windows_
|
||||||
|
|
||||||
* `options` Object
|
* `options` Object
|
||||||
* `icon` [NativeImage](native-image.md)
|
* `icon` [NativeImage](native-image.md)
|
||||||
|
@ -190,7 +182,7 @@ when the tray icon is clicked. Defaults to true.
|
||||||
|
|
||||||
Displays a tray balloon.
|
Displays a tray balloon.
|
||||||
|
|
||||||
### `Tray.popUpContextMenu([menu, position])` _macOS_ _Windows_
|
#### `tray.popUpContextMenu([menu, position])` _macOS_ _Windows_
|
||||||
|
|
||||||
* `menu` Menu (optional)
|
* `menu` Menu (optional)
|
||||||
* `position` Object (optional) - The pop up position.
|
* `position` Object (optional) - The pop up position.
|
||||||
|
@ -202,13 +194,13 @@ be shown instead of the tray icon's context menu.
|
||||||
|
|
||||||
The `position` is only available on Windows, and it is (0, 0) by default.
|
The `position` is only available on Windows, and it is (0, 0) by default.
|
||||||
|
|
||||||
### `Tray.setContextMenu(menu)`
|
#### `tray.setContextMenu(menu)`
|
||||||
|
|
||||||
* `menu` Menu
|
* `menu` Menu
|
||||||
|
|
||||||
Sets the context menu for this icon.
|
Sets the context menu for this icon.
|
||||||
|
|
||||||
### `Tray.getBounds()` _macOS_ _Windows_
|
#### `tray.getBounds()` _macOS_ _Windows_
|
||||||
|
|
||||||
Returns the `bounds` of this tray icon as `Object`.
|
Returns the `bounds` of this tray icon as `Object`.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue