|
|
|
@ -21,6 +21,10 @@ import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer';
|
|
|
|
|
import express from 'express';
|
|
|
|
|
import expressProxy from 'express-http-proxy';
|
|
|
|
|
import Store from 'electron-store';
|
|
|
|
|
const clc = require('cli-color');
|
|
|
|
|
const log = text => {
|
|
|
|
|
console.log(`${clc.blueBright('[background.js]')} ${text}`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Background {
|
|
|
|
|
constructor() {
|
|
|
|
@ -41,7 +45,7 @@ class Background {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init() {
|
|
|
|
|
console.log('initializing');
|
|
|
|
|
log('initializing');
|
|
|
|
|
|
|
|
|
|
// Make sure the app is singleton.
|
|
|
|
|
if (!app.requestSingleInstanceLock()) return app.quit();
|
|
|
|
@ -84,7 +88,7 @@ class Background {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createExpressApp() {
|
|
|
|
|
console.log('creating express app');
|
|
|
|
|
log('creating express app');
|
|
|
|
|
|
|
|
|
|
const expressApp = express();
|
|
|
|
|
expressApp.use('/', express.static(__dirname + '/'));
|
|
|
|
@ -105,7 +109,7 @@ class Background {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createWindow() {
|
|
|
|
|
console.log('creating app window');
|
|
|
|
|
log('creating app window');
|
|
|
|
|
|
|
|
|
|
const appearance = this.store.get('settings.appearance');
|
|
|
|
|
const showLibraryDefault = this.store.get('settings.showLibraryDefault');
|
|
|
|
@ -227,6 +231,7 @@ class Background {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkForUpdates() {
|
|
|
|
|
log('checkForUpdates');
|
|
|
|
|
autoUpdater.checkForUpdatesAndNotify();
|
|
|
|
|
|
|
|
|
|
const showNewVersionMessage = info => {
|
|
|
|
@ -255,12 +260,12 @@ class Background {
|
|
|
|
|
|
|
|
|
|
handleOSDEvents() {
|
|
|
|
|
this.osdlyrics.once('ready-to-show', () => {
|
|
|
|
|
console.log('OSD ready-to-show event');
|
|
|
|
|
log('OSD ready-to-show event');
|
|
|
|
|
this.osdlyrics.show();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.osdlyrics.on('closed', e => {
|
|
|
|
|
console.log('OSD close event');
|
|
|
|
|
log('OSD close event');
|
|
|
|
|
this.osdlyrics = null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -279,12 +284,12 @@ class Background {
|
|
|
|
|
|
|
|
|
|
handleWindowEvents() {
|
|
|
|
|
this.window.once('ready-to-show', () => {
|
|
|
|
|
console.log('windows ready-to-show event');
|
|
|
|
|
log('windows ready-to-show event');
|
|
|
|
|
this.window.show();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.window.on('close', e => {
|
|
|
|
|
console.log('windows close event');
|
|
|
|
|
log('windows close event');
|
|
|
|
|
if (this.willQuitApp) {
|
|
|
|
|
/* the user tried to quit the app */
|
|
|
|
|
this.window = null;
|
|
|
|
@ -315,7 +320,7 @@ class Background {
|
|
|
|
|
|
|
|
|
|
this.window.webContents.on('new-window', function (e, url) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
console.log('open url');
|
|
|
|
|
log('open url');
|
|
|
|
|
const excludeHosts = ['www.last.fm'];
|
|
|
|
|
const exclude = excludeHosts.find(host => url.includes(host));
|
|
|
|
|
if (exclude) {
|
|
|
|
@ -343,7 +348,7 @@ class Background {
|
|
|
|
|
// This method will be called when Electron has finished
|
|
|
|
|
// initialization and is ready to create browser windows.
|
|
|
|
|
// Some APIs can only be used after this event occurs.
|
|
|
|
|
console.log('app ready event');
|
|
|
|
|
log('app ready event');
|
|
|
|
|
|
|
|
|
|
// for development
|
|
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
@ -373,7 +378,7 @@ class Background {
|
|
|
|
|
const proxyRules = this.store.get('proxy');
|
|
|
|
|
if (proxyRules) {
|
|
|
|
|
this.window.webContents.session.setProxy({ proxyRules }, result => {
|
|
|
|
|
console.log('finished setProxy', result);
|
|
|
|
|
log('finished setProxy', result);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -412,7 +417,7 @@ class Background {
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
|
// On macOS it's common to re-create a window in the app when the
|
|
|
|
|
// dock icon is clicked and there are no other windows open.
|
|
|
|
|
console.log('app activate event');
|
|
|
|
|
log('app activate event');
|
|
|
|
|
if (this.window === null) {
|
|
|
|
|
this.createWindow();
|
|
|
|
|
} else {
|
|
|
|
|