mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-16 21:28:06 +00:00
fix: bugs
This commit is contained in:
parent
17ef0e927c
commit
bb87b7f20d
9 changed files with 54 additions and 41 deletions
|
|
@ -26,6 +26,11 @@ const log = text => {
|
|||
console.log(`${clc.blueBright('[background.js]')} ${text}`);
|
||||
};
|
||||
|
||||
const isWindows = process.platform === 'win32';
|
||||
const isMac = process.platform === 'darwin';
|
||||
const isLinux = process.platform === 'linux';
|
||||
const isDevelopment = process.env.NODE_ENV === 'development';
|
||||
|
||||
class Background {
|
||||
constructor() {
|
||||
this.window = null;
|
||||
|
|
@ -38,7 +43,7 @@ class Background {
|
|||
});
|
||||
this.neteaseMusicAPI = null;
|
||||
this.expressApp = null;
|
||||
this.willQuitApp = process.platform === 'darwin' ? false : true;
|
||||
this.willQuitApp = isMac ? false : true;
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
|
@ -73,7 +78,7 @@ class Background {
|
|||
}
|
||||
|
||||
// Exit cleanly on request from parent process in development mode.
|
||||
if (process.platform === 'win32') {
|
||||
if (isWindows) {
|
||||
process.on('message', data => {
|
||||
if (data === 'graceful-exit') {
|
||||
app.quit();
|
||||
|
|
@ -119,7 +124,7 @@ class Background {
|
|||
minWidth: 1080,
|
||||
minHeight: 720,
|
||||
titleBarStyle: 'hiddenInset',
|
||||
frame: process.platform !== 'win32',
|
||||
frame: !isWindows,
|
||||
title: 'YesPlayMusic',
|
||||
show: false,
|
||||
webPreferences: {
|
||||
|
|
@ -165,7 +170,7 @@ class Background {
|
|||
}
|
||||
|
||||
checkForUpdates() {
|
||||
if (process.env.NODE_ENV === 'development') return;
|
||||
if (isDevelopment) return;
|
||||
log('checkForUpdates');
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
|
||||
|
|
@ -195,17 +200,20 @@ class Background {
|
|||
|
||||
handleWindowEvents() {
|
||||
this.window.once('ready-to-show', () => {
|
||||
log('windows ready-to-show event');
|
||||
log('window ready-to-show event');
|
||||
this.window.show();
|
||||
});
|
||||
|
||||
this.window.on('close', e => {
|
||||
log('windows close event');
|
||||
log('window close event');
|
||||
let closeOpt = this.store.get('settings.closeAppOption');
|
||||
if (this.willQuitApp && (closeOpt === 'exit' || closeOpt === 'ask')) {
|
||||
/* the user tried to quit the app */
|
||||
this.window = null;
|
||||
app.quit();
|
||||
} else if (!this.willQuitApp && isMac) {
|
||||
e.preventDefault();
|
||||
this.window.hide();
|
||||
} else {
|
||||
/* the user only tried to close the window */
|
||||
e.preventDefault();
|
||||
|
|
@ -223,7 +231,7 @@ class Background {
|
|||
|
||||
this.window.on('minimize', () => {
|
||||
if (
|
||||
['win32', 'linux'].includes(process.platform) &&
|
||||
!isMac &&
|
||||
this.store.get('settings.closeAppOption') === 'minimizeToTray'
|
||||
) {
|
||||
this.window.hide();
|
||||
|
|
@ -263,7 +271,7 @@ class Background {
|
|||
log('app ready event');
|
||||
|
||||
// for development
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
if (isDevelopment) {
|
||||
this.initDevtools();
|
||||
}
|
||||
|
||||
|
|
@ -292,10 +300,7 @@ class Background {
|
|||
createMenu(this.window, this.store);
|
||||
|
||||
// create tray
|
||||
if (
|
||||
['win32', 'linux'].includes(process.platform) ||
|
||||
process.env.NODE_ENV === 'development'
|
||||
) {
|
||||
if (isWindows || isLinux || isDevelopment) {
|
||||
this.tray = createTray(this.window);
|
||||
}
|
||||
|
||||
|
|
@ -323,7 +328,7 @@ class Background {
|
|||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
if (!isMac) {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue