feat: remember window position

master
qier222 4 years ago
parent 61d1d0ab4d
commit 41ff8058b2
No known key found for this signature in database
GPG Key ID: 9C85007ED905F14D

@ -110,7 +110,7 @@ class Background {
const appearance = this.store.get('settings.appearance'); const appearance = this.store.get('settings.appearance');
const showLibraryDefault = this.store.get('settings.showLibraryDefault'); const showLibraryDefault = this.store.get('settings.showLibraryDefault');
this.window = new BrowserWindow({ const options = {
width: this.store.get('window.width') || 1440, width: this.store.get('window.width') || 1440,
height: this.store.get('window.height') || 840, height: this.store.get('window.height') || 840,
minWidth: 1080, minWidth: 1080,
@ -118,6 +118,7 @@ class Background {
titleBarStyle: 'hiddenInset', titleBarStyle: 'hiddenInset',
frame: process.platform !== 'win32', frame: process.platform !== 'win32',
title: 'YesPlayMusic', title: 'YesPlayMusic',
show: false,
webPreferences: { webPreferences: {
webSecurity: false, webSecurity: false,
nodeIntegration: true, nodeIntegration: true,
@ -130,7 +131,14 @@ class Background {
appearance === 'dark' appearance === 'dark'
? '#222' ? '#222'
: '#fff', : '#fff',
}); };
if (this.store.get('window.x') && this.store.get('window.y')) {
options.x = this.store.get('window.x');
options.y = this.store.get('window.y');
}
this.window = new BrowserWindow(options);
// hide menu bar on Microsoft Windows and Linux // hide menu bar on Microsoft Windows and Linux
this.window.setMenuBarVisibility(false); this.window.setMenuBarVisibility(false);
@ -288,9 +296,12 @@ class Background {
} }
}); });
this.window.on('resize', () => { this.window.on('resized', () => {
let { height, width } = this.window.getBounds(); this.store.set('window', this.window.getBounds());
this.store.set('window', { height, width }); });
this.window.on('moved', () => {
this.store.set('window', this.window.getBounds());
}); });
this.window.on('minimize', () => { this.window.on('minimize', () => {
@ -341,6 +352,9 @@ class Background {
// create window // create window
this.createWindow(); this.createWindow();
this.window.once('ready-to-show', () => {
this.window.show();
});
this.handleWindowEvents(); this.handleWindowEvents();
this.initOSDLyrics(); this.initOSDLyrics();

Loading…
Cancel
Save