Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to not change the existing behavior.

Could you add inside the cleanOptions functions some logic to default this to true? E.g. if (options.activateWithApp === undefined) { options.activateWithApp = true }

if (!hasVisibleWindows) {
this.showWindow().catch(console.error);
}
});
}

let trayImage =
this._options.icon ||
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
* Options for creating a menubar application
*/
export interface Options {
/**
* Listen on `app.on('activate')` to open menubar when app is activated.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Listen on `app.on('activate')` to open menubar when app is activated.
* 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