chore: Prettified Code
[ci skip]
This commit is contained in:
parent
58139b6ecc
commit
e1b1dc3fec
2 changed files with 102 additions and 87 deletions
|
@ -100,7 +100,7 @@ export default class RAOP {
|
|||
shown_name = (manufacturer.length > 0 ? manufacturer[0].substring(13) : "") + " " + (model.length > 0 ? model[0].substring(6) : "");
|
||||
shown_name = shown_name.trim().length > 1 ? shown_name : (host ?? "Unknown").replace(".local", "");
|
||||
}
|
||||
} catch (e) { }
|
||||
} catch (e) {}
|
||||
let host_name = addresses != null && typeof addresses == "object" && addresses.length > 0 ? addresses[0] : typeof addresses == "string" ? addresses : "";
|
||||
|
||||
if (
|
||||
|
@ -211,13 +211,14 @@ export default class RAOP {
|
|||
this.ipairplay = ipv4;
|
||||
this.portairplay = ipport;
|
||||
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) {
|
||||
delete this.devices[idx]
|
||||
this.devices = this.devices.filter((n: any) => n) // remove old controller
|
||||
delete this.devices[idx];
|
||||
this.devices = this.devices.filter((n: any) => n); // remove old controller
|
||||
}
|
||||
this.devices.push(
|
||||
{
|
||||
this.devices.push({
|
||||
id: identifier,
|
||||
ip: ipv4,
|
||||
port: ipport,
|
||||
|
@ -230,11 +231,12 @@ export default class RAOP {
|
|||
airplay2: airplay2dv,
|
||||
debug: null,
|
||||
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)
|
||||
this.devices[idx].controller.on("status", (status: any) => {
|
||||
|
@ -251,7 +253,7 @@ export default class RAOP {
|
|||
}
|
||||
if (status == "pair_failed") {
|
||||
this._win.webContents.executeJavaScript(`app.sendAirPlayFailed()`);
|
||||
this.disconnectAirplay(this.devices[idx].id)
|
||||
this.disconnectAirplay(this.devices[idx].id);
|
||||
}
|
||||
if (status == "stopped") {
|
||||
// this.airtunes.stopAll(() => {
|
||||
|
@ -281,7 +283,9 @@ export default class RAOP {
|
|||
|
||||
electron.ipcMain.on("setAirPlayPasscode", (event, passcode, identifier) => {
|
||||
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) {
|
||||
this.devices[idx].controller.setPasscode(passcode);
|
||||
}
|
||||
|
@ -290,7 +294,9 @@ export default class RAOP {
|
|||
|
||||
electron.ipcMain.on("setAirPlayVolume", (event, volume, identifier) => {
|
||||
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) {
|
||||
this.devices[idx].controller.setVolume(volume);
|
||||
}
|
||||
|
@ -347,8 +353,8 @@ export default class RAOP {
|
|||
});
|
||||
|
||||
electron.ipcMain.on("disconnectAirplay", (event, identifier = "") => {
|
||||
console.log('iden', identifier)
|
||||
this.disconnectAirplay(identifier)
|
||||
console.log("iden", identifier);
|
||||
this.disconnectAirplay(identifier);
|
||||
});
|
||||
|
||||
electron.ipcMain.on("updateAirplayInfo", (event, title, artist, album, artworkURL) => {
|
||||
|
@ -366,35 +372,39 @@ export default class RAOP {
|
|||
});
|
||||
}
|
||||
private disconnectAirplay(identifier: any = "") {
|
||||
console.log("awdas")
|
||||
this._win.webContents.executeJavaScript(`app.airplayDisconnect(false, [], '${identifier}')`).then(() => {
|
||||
console.log("awdas");
|
||||
this._win.webContents
|
||||
.executeJavaScript(`app.airplayDisconnect(false, [], '${identifier}')`)
|
||||
.then(() => {
|
||||
if (identifier == "") {
|
||||
if (this.airtunes) {
|
||||
for (let i in this.devices){
|
||||
this.devices[i].state = -1
|
||||
for (let i in this.devices) {
|
||||
this.devices[i].state = -1;
|
||||
}
|
||||
this.airtunes.stopAll(() => {
|
||||
console.log("endAll");
|
||||
this.airtunes = null;
|
||||
this.devices = []
|
||||
this.devices = [];
|
||||
});
|
||||
} else {
|
||||
this.devices = [];
|
||||
}
|
||||
} 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) {
|
||||
this.devices[idx].state = -1
|
||||
this.devices[idx].controller.stop(() =>{
|
||||
console.log(this.devices[idx].id , "stopped")
|
||||
this.devices[idx].state = -1;
|
||||
this.devices[idx].controller.stop(() => {
|
||||
console.log(this.devices[idx].id, "stopped");
|
||||
});
|
||||
|
||||
delete this.devices[idx]
|
||||
this.devices = this.devices.filter((n: any) => n)
|
||||
delete this.devices[idx];
|
||||
this.devices = this.devices.filter((n: any) => n);
|
||||
}
|
||||
}
|
||||
if (this.devices.length == 0) {
|
||||
console.log('cleanup airtunes')
|
||||
console.log("cleanup airtunes");
|
||||
this._win.webContents.setAudioMuted(false);
|
||||
this.airtunes = null;
|
||||
|
||||
|
@ -403,8 +413,8 @@ export default class RAOP {
|
|||
this.ok = 1;
|
||||
this.i = false;
|
||||
}
|
||||
}).catch((err: any) => console.error("lsdsd", err));
|
||||
|
||||
})
|
||||
.catch((err: any) => console.error("lsdsd", err));
|
||||
}
|
||||
private uploadImageAirplay = (url: any) => {
|
||||
try {
|
||||
|
@ -431,7 +441,7 @@ export default class RAOP {
|
|||
/**
|
||||
* Runs on app stop
|
||||
*/
|
||||
onBeforeQuit(): void { }
|
||||
onBeforeQuit(): void {}
|
||||
|
||||
// /**
|
||||
// * Runs on song change
|
||||
|
@ -456,7 +466,6 @@ export default class RAOP {
|
|||
*/
|
||||
onPlaybackStateDidChange(attributes: any): void {
|
||||
if (this.airtunes && this.devices.length > 0) {
|
||||
|
||||
let title = attributes?.name ?? "";
|
||||
let artist = attributes?.artistName ?? "";
|
||||
let album = attributes?.albumName ?? "";
|
||||
|
|
|
@ -249,7 +249,7 @@ const app = new Vue({
|
|||
idleState: false,
|
||||
appVisible: true,
|
||||
currentAirPlayCodeID: "",
|
||||
airplayTrys: []
|
||||
airplayTrys: [],
|
||||
},
|
||||
watch: {
|
||||
cfg: {
|
||||
|
@ -4373,17 +4373,19 @@ const app = new Vue({
|
|||
},
|
||||
setAirPlayCodeUI(identifier) {
|
||||
this.modals.airplayPW = true;
|
||||
this.currentAirPlayCodeID = identifier
|
||||
this.currentAirPlayCodeID = identifier;
|
||||
},
|
||||
sendAirPlaySuccess(silent = false, identifier = "") {
|
||||
if (!silent){
|
||||
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", idx)
|
||||
if (idx != -1)
|
||||
delete this.airplayTrys[idx]
|
||||
this.airplayTrys = this.airplayTrys.filter(n => n)
|
||||
if (!silent) {
|
||||
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", idx);
|
||||
if (idx != -1) delete this.airplayTrys[idx];
|
||||
this.airplayTrys = this.airplayTrys.filter((n) => n);
|
||||
},
|
||||
sendAirPlayFailed() {
|
||||
notyf.success("Device paring failed!");
|
||||
|
@ -4392,26 +4394,30 @@ const app = new Vue({
|
|||
console.log("airplay dropped", dropped, array, identifier);
|
||||
if (dropped) {
|
||||
let [ipv4, ipport, sepassword, title, artist, album, artworkURL, txt, airplay2dv] = array;
|
||||
console.log(ipv4, ipport, sepassword, title, artist, album, artworkURL, txt, airplay2dv)
|
||||
let idx = this.airplayTrys.findIndex(((a) => {return a.id == ipv4+":"+ipport+"ap"}))
|
||||
console.log(ipv4, ipport, sepassword, title, artist, album, artworkURL, txt, airplay2dv);
|
||||
let idx = this.airplayTrys.findIndex((a) => {
|
||||
return a.id == ipv4 + ":" + ipport + "ap";
|
||||
});
|
||||
if (idx == -1) {
|
||||
this.airplayTrys.push({
|
||||
id : ipv4+":"+ipport+"ap",
|
||||
attempts : 1
|
||||
})
|
||||
id: ipv4 + ":" + ipport + "ap",
|
||||
attempts: 1,
|
||||
});
|
||||
}
|
||||
idx = this.airplayTrys.findIndex(((a) => {return a.id == ipv4+":"+ipport+"ap"}))
|
||||
if (this.airplayTrys[idx].attempts > 3){
|
||||
delete this.airplayTrys[idx]
|
||||
this.airplayTrys = this.airplayTrys.filter(n => n)
|
||||
console.log("delete idx", idx)
|
||||
idx = this.airplayTrys.findIndex((a) => {
|
||||
return a.id == ipv4 + ":" + ipport + "ap";
|
||||
});
|
||||
if (this.airplayTrys[idx].attempts > 3) {
|
||||
delete this.airplayTrys[idx];
|
||||
this.airplayTrys = this.airplayTrys.filter((n) => n);
|
||||
console.log("delete idx", idx);
|
||||
return;
|
||||
} else {
|
||||
this.airplayTrys[idx].attempts = this.airplayTrys[idx].attempts + 1
|
||||
this.airplayTrys[idx].attempts = this.airplayTrys[idx].attempts + 1;
|
||||
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 {
|
||||
if (identifier == "") {
|
||||
app.activeCasts = [];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue