chore: Prettified Code

[ci skip]
This commit is contained in:
vapormusic 2022-09-10 12:26:01 +00:00 committed by cider-chore[bot]
parent 58139b6ecc
commit e1b1dc3fec
2 changed files with 102 additions and 87 deletions

View file

@ -211,13 +211,14 @@ export default class RAOP {
this.ipairplay = ipv4; this.ipairplay = ipv4;
this.portairplay = ipport; this.portairplay = ipport;
let identifier = ipv4 + ":" + ipport + "ap"; let identifier = ipv4 + ":" + ipport + "ap";
let idx = this.devices.findIndex(((a: any) => { return a.id == identifier })) let idx = this.devices.findIndex((a: any) => {
return a.id == identifier;
});
if (idx != -1) { if (idx != -1) {
delete this.devices[idx] delete this.devices[idx];
this.devices = this.devices.filter((n: any) => n) // remove old controller this.devices = this.devices.filter((n: any) => n); // remove old controller
} }
this.devices.push( this.devices.push({
{
id: identifier, id: identifier,
ip: ipv4, ip: ipv4,
port: ipport, port: ipport,
@ -230,11 +231,12 @@ export default class RAOP {
airplay2: airplay2dv, airplay2: airplay2dv,
debug: null, debug: null,
forceAlac: false, forceAlac: false,
}) }),
} });
);
idx = this.devices.findIndex(((a: any) => { return a.id == identifier })) idx = this.devices.findIndex((a: any) => {
return a.id == identifier;
});
// console.log('lol', this.devices) // console.log('lol', this.devices)
this.devices[idx].controller.on("status", (status: any) => { this.devices[idx].controller.on("status", (status: any) => {
@ -251,7 +253,7 @@ export default class RAOP {
} }
if (status == "pair_failed") { if (status == "pair_failed") {
this._win.webContents.executeJavaScript(`app.sendAirPlayFailed()`); this._win.webContents.executeJavaScript(`app.sendAirPlayFailed()`);
this.disconnectAirplay(this.devices[idx].id) this.disconnectAirplay(this.devices[idx].id);
} }
if (status == "stopped") { if (status == "stopped") {
// this.airtunes.stopAll(() => { // this.airtunes.stopAll(() => {
@ -281,7 +283,9 @@ export default class RAOP {
electron.ipcMain.on("setAirPlayPasscode", (event, passcode, identifier) => { electron.ipcMain.on("setAirPlayPasscode", (event, passcode, identifier) => {
if (this.devices.length > 0) { if (this.devices.length > 0) {
let idx = this.devices.findIndex(((a: any) => { return a.id == identifier })) let idx = this.devices.findIndex((a: any) => {
return a.id == identifier;
});
if (idx != -1) { if (idx != -1) {
this.devices[idx].controller.setPasscode(passcode); this.devices[idx].controller.setPasscode(passcode);
} }
@ -290,7 +294,9 @@ export default class RAOP {
electron.ipcMain.on("setAirPlayVolume", (event, volume, identifier) => { electron.ipcMain.on("setAirPlayVolume", (event, volume, identifier) => {
if (this.devices.length > 0) { if (this.devices.length > 0) {
let idx = this.devices.findIndex(((a: any) => { return a.id == identifier })) let idx = this.devices.findIndex((a: any) => {
return a.id == identifier;
});
if (idx != -1) { if (idx != -1) {
this.devices[idx].controller.setVolume(volume); this.devices[idx].controller.setVolume(volume);
} }
@ -347,8 +353,8 @@ export default class RAOP {
}); });
electron.ipcMain.on("disconnectAirplay", (event, identifier = "") => { electron.ipcMain.on("disconnectAirplay", (event, identifier = "") => {
console.log('iden', identifier) console.log("iden", identifier);
this.disconnectAirplay(identifier) this.disconnectAirplay(identifier);
}); });
electron.ipcMain.on("updateAirplayInfo", (event, title, artist, album, artworkURL) => { electron.ipcMain.on("updateAirplayInfo", (event, title, artist, album, artworkURL) => {
@ -366,35 +372,39 @@ export default class RAOP {
}); });
} }
private disconnectAirplay(identifier: any = "") { private disconnectAirplay(identifier: any = "") {
console.log("awdas") console.log("awdas");
this._win.webContents.executeJavaScript(`app.airplayDisconnect(false, [], '${identifier}')`).then(() => { this._win.webContents
.executeJavaScript(`app.airplayDisconnect(false, [], '${identifier}')`)
.then(() => {
if (identifier == "") { if (identifier == "") {
if (this.airtunes) { if (this.airtunes) {
for (let i in this.devices) { for (let i in this.devices) {
this.devices[i].state = -1 this.devices[i].state = -1;
} }
this.airtunes.stopAll(() => { this.airtunes.stopAll(() => {
console.log("endAll"); console.log("endAll");
this.airtunes = null; this.airtunes = null;
this.devices = [] this.devices = [];
}); });
} else { } else {
this.devices = []; this.devices = [];
} }
} else { } else {
let idx = this.devices.findIndex(((a: any) => { return a.id == identifier })) let idx = this.devices.findIndex((a: any) => {
return a.id == identifier;
});
if (idx != -1) { if (idx != -1) {
this.devices[idx].state = -1 this.devices[idx].state = -1;
this.devices[idx].controller.stop(() => { this.devices[idx].controller.stop(() => {
console.log(this.devices[idx].id , "stopped") console.log(this.devices[idx].id, "stopped");
}); });
delete this.devices[idx] delete this.devices[idx];
this.devices = this.devices.filter((n: any) => n) this.devices = this.devices.filter((n: any) => n);
} }
} }
if (this.devices.length == 0) { if (this.devices.length == 0) {
console.log('cleanup airtunes') console.log("cleanup airtunes");
this._win.webContents.setAudioMuted(false); this._win.webContents.setAudioMuted(false);
this.airtunes = null; this.airtunes = null;
@ -403,8 +413,8 @@ export default class RAOP {
this.ok = 1; this.ok = 1;
this.i = false; this.i = false;
} }
}).catch((err: any) => console.error("lsdsd", err)); })
.catch((err: any) => console.error("lsdsd", err));
} }
private uploadImageAirplay = (url: any) => { private uploadImageAirplay = (url: any) => {
try { try {
@ -456,7 +466,6 @@ export default class RAOP {
*/ */
onPlaybackStateDidChange(attributes: any): void { onPlaybackStateDidChange(attributes: any): void {
if (this.airtunes && this.devices.length > 0) { if (this.airtunes && this.devices.length > 0) {
let title = attributes?.name ?? ""; let title = attributes?.name ?? "";
let artist = attributes?.artistName ?? ""; let artist = attributes?.artistName ?? "";
let album = attributes?.albumName ?? ""; let album = attributes?.albumName ?? "";

View file

@ -249,7 +249,7 @@ const app = new Vue({
idleState: false, idleState: false,
appVisible: true, appVisible: true,
currentAirPlayCodeID: "", currentAirPlayCodeID: "",
airplayTrys: [] airplayTrys: [],
}, },
watch: { watch: {
cfg: { cfg: {
@ -4373,17 +4373,19 @@ const app = new Vue({
}, },
setAirPlayCodeUI(identifier) { setAirPlayCodeUI(identifier) {
this.modals.airplayPW = true; this.modals.airplayPW = true;
this.currentAirPlayCodeID = identifier this.currentAirPlayCodeID = identifier;
}, },
sendAirPlaySuccess(silent = false, identifier = "") { sendAirPlaySuccess(silent = false, identifier = "") {
if (!silent) { if (!silent) {
notyf.success("Device paired successfully!");} notyf.success("Device paired successfully!");
console.log("delete idx-pre", identifier) }
let idx = this.airplayTrys.findIndex(((a) => {return a.id == identifier})) console.log("delete idx-pre", identifier);
console.log("delete idx", idx) let idx = this.airplayTrys.findIndex((a) => {
if (idx != -1) return a.id == identifier;
delete this.airplayTrys[idx] });
this.airplayTrys = this.airplayTrys.filter(n => n) console.log("delete idx", idx);
if (idx != -1) delete this.airplayTrys[idx];
this.airplayTrys = this.airplayTrys.filter((n) => n);
}, },
sendAirPlayFailed() { sendAirPlayFailed() {
notyf.success("Device paring failed!"); notyf.success("Device paring failed!");
@ -4392,26 +4394,30 @@ const app = new Vue({
console.log("airplay dropped", dropped, array, identifier); console.log("airplay dropped", dropped, array, identifier);
if (dropped) { if (dropped) {
let [ipv4, ipport, sepassword, title, artist, album, artworkURL, txt, airplay2dv] = array; let [ipv4, ipport, sepassword, title, artist, album, artworkURL, txt, airplay2dv] = array;
console.log(ipv4, ipport, sepassword, title, artist, album, artworkURL, txt, airplay2dv) console.log(ipv4, ipport, sepassword, title, artist, album, artworkURL, txt, airplay2dv);
let idx = this.airplayTrys.findIndex(((a) => {return a.id == ipv4+":"+ipport+"ap"})) let idx = this.airplayTrys.findIndex((a) => {
return a.id == ipv4 + ":" + ipport + "ap";
});
if (idx == -1) { if (idx == -1) {
this.airplayTrys.push({ this.airplayTrys.push({
id: ipv4 + ":" + ipport + "ap", id: ipv4 + ":" + ipport + "ap",
attempts : 1 attempts: 1,
}) });
} }
idx = this.airplayTrys.findIndex(((a) => {return a.id == ipv4+":"+ipport+"ap"})) idx = this.airplayTrys.findIndex((a) => {
return a.id == ipv4 + ":" + ipport + "ap";
});
if (this.airplayTrys[idx].attempts > 3) { if (this.airplayTrys[idx].attempts > 3) {
delete this.airplayTrys[idx] delete this.airplayTrys[idx];
this.airplayTrys = this.airplayTrys.filter(n => n) this.airplayTrys = this.airplayTrys.filter((n) => n);
console.log("delete idx", idx) console.log("delete idx", idx);
return; return;
} else { } else {
this.airplayTrys[idx].attempts = this.airplayTrys[idx].attempts + 1 this.airplayTrys[idx].attempts = this.airplayTrys[idx].attempts + 1;
setTimeout(() => { setTimeout(() => {
ipcRenderer.send("performAirplayPCM", ipv4, ipport, sepassword, title, artist, album, artworkURL, txt, airplay2dv, true);}, 1000) ipcRenderer.send("performAirplayPCM", ipv4, ipport, sepassword, title, artist, album, artworkURL, txt, airplay2dv, true);
}, 1000);
} }
} else { } else {
if (identifier == "") { if (identifier == "") {
app.activeCasts = []; app.activeCasts = [];