Skip to content

Commit

Permalink
feat: add option activateWithApp to allow not activate with this event (
Browse files Browse the repository at this point in the history
#361)

* feat: add option activateWithApp to allow not activate with this event

* feat: make activateWithApp default to true
  • Loading branch information
linonetwo authored Oct 27, 2021
1 parent bb48ebd commit 8384bf2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,13 @@ export class Menubar extends EventEmitter {
this.app.dock.hide();
}

this.app.on('activate', (_event, hasVisibleWindows) => {
if (!hasVisibleWindows) {
this.showWindow().catch(console.error);
}
});
if (this._options.activateWithApp) {
this.app.on('activate', (_event, hasVisibleWindows) => {
if (!hasVisibleWindows) {
this.showWindow().catch(console.error);
}
});
}

let trayImage =
this._options.icon ||
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import {
* Options for creating a menubar application
*/
export interface Options {
/**
* Listen on `app.on('activate')` to open menubar when app is activated.
* @default `true`
*/
activateWithApp?: boolean;
/**
* An Electron BrowserWindow instance, or an options object to be passed into
* the BrowserWindow constructor.
Expand Down
3 changes: 3 additions & 0 deletions src/util/cleanOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const DEFAULT_WINDOW_WIDTH = 400;
export function cleanOptions(opts?: Partial<Options>): Options {
const options: Partial<Options> = { ...opts };

if (options.activateWithApp === undefined) {
options.activateWithApp = true;
}
if (!options.dir) {
options.dir = app.getAppPath();
}
Expand Down

0 comments on commit 8384bf2

Please # to comment.