electron-menubar 1.0.2 → 10.1.1

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 CHANGED
@@ -1,21 +1,26 @@
1
- MIT License
1
+ BSD 2-Clause License
2
2
 
3
- Copyright (c) 2017 Henrique Dias
3
+ Copyright (c) 2015-2019, Max Ogden
4
+ Copyright (c) 2026-present, Gitify
5
+ All rights reserved.
4
6
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
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
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
10
+ * Redistributions of source code must retain the above copyright notice, this
11
+ list of conditions and the following disclaimer.
14
12
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
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,183 @@
1
- # electron-menubar
1
+ [![CI Workflow][ci-workflow-badge]][github-actions] [![Release Workflow][release-workflow-badge]][github-actions] [![Renovate enabled][renovate-badge]][renovate] [![Contributors][contributors-badge]][github] [![Downloads - Year][downloads-badge]][npmjs] [![OSS License][license-badge]][license] [![NPM Latest Version][npmjs-version-badge]][npmjs] [![Latest Release][github-release-badge]][github-releases] ![Libraries.io dependency status for GitHub repo][librariesio-badge] ![npm minzipped bundle size][size-minzip-badge] ![npm minified bundle size][size-minified-badge]
2
2
 
3
- [![npm](https://img.shields.io/npm/v/electron-menubar.svg?style=flat-square)](https://www.npmjs.com/package/electron-menubar)
4
- [![Travis](https://img.shields.io/travis/hacdias/electron-menubar.svg?style=flat-square)](https://travis-ci.org/hacdias/electron-menubar)
3
+ <br />
5
4
 
6
- This lets you create a menubar very easily with Electron.
5
+ <h1 align="center">➖ electron-menubar</h1>
6
+ <h5 align="center"><i>formerly known as menubar</i></h5>
7
+ <h4 align="center">High level way to create menubar desktop applications with Electron.</h4>
7
8
 
8
- ## Install
9
+ <br />
9
10
 
11
+ ## Features
12
+
13
+ - ⚡️ Quick start for creating menubar applications using Electron.
14
+ - 🚀 Zero runtime dependencies.
15
+ - 💻 Works on macOS, Windows and *most* Linux distributions. See [tested platforms][platforms].
16
+
17
+ | <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" /> |
18
+ | :-----------------------------------------------------------: | :--------------------------------------------------------: | :------------------------------------------------------: |
19
+ | macOS | Windows 10 | Ubuntu |
20
+
21
+ > [!NOTE]
22
+ > On native Wayland, the desktop compositor controls window placement, so the popover cannot be anchored to the tray icon and is positioned by the desktop (usually centered). This is a Wayland limitation, not something the library can override. Tray-relative positioning works under X11/XWayland. See [window positioning on Linux][platforms] for the detail and a workaround.
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pnpm add electron-menubar
10
28
  ```
11
- npm install --save electron-menubar
29
+
30
+ ## Usage
31
+
32
+ Starting with your own new project, run these commands:
33
+
34
+ ```bash
35
+ $ pnpm add electron-menubar
36
+ $ touch myApp.js
37
+ $ touch index.html
12
38
  ```
13
39
 
14
- ## Documentation
40
+ Fill `index.html` with some HTML, and `myApp.js` like this:
41
+
42
+ ```javascript
43
+ const { menubar } = require('electron-menubar');
44
+
45
+ const mb = menubar();
46
+
47
+ mb.on('ready', () => {
48
+ console.log('app is ready');
49
+ // your app code here
50
+ });
51
+ ```
52
+
53
+ Then use `electron` to run the app:
54
+
55
+ ```bash
56
+ $ electron myApp.js
57
+ ```
58
+
59
+ ## Examples
60
+
61
+ See [`examples`][examples] folder for a selection of working examples.
62
+
63
+
64
+ ## API Documentation
15
65
 
16
- ### Class `Menubar`
66
+ ### `Menubar` Class
17
67
 
18
- #### `new Menubar([options])`
68
+ The return value of `menubar()` is a `Menubar` class instance, which exposes the following properties and methods.
69
+
70
+ #### Properties
71
+
72
+ | Property | Description |
73
+ | --- | --- |
74
+ | `app` | The [Electron App][electron-docs-app] instance. |
75
+ | `window` | The [Electron Browser Window][electron-docs-browserwindow] instance. |
76
+ | `tray` | The [Electron Tray][electron-docs-tray] instance. |
77
+ | `positioner` | The `Positioner` instance used to compute the window's on-screen coordinates. |
19
78
 
20
- - `options` Object (optional)
21
- - `icon` String. The tray's icon. Defaults to `app.getAppPath()/icon.png`.
22
- - `index` String. The index file for the window. Defaults to `app.getAppPath()/index.html`.
23
- - `preloadWindow` Boolean. Tells if the window must be preloaded. Defaults to `false`.
24
- - `showDockIcon` Boolean. Default is `false`.
25
- - `showOnRightClick` Boolean. Default is `false`.
26
- - `showOnAllWorkspaces` Boolean. Default is `false`.
27
- - `tooltip` String. The tray's tooltip.
28
-
29
79
  #### Methods
30
80
 
31
- - `menubar.isReady()` tells if the menubar is already ready.
32
- - `menubar.hide()` hides the window.
33
- - `menubar.show()` shows the window.
34
-
35
- #### Events
36
-
37
- - `ready`
38
- - `create-window`
39
- - `after-create-window`
40
- - `hide`
41
- - `after-hide`
42
- - `show`
43
- - `after-show`
44
-
45
- ### Class `Positioner`
46
-
47
- - `Positioner.getTaskbarPosition()` returns the position of the taskbar: `top|right|bottom|left`.
48
- - `Positioner.position(window, trayBounds, [alignment])` positions the window in a certain place.
49
- - `window` BrowserWindow. Is the window to position.
50
- - `trayBounds` Rectangle. Are the bounds from the Electron.Tray.
51
- - `alignment` Object. Are the positions to position the window.
52
- - `alignment.x` String. Defaults to `center`. Can be `left|center|right`.
53
- - `alignment.y` String. Defaults to `center`. Can be `up|center|down`.
54
- - `Positioner.calculate(windowBounds, trayBounds, [alignment])` only calculates the position and returns an Object `{x: n, y: k}`.
55
- - `windowBounds` Rectangle. A BrowserWindow bounds.
56
- - `trayBounds` Rectangle. Are the bounds from the Electron.Tray.
57
- - `alignment` Object. Are the positions to position the window.
58
- - `alignment.x` String. Defaults to `center`. Can be `left|center|right`.
59
- - `alignment.y` String. Defaults to `center`. Can be `up|center|down`.
60
-
61
- ## Credits
62
-
63
- The code of this project is mainly based on [`menubar`](https://github.com/maxogden/menubar) and [`electron-traywindow-positioner`](https://github.com/pixtron/electron-traywindow-positioner) with some improvements and cleaning.
81
+ | Method | Description |
82
+ | --- | --- |
83
+ | `setOption(option, value)` | Change an option after menubar is created. |
84
+ | `getOption(option)` | Get a menubar option. |
85
+ | `showWindow()` | Show the menubar window. |
86
+ | `hideWindow()` | Hide the menubar window. |
87
+ | `toggleWindow()` | Show the window if hidden, hide it if visible. |
88
+ | `recenterOnTray()` | Re-center the window over the tray icon. |
89
+ | `setContextMenu(menu)` | Replace the tray context menu (auto-re-publishes on Linux). |
90
+ | `setGlobalShortcut(accelerator)` | Register a global accelerator that toggles the window. Returns `false` on registration failure. |
91
+ | `destroy()` | Tear down the menubar instance. |
92
+ | `isDestroyed()` | Whether the menubar is currently destroyed. |
93
+
94
+ ### `menubar()` Options
95
+
96
+ You can pass an optional options object into the `menubar({ ... })` function:
97
+
98
+ | Option | Default | Description |
99
+ | --- | --- | --- |
100
+ | `dir` | `process.cwd()` | The app source directory. |
101
+ | `index` | `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. |
102
+ | `browserWindow` | | BrowserWindow options passed to the BrowserWindow constructor, see [Electron docs][electron-docs-browserwindow-options]. <details><summary>Useful fields</summary>• `x` (default `undefined`) - the x position of the window<br>• `y` (default `undefined`) - the y position of the window<br>• `width` (default `400`) - window width<br>• `height` (default `400`) - window height<br>• `alwaysOnTop` (default `false`) - if `true`, the window will not hide on blur</details> |
103
+ | `icon` | `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. |
104
+ | `tooltip` | empty | Menubar tray icon tooltip text. |
105
+ | `tray` | created on-the-fly | An Electron `Tray` instance. If provided, `opts.icon` will be ignored. |
106
+ | `preloadWindow` | `false` | Create [BrowserWindow][electron-docs-browserwindow-options] instance before it is used, increasing resource usage but making the click on the menubar load faster. |
107
+ | `loadUrlOptions` | `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][electron-docs-browserwindow-loadurl]. |
108
+ | `showOnAllWorkspaces` | `true` | Makes the window available on all macOS workspaces. |
109
+ | `windowPosition` | `trayCenter` (macOS/Linux), `trayBottomCenter` (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`. |
110
+ | `showDockIcon` | `false` | Configure the visibility of the application dock icon. |
111
+ | `trigger` | `'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. |
112
+ | `showOnRightClick` | `false` | **Deprecated**, use `trigger: 'right-click'` instead. Show the window on `right-click` event instead of regular `click`. |
113
+ | `contextMenu` | | An Electron `Menu` to attach to the tray icon. <details><summary>Platform behavior</summary>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.</details> |
114
+ | `hideOnClose` | `false` | Hide the window on `close` instead of destroying it, so the next tray click re-uses the same `BrowserWindow`. <details><summary>Platform notes</summary>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.</details> |
115
+ | `escapeToHide` | `false` | Hide the menubar window when the user presses `Escape` while it has focus. |
116
+ | `ignoreDoubleClickEvents` | `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. |
117
+ | `globalShortcut` | | An [Accelerator][electron-docs-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. |
118
+
119
+ ### Events
120
+
121
+ The `Menubar` class is an event emitter:
122
+
123
+ | Event | Description |
124
+ | --- | --- |
125
+ | `ready` | When `menubar`'s tray icon has been created and initialized, i.e. when `menubar` is ready to be used. Note: this is different from the Electron app's `ready` event, which happens much earlier in the process. |
126
+ | `create-window` | The line before `new BrowserWindow()` is called. |
127
+ | `before-load` | After create window, before `loadUrl` (can be used for `require("@electron/remote/main").enable(webContents)`). |
128
+ | `after-create-window` | The line after all window init code is done and the url was loaded. |
129
+ | `show` | The line before `window.show()` is called. |
130
+ | `after-show` | The line after `window.show()` is called. |
131
+ | `hide` | The line before `window.hide()` is called (on window blur). |
132
+ | `after-hide` | The line after `window.hide()` is called. |
133
+ | `after-close` | After the `.window` (BrowserWindow) property has been deleted. |
134
+ | `focus-lost` | Emitted if the always-on-top option is set and the user clicks away. |
135
+
136
+ ## Tips
137
+
138
+ - 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()`
139
+ - Use `mb.on('focus-lost')` if you would like to perform some operation when using the option `browserWindow.alwaysOnTop: true`
140
+ - To restore focus of previous window after menubar hide, use `mb.on('after-hide', () => { mb.app.hide() } )` or similar
141
+ - 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][examples-native] for more information.
142
+ - 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');`
143
+
144
+ ## Acknowledgements
145
+
146
+ Originally created by [Max][github-upstream-creator] — hard-forked from [max-mapper/menubar][github-upstream-repo].
147
+
148
+
149
+ <!-- LINK LABELS -->
150
+
151
+ [github]: https://github.com/gitify-app/electron-menubar
152
+ [github-actions]: https://github.com/gitify-app/electron-menubar/actions
153
+ [github-issues]: https://github.com/gitify-app/electron-menubar/issues
154
+ [github-releases]: https://github.com/gitify-app/gitify/electron-menubar/latest
155
+ [github-upstream-creator]: https://github.com/max-mapper
156
+ [github-upstream-repo]: https://github.com/max-mapper/menubar
157
+
158
+ [examples]: examples
159
+ [examples-native]: examples/native-menu
160
+
161
+ [platforms]: PLATFORMS
162
+
163
+ [electron-docs-accelerator]: https://electronjs.org/docs/api/accelerator
164
+ [electron-docs-app]:https://electronjs.org/docs/api/app
165
+ [electron-docs-browserwindow]: https://electronjs.org/docs/api/browser-window
166
+ [electron-docs-browserwindow-options]: https://electronjs.org/docs/api/browser-window#new-browserwindowoptions
167
+ [electron-docs-browserwindow-loadurl]: https://electronjs.org/docs/api/browser-window#winloadurlurl-options
168
+ [electron-docs-tray]: https://electronjs.org/docs/api/tray
169
+
170
+ [ci-workflow-badge]: https://img.shields.io/github/actions/workflow/status/gitify-app/electron-menubar/test.yml?logo=github&label=CI
171
+ [release-workflow-badge]: https://img.shields.io/github/actions/workflow/status/gitify-app/electron-menubar/release.yml?logo=github&label=Release
172
+ [downloads-badge]: https://img.shields.io/npm/dy/electron-menubar?logo=npm
173
+ [contributors-badge]: https://img.shields.io/github/contributors/gitify-app/electron-menubar?logo=github
174
+ [librariesio-badge]: https://img.shields.io/librariesio/github/gitify-app/electron-menubar?logo=libraries.io&logoColor=white
175
+ [license]: LICENSE
176
+ [license-badge]: https://img.shields.io/github/license/gitify-app/electron-menubar?logo=github
177
+ [github-release-badge]: https://img.shields.io/github/v/release/gitify-app/electron-menubar?logo=github
178
+ [npmjs]: https://www.npmjs.com/package/electron-menubar
179
+ [npmjs-version-badge]: https://img.shields.io/npm/v/electron-menubar?logo=npm
180
+ [renovate]: https://github.com/gitify-app/gitify/issues/576
181
+ [renovate-badge]: https://img.shields.io/badge/renovate-enabled-brightgreen.svg?logo=renovate&logoColor=white
182
+ [size-minzip-badge]: https://img.shields.io/bundlephobia/minzip/electron-menubar.svg?logo=npm
183
+ [size-minified-badge]: https://img.shields.io/bundlephobia/min/electron-menubar.svg?logo=npm
Binary file
Binary file