/* eslint-disable no-unused-vars */ const { BrowserWindow, ipcRenderer, remote } = require("electron"); const axios = require("axios").default; const path = require("path"); const skinview3d = require("skinview3d/dist/skinview3d.min.js"); const session = ipcRenderer.sendSync("getSession"); if (!session.accessToken) { console.log("Session does not exist, return to auth"); remote.getCurrentWindow().loadURL(path.join(`file://${__dirname}/auth.hbs`)); } else { console.log("Session does exist, continue"); } const regex = /(?!\w*_)\w*(?=\.\w*)/g; var action = __filename.match(regex)[0]; switch (action) { case "current": axios({ method: "GET", url: "https://sessionserver.mojang.com/session/minecraft/profile/" + session.selectedProfile.id }).then((data) => { // Switch button and views var btn = document.querySelectorAll("div.content > button#switch")[0]; var view = { flat: document.querySelectorAll("div.content > img.skin#flat")[0], mesh: document.querySelectorAll("div.content > div#mesh")[0] }; // Set flat view const url = JSON.parse(atob(data.data.properties[0].value)).textures.SKIN.url; view.flat.src = url; // Set mesh view let skinViewer = new skinview3d.SkinViewer({ domElement: view.mesh, width: 200, height: 200, skinUrl: url }); let control = skinview3d.createOrbitControls(skinViewer); control.enableRotate = true; control.enableZoom = false; control.enablePan = false; // Switch button action btn.addEventListener("click", (e) => { console.log("Switch button clicked"); if (view.flat.style.display == "inline") { view.flat.style.display = "none"; view.mesh.style.display = "inline"; btn.innerHTML = "Switch to 2D"; } else { view.flat.style.display = "inline"; view.mesh.style.display = "none"; btn.innerHTML = "Switch to 3D"; } }); // Download button action document.querySelectorAll("div.content > button#download")[0].addEventListener("click", (e) => { ipcRenderer.send("download", { url: url, properties: { saveAs: true } }); ipcRenderer.on("downloadResult", (event, arg) => { var msg = document.querySelectorAll("div.content > p.message")[0]; console.log(msg); msg.classList.add("success"); msg.innerHTML = "Downloaded successfully"; }); }); }); break; case "upload": break; case "random": break; } document.querySelectorAll("div.content > button#main")[0].addEventListener("click", (e) => { remote.getCurrentWindow().loadURL(path.join(`file://${__dirname}/main.hbs`)); });