electron-menubar 1.0.2 → 10.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -17
- package/README.md +125 -53
- package/assets/IconTemplate.png +0 -0
- package/assets/IconTemplate@2x.png +0 -0
- package/lib/index.cjs +554 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +329 -0
- package/lib/index.d.mts +329 -0
- package/lib/index.mjs +525 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +66 -26
- package/.travis.yml +0 -4
- package/index.js +0 -7
- package/menubar.js +0 -179
- package/positioner.js +0 -211
package/LICENSE
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
BSD 2-Clause License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2015-2019, Max Ogden
|
|
4
|
+
Copyright (c) 2026-present, Gitify
|
|
5
|
+
All rights reserved.
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
|
8
|
+
modification, are permitted provided that the following conditions are met:
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
11
|
+
list of conditions and the following disclaimer.
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
and/or other materials provided with the distribution.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
18
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
21
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
22
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
23
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
24
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
25
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,63 +1,135 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
|
+
[](https://www.npmjs.com/package/electron-menubar)
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
[](https://travis-ci.org/hacdias/electron-menubar)
|
|
7
|
+
<br /><br /><br />
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
<h1 align="center">➖ Menubar</h1>
|
|
10
|
+
<h4 align="center">High level way to create menubar desktop applications with Electron.</h4>
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
<br /><br /><br />
|
|
9
13
|
|
|
14
|
+
This module provides boilerplate for setting up a menubar application using Electron. All you have to do is point it at your `index.html` and `menubar` will handle the rest.
|
|
15
|
+
|
|
16
|
+
✅ Zero runtime dependencies.
|
|
17
|
+
|
|
18
|
+
✅ Works on macOS, Windows and most Linuxes. See [tested platforms](./PLATFORMS.md).
|
|
19
|
+
|
|
20
|
+
✅ 💥 [**4.9kB minified + gzipped**](https://bundlephobia.com/result?p=electron-menubar) 💥
|
|
21
|
+
|
|
22
|
+
| <img src="assets/screenshot-macos-dark.png" height="250px" /> | <img src="assets/screenshot-windows.png" height="250px" /> | <img src="assets/screenshot-linux.png" height="250px" /> |
|
|
23
|
+
| :-----------------------------------------------------------: | :--------------------------------------------------------: | :------------------------------------------------------: |
|
|
24
|
+
| macOS Mojave 10.14 | Windows 10 | Ubuntu 18.04 |
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
bun add electron-menubar
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
Starting with your own new project, run these commands:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
$ bun add electron-menubar
|
|
38
|
+
$ touch myApp.js
|
|
39
|
+
$ touch index.html
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Fill `index.html` with some HTML, and `myApp.js` like this:
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
const { menubar } = require('electron-menubar');
|
|
46
|
+
|
|
47
|
+
const mb = menubar();
|
|
48
|
+
|
|
49
|
+
mb.on('ready', () => {
|
|
50
|
+
console.log('app is ready');
|
|
51
|
+
// your app code here
|
|
52
|
+
});
|
|
10
53
|
```
|
|
11
|
-
|
|
54
|
+
|
|
55
|
+
Then use `electron` to run the app:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
$ electron myApp.js
|
|
12
59
|
```
|
|
13
60
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- `
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- `
|
|
32
|
-
- `
|
|
33
|
-
- `
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
- `
|
|
40
|
-
- `
|
|
41
|
-
- `
|
|
42
|
-
- `
|
|
43
|
-
- `
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
- `
|
|
48
|
-
- `
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
- `
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
Alternatively, see [`examples/hello-world`](/examples/hello-world) folder for a simple working example.
|
|
62
|
+
|
|
63
|
+
## `Menubar` Class
|
|
64
|
+
|
|
65
|
+
The return value of `menubar()` is a `Menubar` class instance, which has these properties:
|
|
66
|
+
|
|
67
|
+
- `app`: the [Electron App](https://electronjs.org/docs/api/app) instance,
|
|
68
|
+
- `window`: the [Electron Browser Window](https://electronjs.org/docs/api/browser-window) instance,
|
|
69
|
+
- `tray`: the [Electron Tray](https://electronjs.org/docs/api/tray) instance,
|
|
70
|
+
- `positioner`: the `Positioner` instance used to compute the window's on-screen coordinates,
|
|
71
|
+
- `setOption(option, value)`: change an option after menubar is created,
|
|
72
|
+
- `getOption(option)`: get an menubar option,
|
|
73
|
+
- `showWindow()`: show the menubar window,
|
|
74
|
+
- `hideWindow()`: hide the menubar window,
|
|
75
|
+
- `toggleWindow()`: show the window if hidden, hide it if visible,
|
|
76
|
+
- `recenterOnTray()`: re-center the window over the tray icon,
|
|
77
|
+
- `setContextMenu(menu)`: replace the tray context menu (auto-re-publishes on Linux),
|
|
78
|
+
- `setGlobalShortcut(accelerator)`: register a global accelerator that toggles the window — returns `false` on registration failure,
|
|
79
|
+
- `destroy()`: tear down the menubar instance,
|
|
80
|
+
- `isDestroyed()`: whether the menubar is currently destroyed.
|
|
81
|
+
|
|
82
|
+
## `menubar()` Options
|
|
83
|
+
|
|
84
|
+
You can pass an optional options object into the `menubar({ ... })` function:
|
|
85
|
+
|
|
86
|
+
- `dir` (default `process.cwd()`) - the app source directory
|
|
87
|
+
- `index` (default `file:// + opts.dir + index.html`) - The URL to load the menubar's browserWindow with. The url can be a remote address (e.g. `http://`) or a path to a local HTML file using the `file://` protocol.
|
|
88
|
+
- `browserWindow` - BrowserWindow options to be passed to the BrowserWindow constructor, see [Electron docs](https://electronjs.org/docs/api/browser-window#new-browserwindowoptions). Some interesting fields to passed down are:
|
|
89
|
+
- `x` (default `undefined`) - the x position of the window
|
|
90
|
+
- `y` (default `undefined`) - the y position of the window
|
|
91
|
+
- `width` (default 400) - window width
|
|
92
|
+
- `height` (default 400) - window height
|
|
93
|
+
- `alwaysOnTop` (default false) - if true, the window will not hide on blur
|
|
94
|
+
- `icon` (default `opts.dir + IconTemplate.png`) - the png icon to use for the menubar. A good size to start with is 20x20. To support retina, supply a 2x sized image (e.g. 40x40) with `@2x` added to the end of the name, so `icon.png` and `icon@2x.png` and Electron will automatically use your `@2x` version on retina screens.
|
|
95
|
+
- `tooltip` (default empty) - menubar tray icon tooltip text
|
|
96
|
+
- `tray` (default created on-the-fly) - an electron `Tray` instance. if provided `opts.icon` will be ignored
|
|
97
|
+
- `preloadWindow` (default false) - Create [BrowserWindow](https://electronjs.org/docs/api/browser-window#new-browserwindowoptions) instance before it is used -- increasing resource usage, but making the click on the menubar load faster.
|
|
98
|
+
- `loadUrlOptions` - (default undefined) The options passed when loading the index URL in the menubar's browserWindow. Everything browserWindow.loadURL supports is supported; this object is simply passed onto [browserWindow.loadURL](https://electronjs.org/docs/api/browser-window#winloadurlurl-options)
|
|
99
|
+
- `showOnAllWorkspaces` (default true) - Makes the window available on all OS X workspaces.
|
|
100
|
+
- `windowPosition` (default `trayCenter` on macOS/Linux, `trayBottomCenter` on Windows) - Sets the window position (`browserWindow.x` / `browserWindow.y` will still override this). Valid values: `trayLeft`, `trayBottomLeft`, `trayRight`, `trayBottomRight`, `trayCenter`, `trayBottomCenter`, `topLeft`, `topRight`, `bottomLeft`, `bottomRight`, `topCenter`, `bottomCenter`, `leftCenter`, `rightCenter`, `center`.
|
|
101
|
+
- `showDockIcon` (default false) - Configure the visibility of the application dock icon.
|
|
102
|
+
- `trigger` (default `'click'`) - Tray event that toggles the menubar window. One of `'click'`, `'right-click'`, or `'none'`. Use `'none'` to disable automatic toggling — useful when a single tray icon serves multiple windows. The window can still be shown by calling `mb.showWindow()` directly.
|
|
103
|
+
- `showOnRightClick` (default false) - **Deprecated**, use `trigger: 'right-click'` instead. Show the window on 'right-click' event instead of regular 'click'.
|
|
104
|
+
- `contextMenu` - An Electron `Menu` to attach to the tray icon. On Linux it is bound via `tray.setContextMenu` (required by libappindicator / StatusNotifierItem) and re-published on every show/hide to defeat the indicator's menu cache. On macOS and Windows it pops up on right-click via `tray.popUpContextMenu`, so left-click continues to toggle the window. Combine with `trigger: 'none'` if you want right-click to be the only interaction.
|
|
105
|
+
- `hideOnClose` (default false) - Hide the window on `close` instead of destroying it, so the next tray click re-uses the same `BrowserWindow`. On Linux/Wayland the hide is deferred via `setImmediate` to work around a compositor bug that leaves frameless surfaces in a half-closed state when hidden synchronously from the `close` handler. The library tracks the app's `before-quit` event internally, so real quits go through unimpeded.
|
|
106
|
+
- `escapeToHide` (default false) - Hide the menubar window when the user presses `Escape` while it has focus.
|
|
107
|
+
- `ignoreDoubleClickEvents` (default true, macOS only) - Calls `tray.setIgnoreDoubleClickEvents(true)` so an accidental double-click doesn't race the close-on-blur handler and flicker the tray icon. Pass `false` to opt out. No-op on Linux/Windows.
|
|
108
|
+
- `globalShortcut` - An [Accelerator](https://electronjs.org/docs/api/accelerator) string registered as a global keyboard shortcut that toggles the menubar window. Unregistered automatically on `destroy()`. Use `mb.setGlobalShortcut(accelerator)` to change or clear it at runtime.
|
|
109
|
+
|
|
110
|
+
## Events
|
|
111
|
+
|
|
112
|
+
The `Menubar` class is an event emitter:
|
|
113
|
+
|
|
114
|
+
- `ready` - when `menubar`'s tray icon has been created and initialized, i.e. when `menubar` is ready to be used. Note: this is different than Electron app's `ready` event, which happens much earlier in the process
|
|
115
|
+
- `create-window` - the line before `new BrowserWindow()` is called
|
|
116
|
+
- `before-load` - after create window, before loadUrl (can be used for `require("@electron/remote/main").enable(webContents)`)
|
|
117
|
+
- `after-create-window` - the line after all window init code is done and url was loaded
|
|
118
|
+
- `show` - the line before `window.show()` is called
|
|
119
|
+
- `after-show` - the line after `window.show()` is called
|
|
120
|
+
- `hide` - the line before `window.hide()` is called (on window blur)
|
|
121
|
+
- `after-hide` - the line after `window.hide()` is called
|
|
122
|
+
- `after-close` - after the `.window` (BrowserWindow) property has been deleted
|
|
123
|
+
- `focus-lost` - emitted if always-on-top option is set and the user clicks away
|
|
124
|
+
|
|
125
|
+
## Tips
|
|
126
|
+
|
|
127
|
+
- Use `mb.on('after-create-window', callback)` to run things after your app has loaded. For example you could run `mb.window.openDevTools()` to open the developer tools for debugging, or load a different URL with `mb.window.loadURL()`
|
|
128
|
+
- Use `mb.on('focus-lost')` if you would like to perform some operation when using the option `browserWindow.alwaysOnTop: true`
|
|
129
|
+
- To restore focus of previous window after menubar hide, use `mb.on('after-hide', () => { mb.app.hide() } )` or similar
|
|
130
|
+
- To attach a native context menu, pass it as `contextMenu`: `menubar({ contextMenu })`. The library wires it via `setContextMenu` on Linux and `popUpContextMenu` on right-click on macOS/Windows so left-click still toggles the window. See [this example](https://github.com/gitify-app/menubar/tree/main/examples/native-menu) for more information.
|
|
131
|
+
- To avoid a flash when opening your menubar app, you can disable backgrounding the app using the following: `mb.app.commandLine.appendSwitch('disable-backgrounding-occluded-windows', 'true');`
|
|
60
132
|
|
|
61
133
|
## Credits
|
|
62
134
|
|
|
63
|
-
|
|
135
|
+
Originally created by [Max Ogden](https://github.com/maxogden) — forked from [maxogden/menubar](https://github.com/maxogden/menubar).
|
|
Binary file
|
|
Binary file
|