Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Core 2022-03-12 12:00:59 +00:00
commit ea338a2492
6 changed files with 64 additions and 16 deletions

View file

@ -893,6 +893,14 @@ export class BrowserWindow {
app.exit()
})
app.on('before-quit', () => {
BrowserWindow.win.webContents.executeJavaScript(`
window.localStorage.setItem("currentTrack", JSON.stringify(app.mk.nowPlayingItem));
window.localStorage.setItem("currentTime", JSON.stringify(app.mk.currentPlaybackTime));
window.localStorage.setItem("currentQueue", JSON.stringify(app.mk.queue.items));
ipcRenderer.send('stopGCast','');`)
})
ipcMain.on('play', (_event, type, id) => {
BrowserWindow.win.webContents.executeJavaScript(`
@ -1169,17 +1177,22 @@ export class BrowserWindow {
*/
private static getIP(): string {
let ip: string = '';
let ip2: any = [];
let alias = 0;
const ifaces: any = networkInterfaces();
for (let dev in ifaces) {
ifaces[dev].forEach((details: any) => {
if (details.family === 'IPv4') {
if (details.family === 'IPv4' && !details.internal) {
if (!/(loopback|vmware|internal|hamachi|vboxnet|virtualbox)/gi.test(dev + (alias ? ':' + alias : ''))) {
if (details.address.substring(0, 8) === '192.168.' ||
details.address.substring(0, 7) === '172.16.' ||
details.address.substring(0, 3) === '10.'
) {
ip = details.address;
if (!ip.startsWith('192.168.') ||
(ip2.startsWith('192.168.') && !ip.startsWith('192.168.')) &&
(ip2.startsWith('172.16.') && !ip.startsWith('192.168.') && !ip.startsWith('172.16.')) ||
(ip2.startsWith('10.') && !ip.startsWith('192.168.') && !ip.startsWith('172.16.') && !ip.startsWith('10.'))
){ip = details.address;}
++alias;
}
}

View file

@ -21,4 +21,12 @@ CiderCastController.prototype.sendIp = function(ip) {
this.request(data);
};
CiderCastController.prototype.kill = function() {
// TODO: Implement Callback
let data = {
action : "stop"
}
this.request(data);
};
module.exports = CiderCastController;

View file

@ -74,4 +74,8 @@ CiderReceiver.prototype.sendIp = function(opts){
this.mediaReceiver.sendIp.apply(this.mediaReceiver, arguments);
};
CiderReceiver.prototype.kill = function(opts){
this.mediaReceiver.kill.apply(this.mediaReceiver, arguments);
};
module.exports = CiderReceiver;

View file

@ -27,6 +27,7 @@ export default class ChromecastPlugin {
// private requests = [];
// private GCstream = new Stream.PassThrough(),
private connectedHosts: any = {};
private connectedPlayer: any;
// private port = false;
// private server = false;
// private bufcount = 0;
@ -185,23 +186,35 @@ export default class ChromecastPlugin {
// send websocket ip
player.sendIp("ws://" + this.getIp() + ":26369");
electron.ipcMain.on('stopGCast', (_event) => {
player.kill();
})
electron.app.on('before-quit', (_event) => {
player.kill();
})
});
}
private getIp() {
let ip = false;
private getIp(){
let ip: string = '';
let ip2: any = [];
let alias = 0;
let ifaces: any = os.networkInterfaces();
for (var dev in ifaces) {
const ifaces: any = os.networkInterfaces();
for (let dev in ifaces) {
ifaces[dev].forEach((details: any) => {
if (details.family === 'IPv4') {
if (details.family === 'IPv4' && !details.internal) {
if (!/(loopback|vmware|internal|hamachi|vboxnet|virtualbox)/gi.test(dev + (alias ? ':' + alias : ''))) {
if (details.address.substring(0, 8) === '192.168.' ||
details.address.substring(0, 7) === '172.16.' ||
details.address.substring(0, 3) === '10.'
) {
ip = details.address;
if (!ip.startsWith('192.168.') ||
(ip2.startsWith('192.168.') && !ip.startsWith('192.168.')) &&
(ip2.startsWith('172.16.') && !ip.startsWith('192.168.') && !ip.startsWith('172.16.')) ||
(ip2.startsWith('10.') && !ip.startsWith('192.168.') && !ip.startsWith('172.16.') && !ip.startsWith('10.'))
){ip = details.address;}
++alias;
}
}
@ -320,6 +333,11 @@ export default class ChromecastPlugin {
electron.ipcMain.on('stopGCast', (_event) => {
this._win.webContents.setAudioMuted(false);
this.activeConnections.forEach((client: any) => {
try{
client.stop();
} catch(e){}
})
this.activeConnections = [];
this.connectedHosts = {};

View file

@ -248,7 +248,8 @@ const CiderAudio = {
case "data":
const audioData = data.audioBuffer;
const bufferSize = data.bufferSize;
ipcRenderer.send('writeWAV', audioData[0], audioData[1], bufferSize);
if((audioData[0]).some(item => item !== 0) || (audioData[0]).some(item => item !== 0)){
ipcRenderer.send('writeWAV', audioData[0], audioData[1], bufferSize);}
break;
case "stop":
break;

View file

@ -643,11 +643,6 @@ const app = new Vue({
this.library.albums.displayListing = this.library.albums.listing
}
window.onbeforeunload = function (e) {
window.localStorage.setItem("currentTrack", JSON.stringify(app.mk.nowPlayingItem))
window.localStorage.setItem("currentTime", JSON.stringify(app.mk.currentPlaybackTime))
window.localStorage.setItem("currentQueue", JSON.stringify(app.mk.queue.items))
};
if (typeof MusicKit.PlaybackBitrate[app.cfg.audio.quality] !== "string") {
app.mk.bitrate = MusicKit.PlaybackBitrate[app.cfg.audio.quality]
@ -2613,6 +2608,7 @@ const app = new Vue({
req.open('GET', url, true);
req.setRequestHeader("authority", "apic-desktop.musixmatch.com");
req.onload = function () {
try{
let jsonResponse = JSON.parse(this.responseText);
let status2 = jsonResponse["message"]["header"]["status_code"];
if (status2 == 200) {
@ -2635,7 +2631,10 @@ const app = new Vue({
// console.log('token 4xx');
getToken(mode, track, artist, songid, lang, time)
}
}catch(e){
console.log('error');
app.loadAMLyrics();
}
};
req.onerror = function () {
console.log('error');
@ -2656,6 +2655,7 @@ const app = new Vue({
req.open('GET', url, true);
req.setRequestHeader("authority", "apic-desktop.musixmatch.com");
req.onload = function () {
try{
let jsonResponse = JSON.parse(this.responseText);
console.log(jsonResponse);
let status1 = jsonResponse["message"]["header"]["status_code"];
@ -2733,6 +2733,9 @@ const app = new Vue({
}
} else { //4xx rejected
getToken(1, track, artist, '', lang, time);
}}catch(e){
console.log(e);
app.loadAMLyrics()
}
}
req.onerror = function () {
@ -2751,6 +2754,7 @@ const app = new Vue({
req2.open('GET', url2, true);
req2.setRequestHeader("authority", "apic-desktop.musixmatch.com");
req2.onload = function () {
try{
let jsonResponse2 = JSON.parse(this.responseText);
console.log(jsonResponse2);
let status2 = jsonResponse2["message"]["header"]["status_code"];
@ -2776,7 +2780,7 @@ const app = new Vue({
}
} else { //4xx rejected
getToken(2, '', '', id, lang, '');
}
}}catch(e){}
}
req2.send();
}