-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
browserWindow
field in options, deprecate height
, `widt…
…h`, `x`, `y`, `alwaysOnTop` in favor of `browserWindow` (#18) * Allow browserWindow in options * Make cleanOptions work well * Update readme * Fix lint * Update readme
- Loading branch information
1 parent
755266c
commit 0b2d897
Showing
5 changed files
with
234 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ See the [`example/`](/example) folder for a working example. | |
|
||
The return value of `mb` is a `Menubar` class instance, which subclasses `EventEmitter` and has these additional properties: | ||
|
||
```javascript | ||
``` | ||
{ | ||
app: the electron require('app') instance, | ||
window: the electron require('browser-window') instance, | ||
|
@@ -70,19 +70,25 @@ You can pass an optional options object into the menubar constructor: | |
|
||
- `dir` (default `process.cwd()`) - the app source directory | ||
- `index` (default `file:// + opts.dir + index.html`) - the html to load for the pop up window | ||
- `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: | ||
- `x` (default `undefined`) - the x position of the window | ||
- `y` (default `undefined`) - the y position of the window | ||
- `width` (default 400) - window width | ||
- `height` (default 400) - window height | ||
- `alwaysOnTop` (default false) - if true, the window will not hide on blur | ||
- `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 `[email protected]` and Electron will automatically use your `@2x` version on retina screens. | ||
- `tooltip` (default empty) - menubar tray icon tooltip text | ||
- `tray` (default created on-the-fly) - an electron `Tray` instance. if provided `opts.icon` will be ignored | ||
- `preloadWindow` (default false) - Create [BrowserWindow](https://github.com/atom/electron/blob/master/docs/api/browser-window.md) instance before it is used -- increasing resource usage, but making the click on the menubar load faster. | ||
- `width` (default 400) - window width | ||
- `height` (default 400) - window height | ||
- `x` (default null) - the x position of the window | ||
- `y` (default null) - the y position of the window | ||
- `alwaysOnTop` (default false) - if true, the window will not hide on blur | ||
- `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. | ||
- `showOnAllWorkspaces` (default true) - Makes the window available on all OS X workspaces. | ||
- `windowPosition` (default trayCenter and trayBottomCenter on Windows) - Sets the window position (x and y will still override this), check [positioner docs](https://github.com/jenslind/electron-positioner#docs) for valid values. | ||
- `showDockIcon` (default false) - Configure the visibility of the application dock icon. | ||
- `showOnRightClick` (default false) - Show the window on 'right-click' event instead of regular 'click' | ||
- `width` _deprecated_ - Please use `options.browserWindow.width`, see [Electron docs](https://electronjs.org/docs/api/browser-window#new-browserwindowoptions) for more info on this field. | ||
- `height` _deprecated_ - Please use `options.browserWindow.height`, see [Electron docs](https://electronjs.org/docs/api/browser-window#new-browserwindowoptions) for more info on this field. | ||
- `x` _deprecated_ - Please use `options.browserWindow.x`, see [Electron docs](https://electronjs.org/docs/api/browser-window#new-browserwindowoptions) for more info on this field. | ||
- `y` _deprecated_ - Please use `options.browserWindow.y`, see [Electron docs](https://electronjs.org/docs/api/browser-window#new-browserwindowoptions) for more info on this field. | ||
- `alwaysOnTop` _deprecated_ - Please use `options.browserWindow.alwaysOnTop`, see [Electron docs](https://electronjs.org/docs/api/browser-window#new-browserwindowoptions) for more info on this field. | ||
|
||
## Events | ||
|
||
|
@@ -101,5 +107,5 @@ The return value of the menubar constructor is an event emitter: | |
## Tips | ||
|
||
- 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()` | ||
- Use `mb.on('focus-lost')` if you would like to perform some operation when using the option `alwaysOnTop:true` | ||
- Use `mb.on('focus-lost')` if you would like to perform some operation when using the option `browserWindow.alwaysOnTop: true` | ||
- To restore focus of previous window after menubar hide, use `mb.on('after-hide', () => { mb.app.hide() } )` or similar |
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 |
---|---|---|
@@ -1,25 +1,46 @@ | ||
import { Tray } from 'electron'; | ||
import { BrowserWindowConstructorOptions, Tray } from 'electron'; | ||
|
||
export interface Options { | ||
/** | ||
* If true, the window will not hide on blur. | ||
* @deprecated Please pass this option inside `options.browserWindow`. | ||
*/ | ||
alwaysOnTop?: boolean; | ||
/** | ||
* An Electron BrowserWindow instance, or an options object to be passed into | ||
* the BrowserWindow constructor. | ||
* @example | ||
* ```javascript | ||
* const options = { height: 640, width: 480 }; | ||
* const mb = new Menubar({ | ||
* browserWindow: new BrowserWindow(options) | ||
* }); | ||
* | ||
* // The above is equivalent to | ||
* | ||
* const options = { height: 640, width: 480 }; | ||
* const mb = new Menubar({ | ||
* browserWindow: options | ||
* }); | ||
* ``` | ||
*/ | ||
browserWindow: BrowserWindowConstructorOptions; | ||
/** | ||
* The app source directory. | ||
*/ | ||
dir: string; | ||
/** | ||
* Window height. | ||
* @deprecated Please pass this option inside `options.browserWindow`. | ||
*/ | ||
height: number; | ||
height?: number; | ||
/** | ||
* 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 [email protected] and Electron will | ||
* automatically use your @2x version on retina screens. | ||
*/ | ||
icon?: string | Electron.NativeImage; | ||
icon: string | Electron.NativeImage; | ||
/** | ||
* The html to load for the pop up window. | ||
*/ | ||
|
@@ -28,31 +49,29 @@ export interface Options { | |
* Create BrowserWindow instance before it is used -- increasing resource | ||
* usage, but making the click on the menubar load faster. | ||
*/ | ||
preloadWindow?: boolean; | ||
preloadWindow: boolean; | ||
/** | ||
* Configure the visibility of the application dock icon. | ||
* Configure the visibility of the application dock icon, macOS only. Calls | ||
* [`app.dock.hide`](https://electronjs.org/docs/api/app#appdockhide-macos) | ||
*/ | ||
showDockIcon: boolean; | ||
/** | ||
* Makes the window available on all OS X workspaces. | ||
* Makes the window available on all OS X workspaces. Calls | ||
* [`setVisibleOnAllWorkspaces`](https://electronjs.org/docs/api/browser-window#winsetvisibleonallworkspacesvisible-options) | ||
*/ | ||
showOnAllWorkspaces?: boolean; | ||
showOnAllWorkspaces: boolean; | ||
/** | ||
* Show the window on 'right-click' event instead of regular 'click'. | ||
*/ | ||
showOnRightClick?: boolean; | ||
showOnRightClick: boolean; | ||
/** | ||
* Menubar tray icon tooltip text. | ||
* Menubar tray icon tooltip text. Calls [`tray.setTooltip`](https://electronjs.org/docs/api/tray#traysettooltiptooltip) | ||
*/ | ||
tooltip: string; | ||
/** | ||
* An electron Tray instance. If provided, `options.icon` will be ignored. | ||
*/ | ||
tray?: Tray; | ||
/** | ||
* the x position of the window. | ||
*/ | ||
x?: number; | ||
tray: Tray; | ||
/** | ||
* Sets the window position (x and y will still override this), check | ||
* electron-positioner docs for valid values. | ||
|
@@ -75,10 +94,17 @@ export interface Options { | |
| 'center'; | ||
/** | ||
* Window width. | ||
* @deprecated Please pass this option inside `options.browserWindow`. | ||
*/ | ||
width?: number; | ||
/** | ||
* The x position of the window. | ||
* @deprecated Please pass this option inside `options.browserWindow`. | ||
*/ | ||
width: number; | ||
x?: number; | ||
/** | ||
* the x position of the window. | ||
* The x position of the window. | ||
* @deprecated Please pass this option inside `options.browserWindow`. | ||
*/ | ||
y?: number; | ||
} |
Oops, something went wrong.