Changed handlers and removed old listeners
Fixed on-close to work correctly on quit
This commit is contained in:
parent
0ab0bd7b77
commit
d80bfc8398
2 changed files with 47 additions and 46 deletions
|
@ -6,7 +6,7 @@ import * as express from "express";
|
|||
import * as getPort from "get-port";
|
||||
import * as yt from "youtube-search-without-api-key";
|
||||
import * as fs from "fs";
|
||||
import { Stream } from "stream";
|
||||
import {Stream} from "stream";
|
||||
import * as qrcode from "qrcode-terminal";
|
||||
import * as os from "os";
|
||||
import * as mm from 'music-metadata';
|
||||
|
@ -76,7 +76,7 @@ export class Win {
|
|||
* Creates the browser window
|
||||
*/
|
||||
async createWindow(): Promise<Electron.BrowserWindow> {
|
||||
this.clientPort = await getPort({ port: 9000 });
|
||||
this.clientPort = await getPort({port: 9000});
|
||||
this.verifyFiles();
|
||||
|
||||
// Load the previous state with fallback to defaults
|
||||
|
@ -262,7 +262,7 @@ export class Win {
|
|||
if (itspod != null)
|
||||
details.requestHeaders["Cookie"] = `itspod=${itspod}`;
|
||||
}
|
||||
callback({ requestHeaders: details.requestHeaders });
|
||||
callback({requestHeaders: details.requestHeaders});
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -295,7 +295,7 @@ export class Win {
|
|||
let i18n = fs.readFileSync(path.join(__dirname, `../../src/i18n/${key}.jsonc`), "utf8");
|
||||
i18n = jsonc.parse(i18n)
|
||||
Object.assign(i18nBase, i18n)
|
||||
}catch(e) {
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
event.returnValue = e;
|
||||
}
|
||||
|
@ -330,11 +330,6 @@ export class Win {
|
|||
event.returnValue = this.devMode;
|
||||
});
|
||||
|
||||
electron.ipcMain.on("close", () => {
|
||||
// listen for close event
|
||||
this.win.close();
|
||||
});
|
||||
|
||||
electron.ipcMain.on("put-library-songs", (event, arg) => {
|
||||
fs.writeFileSync(
|
||||
path.join(this.paths.ciderCache, "library-songs.json"),
|
||||
|
@ -415,8 +410,8 @@ export class Win {
|
|||
return await yt.search(u);
|
||||
});
|
||||
|
||||
electron.ipcMain.handle("setVibrancy", (event, key, value) => {
|
||||
this.win.setVibrancy(value);
|
||||
electron.ipcMain.on("close", () => {
|
||||
this.win.close();
|
||||
});
|
||||
|
||||
electron.ipcMain.on("maximize", () => {
|
||||
|
@ -429,7 +424,7 @@ export class Win {
|
|||
});
|
||||
electron.ipcMain.on("unmaximize", () => {
|
||||
// listen for maximize event
|
||||
this.win.unmaximize();
|
||||
this.win.unmaximize();
|
||||
});
|
||||
|
||||
electron.ipcMain.on("minimize", () => {
|
||||
|
@ -443,7 +438,7 @@ export class Win {
|
|||
});
|
||||
|
||||
electron.ipcMain.on("windowmin", (event, width, height) => {
|
||||
this.win.setMinimumSize(width,height);
|
||||
this.win.setMinimumSize(width, height);
|
||||
})
|
||||
|
||||
electron.ipcMain.on("windowontop", (event, ontop) => {
|
||||
|
@ -462,7 +457,7 @@ export class Win {
|
|||
})
|
||||
//Fullscreen
|
||||
electron.ipcMain.on('detachDT', (event, _) => {
|
||||
this.win.webContents.openDevTools({ mode: 'detach' });
|
||||
this.win.webContents.openDevTools({mode: 'detach'});
|
||||
})
|
||||
|
||||
|
||||
|
@ -497,7 +492,7 @@ export class Win {
|
|||
}
|
||||
|
||||
//QR Code
|
||||
electron.ipcMain.handle('showQR', async (event , _) => {
|
||||
electron.ipcMain.handle('showQR', async (event, _) => {
|
||||
let url = `http://${getIp()}:${this.remotePort}`;
|
||||
electron.shell.openExternal(`https://cider.sh/pair-remote?url=${btoa(encodeURI(url))}`);
|
||||
/*
|
||||
|
@ -510,11 +505,11 @@ export class Win {
|
|||
'get url'
|
||||
fetch(url)
|
||||
.then(res => res.buffer())
|
||||
.then(async(buffer) => {
|
||||
.then(async (buffer) => {
|
||||
try {
|
||||
const metadata = await mm.parseBuffer(buffer, 'audio/x-m4a');
|
||||
let SoundCheckTag = metadata.native.iTunes[1].value
|
||||
console.log('sc',SoundCheckTag)
|
||||
console.log('sc', SoundCheckTag)
|
||||
this.win.webContents.send('SoundCheckTag', SoundCheckTag)
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
|
@ -555,6 +550,25 @@ export class Win {
|
|||
});
|
||||
}
|
||||
|
||||
let isQuiting = false
|
||||
|
||||
this.win.on("close", (event: Event) => {
|
||||
if ((this.store.general.close_button_hide || process.platform === "darwin" )&& !isQuiting) {
|
||||
event.preventDefault();
|
||||
this.win.hide();
|
||||
} else {
|
||||
this.win.destroy();
|
||||
}
|
||||
})
|
||||
|
||||
electron.app.on('before-quit', () => {
|
||||
isQuiting = true
|
||||
});
|
||||
|
||||
electron.app.on('window-all-closed', () => {
|
||||
electron.app.quit()
|
||||
})
|
||||
|
||||
this.win.on("closed", () => {
|
||||
this.win = null;
|
||||
});
|
||||
|
@ -562,19 +576,20 @@ export class Win {
|
|||
// Set window Handler
|
||||
this.win.webContents.setWindowOpenHandler((x: any) => {
|
||||
if (x.url.includes("apple") || x.url.includes("localhost")) {
|
||||
return { action: "allow" };
|
||||
return {action: "allow"};
|
||||
}
|
||||
electron.shell.openExternal(x.url).catch(console.error);
|
||||
return { action: "deny" };
|
||||
return {action: "deny"};
|
||||
});
|
||||
}
|
||||
|
||||
private async broadcastRemote() {
|
||||
function getIp() {
|
||||
let ip :any = false;
|
||||
let ip: any = false;
|
||||
let alias = 0;
|
||||
const ifaces: any = os.networkInterfaces() ;
|
||||
const ifaces: any = os.networkInterfaces();
|
||||
for (var dev in ifaces) {
|
||||
ifaces[dev].forEach( (details: any) => {
|
||||
ifaces[dev].forEach((details: any) => {
|
||||
if (details.family === 'IPv4') {
|
||||
if (!/(loopback|vmware|internal|hamachi|vboxnet|virtualbox)/gi.test(dev + (alias ? ':' + alias : ''))) {
|
||||
if (details.address.substring(0, 8) === '192.168.' ||
|
||||
|
@ -586,14 +601,15 @@ export class Win {
|
|||
}
|
||||
}
|
||||
}
|
||||
}) ;
|
||||
});
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
const myString = `http://${getIp()}:${this.remotePort}`;
|
||||
let mdns = require('mdns-js');
|
||||
const encoded = new Buffer(myString).toString('base64');
|
||||
var x = mdns.tcp('cider-remote');
|
||||
var x = mdns.tcp('cider-remote');
|
||||
var txt_record = {
|
||||
"Ver": "131077",
|
||||
'DvSv': '3689',
|
||||
|
@ -604,7 +620,7 @@ export class Win {
|
|||
"CtlN": "Cider",
|
||||
"iV": "196623"
|
||||
}
|
||||
let server2 = mdns.createAdvertisement(x, `${await getPort({port: 3839})}`, { name: encoded, txt: txt_record });
|
||||
let server2 = mdns.createAdvertisement(x, `${await getPort({port: 3839})}`, {name: encoded, txt: txt_record});
|
||||
server2.start();
|
||||
console.log('remote broadcasted')
|
||||
}
|
||||
|
|
|
@ -3473,22 +3473,7 @@ const app = new Vue({
|
|||
}
|
||||
},
|
||||
closeWindow(){
|
||||
switch (app.cfg.general.close_behavior) {
|
||||
case 0:
|
||||
case '0':
|
||||
// the minimizeToTray plugin will handle this
|
||||
window.close();
|
||||
break;
|
||||
case 1:
|
||||
case '1':
|
||||
ipcRenderer.send('minimize');
|
||||
break;
|
||||
case 2:
|
||||
case '2':
|
||||
ipcRenderer.send('minimizeTray');
|
||||
break;
|
||||
|
||||
}
|
||||
ipcRenderer.send('close');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue