electron-menubar 1.0.1 → 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 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,135 @@
1
- # electron-menubar
1
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/gitify-app/menubar/test.yml)
2
+ [![npm](https://img.shields.io/npm/v/electron-menubar.svg)](https://www.npmjs.com/package/electron-menubar)
3
+ ![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/gitify-app/menubar)
4
+ ![npm bundle size](https://img.shields.io/bundlephobia/minzip/electron-menubar.svg)
5
+ ![npm bundle size](https://img.shields.io/bundlephobia/min/electron-menubar.svg)
2
6
 
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)
7
+ <br /><br /><br />
5
8
 
6
- This lets you create a menubar very easily with Electron.
9
+ <h1 align="center">➖ Menubar</h1>
10
+ <h4 align="center">High level way to create menubar desktop applications with Electron.</h4>
7
11
 
8
- ## Install
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
- npm install --save electron-menubar
54
+
55
+ Then use `electron` to run the app:
56
+
57
+ ```bash
58
+ $ electron myApp.js
12
59
  ```
13
60
 
14
- ## Documentation
15
-
16
- ### Class `Menubar`
17
-
18
- #### `new Menubar([options])`
19
-
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
- #### Methods
30
-
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`.
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
- 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.
135
+ Originally created by [Max Ogden](https://github.com/maxogden) — forked from [maxogden/menubar](https://github.com/maxogden/menubar).
Binary file
Binary file