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 = (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", "");
|
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 : "";
|
let host_name = addresses != null && typeof addresses == "object" && addresses.length > 0 ? addresses[0] : typeof addresses == "string" ? addresses : "";
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -211,30 +211,32 @@ 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,
|
||||||
|
state: 0,
|
||||||
|
controller: this.airtunes.add(ipv4, {
|
||||||
port: ipport,
|
port: ipport,
|
||||||
state: 0,
|
volume: airplay2dv ? 30 : 50,
|
||||||
controller: this.airtunes.add(ipv4, {
|
password: sepassword,
|
||||||
port: ipport,
|
txt: txt,
|
||||||
volume: airplay2dv ? 30 : 50,
|
airplay2: airplay2dv,
|
||||||
password: sepassword,
|
debug: null,
|
||||||
txt: txt,
|
forceAlac: false,
|
||||||
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)
|
// 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,45 +372,49 @@ 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
|
||||||
if (identifier == "") {
|
.executeJavaScript(`app.airplayDisconnect(false, [], '${identifier}')`)
|
||||||
if (this.airtunes) {
|
.then(() => {
|
||||||
for (let i in this.devices){
|
if (identifier == "") {
|
||||||
this.devices[i].state = -1
|
if (this.airtunes) {
|
||||||
|
for (let i in this.devices) {
|
||||||
|
this.devices[i].state = -1;
|
||||||
|
}
|
||||||
|
this.airtunes.stopAll(() => {
|
||||||
|
console.log("endAll");
|
||||||
|
this.airtunes = null;
|
||||||
|
this.devices = [];
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.devices = [];
|
||||||
}
|
}
|
||||||
this.airtunes.stopAll(() => {
|
|
||||||
console.log("endAll");
|
|
||||||
this.airtunes = null;
|
|
||||||
this.devices = []
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
this.devices = [];
|
let idx = this.devices.findIndex((a: any) => {
|
||||||
}
|
return a.id == identifier;
|
||||||
} else {
|
|
||||||
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")
|
|
||||||
});
|
});
|
||||||
|
if (idx != -1) {
|
||||||
delete this.devices[idx]
|
this.devices[idx].state = -1;
|
||||||
this.devices = this.devices.filter((n: any) => n)
|
this.devices[idx].controller.stop(() => {
|
||||||
|
console.log(this.devices[idx].id, "stopped");
|
||||||
|
});
|
||||||
|
|
||||||
|
delete this.devices[idx];
|
||||||
|
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;
|
|
||||||
|
|
||||||
this.ipairplay = "";
|
|
||||||
this.portairplay = "";
|
|
||||||
this.ok = 1;
|
|
||||||
this.i = false;
|
|
||||||
}
|
|
||||||
}).catch((err: any) => console.error("lsdsd", err));
|
|
||||||
|
|
||||||
|
this.ipairplay = "";
|
||||||
|
this.portairplay = "";
|
||||||
|
this.ok = 1;
|
||||||
|
this.i = false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err: any) => console.error("lsdsd", err));
|
||||||
}
|
}
|
||||||
private uploadImageAirplay = (url: any) => {
|
private uploadImageAirplay = (url: any) => {
|
||||||
try {
|
try {
|
||||||
|
@ -431,7 +441,7 @@ export default class RAOP {
|
||||||
/**
|
/**
|
||||||
* Runs on app stop
|
* Runs on app stop
|
||||||
*/
|
*/
|
||||||
onBeforeQuit(): void { }
|
onBeforeQuit(): void {}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * Runs on song change
|
// * Runs on song change
|
||||||
|
@ -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 ?? "";
|
||||||
|
|
|
@ -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) => {
|
||||||
if (this.airplayTrys[idx].attempts > 3){
|
return a.id == ipv4 + ":" + ipport + "ap";
|
||||||
delete this.airplayTrys[idx]
|
});
|
||||||
this.airplayTrys = this.airplayTrys.filter(n => n)
|
if (this.airplayTrys[idx].attempts > 3) {
|
||||||
console.log("delete idx", idx)
|
delete this.airplayTrys[idx];
|
||||||
return;
|
this.airplayTrys = this.airplayTrys.filter((n) => n);
|
||||||
|
console.log("delete idx", idx);
|
||||||
|
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 = [];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue