manager/templates/app/app.js

721 lines
18 KiB
JavaScript
Raw Normal View History

2023-04-26 21:26:20 +00:00
const {ipcRenderer} = require("electron");
const ipc = ipcRenderer;
const fs = require("fs")
const packageJson = require("../../package.json")
const logo = document.getElementById("logo")
const username = document.getElementById("username")
const signout = document.getElementById("signout")
const onlineNumber = document.getElementById("online")
const closeBtn = document.getElementById("closeBtn");
const minimizeBtn = document.getElementById("minimizeBtn");
const musicTitle = document.getElementById("music_title")
const musicURL = document.getElementById("music_img")
const exitSpan = document.getElementById("exitSpan")
const list = document.getElementById("list")
const listDialog = document.getElementById("listDialog")
const listClose = document.getElementById("listClose")
const listClear = document.getElementById("listClear")
const listcontent = document.getElementById("listContent")
2023-04-28 15:29:41 +00:00
const listNumber = document.getElementById("listNumber")
2023-04-26 21:26:20 +00:00
const search = document.getElementById("search")
const searchBar = document.getElementById("searchBar")
const searchDialog = document.getElementById("searchDialog")
const searchClose = document.getElementById("searchClose")
const searchcontent = document.getElementById("searchContent")
2023-04-28 15:29:41 +00:00
const durationBar = document.getElementById("duration")
const durationText = document.getElementById("durationText")
const stDialog = document.getElementById("stDialog")
const settings = document.getElementById("settings")
const stClose = document.getElementById("stClose")
2023-04-29 21:23:37 +00:00
const patchDialog = document.getElementById("patchDialog")
const patchnote = document.getElementById("patchnote")
const patchClose = document.getElementById("patchClose")
const patchInfo = document.getElementById("patchInfo")
2023-04-30 17:00:04 +00:00
const sendDialog = document.getElementById("sendDialog")
const send = document.getElementById("bug")
const sendClose = document.getElementById("sendClose")
const sendContent = document.getElementById("sendContent")
const sendInfo = document.getElementById("sendInfo")
const sendSend = document.getElementById("sendSend")
const sendText = document.getElementById("sendText")
const sendChos = document.getElementById("sendChos")
2023-04-29 21:23:37 +00:00
2023-04-28 15:29:41 +00:00
const volCursor = document.getElementById("volCursor")
const volPct = document.getElementById("volPct")
const restart = document.getElementById("restart")
2023-04-30 21:42:49 +00:00
const updDialog = document.getElementById("updDialog")
const upd = document.getElementById("upd")
const updClose = document.getElementById("updClose")
const updSpan = document.getElementById("updSpan")
2023-05-01 21:39:49 +00:00
const favDialog = document.getElementById("favDialog")
const fav = document.getElementById("fav")
const favClose = document.getElementById("favClose")
const favClear = document.getElementById("favClear")
const favContent = document.getElementById("favContent")
fav.addEventListener("click", () => {
favDialog.showModal()
showFavoris()
})
favClear.addEventListener("click", () => {
const settings = getSettings()
settings.favoris = []
saveSettings(settings)
showFavoris()
})
function showFavoris() {
const settings = getSettings()
var contentToPush = new Array()
for(var title of settings.favoris) {
contentToPush.push('<div class="song"> <img class="thumbnail" src="' + title.thumbnail + '"><div class="titleSong"> <p class="listTitle">' + title.title + '</p></div> <button style="margin : 0;" id="' + settings.favoris.indexOf(title) + '_fadd" class="buttonReduce"><i class="fa fa-plus"></i></button> <button id="' + settings.favoris.indexOf(title) + '_fdelete" class="buttonClose"><i class="fa fa-trash"></i></button> </div></div>')
}
if(contentToPush.join("") == "") {
favContent.innerHTML = '<p class="error">Aucun morceau dans les favoris !</p>'
} else {
favContent.innerHTML = contentToPush.join("")
}
for(var title of settings.favoris) {
const titleBtn = document.getElementById(settings.favoris.indexOf(title) + "_fdelete")
const addBtn = document.getElementById(settings.favoris.indexOf(title) + "_fadd")
addBtn.addEventListener("click", () => {
ipc.send("addQueue", settings.favoris[addBtn.id.replace("_fadd", "")].uri)
favDialog.close()
})
titleBtn.addEventListener("click", () => {
settings.favoris.splice(titleBtn.id.replace("_fdelete", ""), 1)
saveSettings(settings)
showFavoris()
})
}
}
favClose.addEventListener("click", () => {
favDialog.close()
})
2023-04-30 21:42:49 +00:00
upd.addEventListener("click", () => {
updDialog.showModal()
updSpan.innerHTML = ""
setTimeout(() => {
2023-05-01 21:39:49 +00:00
updSpan.innerHTML = '<button style="margin-left: 25%;" id="updYes" class="bug"><i class="fas fa-warning"></i> Mettre à jour</button>'
2023-04-30 21:42:49 +00:00
const updYes = document.getElementById("updYes")
updYes.addEventListener("click", () => {
ipc.send("forceUpdate")
})
}, 2000)
})
updClose.addEventListener("click", () => {
updDialog.close()
})
2023-04-28 15:29:41 +00:00
restart.addEventListener("click", () => {
stDialog.close()
ipc.send("restart")
})
2023-04-29 21:23:37 +00:00
if(packageJson.dev == true) {
2023-04-30 17:00:04 +00:00
document.getElementById("devversion").innerHTML = "<p class='dp'>Cette version est expérimentale.<br> En cas de bug, <a style='cursor: pointer;text-decoration: underline;' id='bugD'>cliquez ici </a> </p>"
const sendB = document.getElementById("bugD")
sendB.addEventListener("click", () => {
2023-04-30 21:42:49 +00:00
2023-05-01 21:39:49 +00:00
sendInfo.innerHTML = ""
sendText.value = ""
sendChos.value = "Bug"
sendDialog.showModal()
2023-04-30 21:42:49 +00:00
2023-04-30 17:00:04 +00:00
})
2023-04-29 21:23:37 +00:00
}
2023-04-28 15:29:41 +00:00
var durationAll = 0
var durationProgress = 0
var isPlaying = false
2023-04-29 12:43:58 +00:00
2023-04-28 15:29:41 +00:00
2023-04-29 21:23:37 +00:00
patchnote.addEventListener("click", () => {
patchDialog.showModal()
const data = fs.readFileSync(__dirname + require("path").sep + "../../infoupdate.html")
patchInfo.innerHTML = data
})
patchClose.addEventListener("click", () => {
patchDialog.close()
})
2023-04-28 15:29:41 +00:00
settings.addEventListener("click", () => {
stDialog.showModal()
})
stClose.addEventListener("click", () => {
stDialog.close()
})
2023-04-30 17:00:04 +00:00
send.addEventListener("click", () => {
2023-04-30 21:42:49 +00:00
sendInfo.innerHTML = ""
sendText.value = ""
sendChos.value = "Bug"
2023-04-30 17:00:04 +00:00
sendDialog.showModal()
})
sendClose.addEventListener("click", () => {
sendDialog.close()
})
sendSend.addEventListener("click", () => {
sendInfo.innerHTML = ""
if(sendText.value == "") {
sendInfo.innerHTML = '<p style="text-align: center; color: red;">Le formulaire n\'a pas été rempli correctement !</p>'
} else {
const report = {
"type":sendChos.value,
"text": sendText.value
}
ipc.send("report", report)
}
})
ipc.on("reportForm", (ev, ans) => {
if(ans == true) {
sendInfo.innerHTML = '<p style="text-align: center;">Le formulaire a été envoyé !</p>'
} else {
sendInfo.innerHTML = '<p style="text-align: center; color: red;">Erreur lors de l\'envoi du formulaire !</p>'
}
})
2023-04-28 15:29:41 +00:00
durationBar.value = 0
listNumber.classList.add("exitNotShow")
function setTime() {
durationBar.max = durationAll
durationProgress += 1000
durationBar.value = durationProgress
const maxhours = Math.floor(durationAll / 3600000);
const nowhours = Math.floor(durationProgress / 3600000);
var maxmin = Math.trunc(durationAll / 60000) - (Math.floor(durationAll / 60000 / 60) * 60);
var maxsec = Math.floor(durationAll / 1000) - (Math.floor(durationAll / 1000 / 60) * 60);
var nowmin = Math.trunc(durationProgress / 60000) - (Math.floor(durationProgress / 60000 / 60) * 60);
var nowsec = Math.floor(durationProgress / 1000) - (Math.floor(durationProgress / 1000 / 60) * 60);
console.log(durationAll)
console.log(durationProgress)
console.log("---------------------")
var now = ""
var max = ""
if (maxmin < 10) {
maxmin = `0${maxmin}`;
}
if (nowmin < 10) {
nowmin = `0${nowmin}`;
}
if (maxsec < 10) {
maxsec = `0${maxsec}`;
}
if (nowsec < 10) {
nowsec = `0${nowsec}`;
}
if(maxhours != 0) {
max = maxhours + ":" + maxmin + ":" + maxsec
} else {
max = maxmin + ":" + maxsec
}
if(nowhours != 0) {
now = nowhours + ":" + nowmin + ":" + nowsec
} else {
now = nowmin + ":" + nowsec
}
durationText.innerHTML = now + "/" + max
}
setInterval(() => {
if(isPlaying == true) {
setTime()
2023-04-29 12:43:58 +00:00
}
2023-04-28 15:29:41 +00:00
}, 1000)
durationBar.addEventListener("change", () => {
ipc.send("seek", durationBar.value)
})
volCursor.addEventListener("change", () => {
ipc.send("volume", volCursor.value)
})
const loop = document.getElementById("loop")
loop.addEventListener("click", () => {
ipc.send("loop")
})
2023-04-26 21:26:20 +00:00
listClear.addEventListener("click", () => {
ipc.send("listClear")
})
searchBar.addEventListener("change", () => {
ipc.send("findReq", searchBar.value)
})
ipc.on("findResult", (ev, list) => {
if(list.tracks != null) {
const data = list.tracks
var contentToPush = new Array()
for(var title of data) {
2023-05-01 21:39:49 +00:00
contentToPush.push(' <div class="ressong"> <img class="thumbnail" src="' + title.thumbnail + '"><div class="titleSong"> <p class="searchTitle">' + title.title + '</p></div><button id="' + data.indexOf(title) + '_sfav" class="buttonFav"><i class="fa fa-star"></i></button> <button id="' + data.indexOf(title) + '_sadd" class="buttonReduce"><i class="fa fa-plus"></i></button></div>')
2023-04-26 21:26:20 +00:00
}
if(contentToPush.join("") == "") {
searchcontent.innerHTML = '<p class="error">Aucun morceau trouvé !</p>'
} else {
searchcontent.innerHTML = contentToPush.join("")
}
for(var title of data) {
2023-05-01 21:39:49 +00:00
const titleBtn = document.getElementById(data.indexOf(title)+ "_sadd")
const favBtn = document.getElementById(data.indexOf(title)+ "_sfav")
2023-04-26 21:26:20 +00:00
titleBtn.addEventListener("click", () => {
searchcontent.innerHTML = ""
searchBar.value = ""
2023-05-01 21:39:49 +00:00
ipc.send("addQueue", data[titleBtn.id.replace("_sadd", "")].uri)
})
favBtn.addEventListener("click", () => {
const settings = getSettings()
if(settings.favoris == null) {
settings["favoris"] = []
}
var check = false
for(var song of settings.favoris) {
if(song.uri == data[favBtn.id.replace("_sfav", "")].uri) {
check = true
}
}
if(check == false) {
settings.favoris.push(data[favBtn.id.replace("_sfav", "")])
} else {
console.log("ALREADY ADDED")
}
saveSettings(settings)
searchDialog.close()
2023-04-26 21:26:20 +00:00
})
}
} else {
searchcontent.innerHTML = '<p class="error">Aucun morceau trouvé !</p>'
}
})
2023-05-01 21:39:49 +00:00
const path = require("path")
function getSettings() {
return require("../../settings.json")
}
function saveSettings(doc) {
fs.writeFileSync(__dirname.replace("templates" + path.sep + "app", "settings.json"), JSON.stringify(doc, null, 2))
}
2023-04-26 21:26:20 +00:00
list.addEventListener("click", () => {
listDialog.showModal()
})
listClose.addEventListener("click", () => {
listDialog.close()
})
search.addEventListener("click", () => {
searchDialog.showModal()
2023-05-01 21:39:49 +00:00
searchcontent.innerHTML = ""
searchBar.value = ""
2023-04-26 21:26:20 +00:00
})
searchClose.addEventListener("click", () => {
searchDialog.close()
})
const backward = document.getElementById("backward")
const play = document.getElementById("play")
const forward = document.getElementById("forward")
ipc.send("askUpdateState")
document.getElementById("version").innerHTML = packageJson.version
closeBtn.addEventListener("click", () => {
ipc.send("close");
});
minimizeBtn.addEventListener("click", () => {
ipc.send("minimize")
})
play.addEventListener("click" ,() => {
ipc.send("play")
console.log("PLAY")
})
backward.addEventListener("click" ,() => {
ipc.send("backward")
console.log("BACKWARD")
})
forward.addEventListener("click" ,() => {
ipc.send("forward")
console.log("FORWARD")
})
ipc.on("actualize", (ev, data) => {
2023-04-28 15:29:41 +00:00
isPlaying = false
2023-04-26 21:26:20 +00:00
console.log(data)
onlineNumber.innerHTML = data.onlineNumber
2023-04-28 15:29:41 +00:00
if(data.loop == true) {
loop.innerHTML = '<i class="third-join fa fa-retweet"></i>'
} else {
loop.innerHTML = '<i class="fa fa-retweet"></i>'
}
if(data.volume) {
volCursor.step = 1
volCursor.max = 100
volCursor.value = Math.trunc(data.volume / 10)
volPct.innerHTML = Math.trunc(data.volume / 10) + "%"
} else {
volPct.innerHTML = "0%"
2023-04-26 21:26:20 +00:00
}
if(data.isOnline == true) {
2023-04-28 15:29:41 +00:00
exitSpan.classList.remove("exitNotShow")
loop.classList.remove("exitNotShow")
2023-04-26 21:26:20 +00:00
exitSpan.innerHTML = ' <button id="exit" class="third-leave"><i class="fa fa-phone-slash"></i></button>'
const exit = document.getElementById("exit")
exit.addEventListener("click", () => {
ipc.send("exitBot")
})
2023-04-28 15:29:41 +00:00
volCursor.disabled = false
volCursor.classList.remove("grised")
durationBar.disabled = false
durationBar.classList.remove("grised")
} else {
exitSpan.classList.add("exitNotShow")
loop.classList.add("exitNotShow")
2023-04-26 21:26:20 +00:00
exitSpan.innerHTML = ""
2023-04-28 15:29:41 +00:00
durationBar.disabled = true
durationBar.classList.add("grised")
durationBar.value = 0
volCursor.disabled = true
volCursor.classList.add("grised")
volCursor.value = 0
2023-04-26 21:26:20 +00:00
}
if(data.queue != null) {
var contentToPush = new Array()
2023-04-28 15:29:41 +00:00
var queueNum = 0
2023-04-26 21:26:20 +00:00
for(var title of data.queue) {
2023-04-28 15:29:41 +00:00
queueNum += 1
console.log(queueNum)
2023-04-26 21:26:20 +00:00
console.log(data.queue.indexOf(title) + " - " + title.title)
2023-05-01 21:39:49 +00:00
contentToPush.push(' <div class="song"> <img class="thumbnail" src="' + title.thumbnail + '"><div class="titleSong"> <p class="listTitle">' + title.title + '</p></div> <button id="' + data.queue.indexOf(title) + '_lmove" class="buttonReduce"><i class="fa fa-arrow-up"></i></button> <button id="' + data.queue.indexOf(title) + '_ldelete" class="buttonClose"><i class="fa fa-trash"></i></button> </div></div>')
2023-04-26 21:26:20 +00:00
}
if(contentToPush.join("") == "") {
2023-04-28 15:29:41 +00:00
listNumber.classList.add("exitNotShow")
2023-04-26 21:26:20 +00:00
listcontent.innerHTML = '<p class="error">Aucun morceau dans la liste de lecture !</p>'
} else {
2023-04-28 15:29:41 +00:00
listNumber.innerHTML = '<span class="numtext">' + queueNum + '</span>'
listNumber.classList.remove("exitNotShow")
2023-04-26 21:26:20 +00:00
listcontent.innerHTML = contentToPush.join("")
}
for(var title of data.queue) {
console.log(data.queue.indexOf(title) + " - " + title.title)
2023-05-01 21:39:49 +00:00
const titleBtn = document.getElementById(data.queue.indexOf(title)+ "_ldelete")
const moveBtn = document.getElementById(data.queue.indexOf(title)+ "_lmove")
2023-04-26 21:26:20 +00:00
titleBtn.addEventListener("click", () => {
2023-05-01 21:39:49 +00:00
ipc.send("deleteQueue", titleBtn.id.replace("_ldelete", ""))
2023-04-26 21:26:20 +00:00
})
2023-04-30 17:00:04 +00:00
moveBtn.addEventListener("click", () => {
2023-05-01 21:39:49 +00:00
ipc.send("moveQueue", moveBtn.id.replace("_lmove", ""))
2023-04-30 17:00:04 +00:00
})
2023-04-26 21:26:20 +00:00
}
} else {
listcontent.innerHTML = '<p class="error">Aucun morceau dans la liste de lecture !</p>'
2023-04-28 15:29:41 +00:00
listNumber.classList.add("exitNotShow")
2023-04-26 21:26:20 +00:00
}
if(data.current == null) {
musicURL.innerHTML = '<img class="thumbnail" src="../common/Mediamodifier-Design.svg">'
musicTitle.innerHTML = "Aucun titre joué"
} else {
2023-04-28 15:29:41 +00:00
setTime()
2023-04-26 21:26:20 +00:00
musicURL.innerHTML = '<img class="thumbnail" src="' + data.current.thumbnail + '">'
musicTitle.innerHTML = data.current.title
}
2023-04-28 15:29:41 +00:00
2023-04-29 12:43:58 +00:00
durationProgress = 0
durationAll = 0
durationBar.value = 0
durationText.innerHTML = "=:==/=:=="
2023-04-28 15:29:41 +00:00
if(data.durationAll) {
isPlaying = true
durationBar.disabled = false
durationBar.classList.remove("grised")
setTime()
durationAll = data.durationAll
durationProgress = data.durationNow
durationBar.value = durationProgress
} else {
2023-04-29 12:43:58 +00:00
2023-04-28 15:29:41 +00:00
isPlaying = false
durationAll = 0
durationProgress = 0
durationBar.disabled = true
durationBar.classList.add("grised")
durationBar.value = 0
durationText.innerHTML = "=:==/=:=="
}
if(data.playing == 1) {
play.innerHTML = '<i style="width: 25px; height: 25px" class="fas fa-pause"></i>'
isPlaying = true
2023-04-29 12:43:58 +00:00
setTime()
2023-04-28 15:29:41 +00:00
} else {
2023-04-29 12:43:58 +00:00
2023-04-28 15:29:41 +00:00
play.innerHTML = '<i style="width: 25px; height: 25px" class="fas fa-play"></i>'
isPlaying = false
2023-04-29 12:43:58 +00:00
}
if(data.current && data.playing == 0) {
setTime()
2023-04-28 15:29:41 +00:00
}
2023-04-29 12:43:58 +00:00
2023-04-28 15:29:41 +00:00
2023-04-26 21:26:20 +00:00
})
ipc.on("updateData", (ev, data) => {
username.innerHTML = data.username
logo.innerHTML = "<img class='logo' src='https://cdn.discordapp.com/avatars/" + data.id + "/" + data.avatar + ".png'>"
})
signout.addEventListener("click", () => {
ipc.send("signout")
})