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

fix(setSize): reset position when setSize #350

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
31 changes: 26 additions & 5 deletions src/Menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,37 @@ export class Menubar extends EventEmitter {
throw new Error('Window has been initialized just above. qed.');
}

this.emit('show');

this.setPosition(trayPos)

this._browserWindow.show();
this._isVisible = true;
this.emit('after-show');
return;
}

private async setPosition(trayPos?: Electron.Rectangle): Promise<void> {
if (!this.tray) {
throw new Error('Tray should have been instantiated by now');
}

if (!this._browserWindow) {
await this.createWindow();
}

// Use guard for TypeScript, to avoid ! everywhere
if (!this._browserWindow) {
throw new Error('Window has been initialized just above. qed.');
}

// 'Windows' taskbar: sync windows position each time before showing
// https://github.com/maxogden/menubar/issues/232
if (['win32', 'linux'].includes(process.platform)) {
// Fill in this._options.windowPosition when taskbar position is available
this._options.windowPosition = getWindowPosition(this.tray);
}

this.emit('show');

if (trayPos && trayPos.x !== 0) {
// Cache the bounds
this._cachedBounds = trayPos;
Expand Down Expand Up @@ -188,9 +210,6 @@ export class Menubar extends EventEmitter {
// `.setPosition` crashed on non-integers
// https://github.com/maxogden/menubar/issues/233
this._browserWindow.setPosition(Math.round(x), Math.round(y));
this._browserWindow.show();
this._isVisible = true;
this.emit('after-show');
return;
}

Expand Down Expand Up @@ -310,6 +329,8 @@ export class Menubar extends EventEmitter {

this._browserWindow.on('close', this.windowClear.bind(this));

this._browserWindow.on('resize', this.setPosition.bind(this, undefined));

// If the user explicity set options.index to false, we don't loadURL
// https://github.com/maxogden/menubar/issues/255
if (this._options.index !== false) {
Expand Down