2020-05-12 09:48:51 +02:00
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
const { BrowserWindow, ipcRenderer, remote } = require("electron");
|
|
|
|
const axios = require("axios").default;
|
|
|
|
const path = require("path");
|
|
|
|
|
2020-05-12 19:02:20 +02:00
|
|
|
const skinview3d = require("skinview3d/dist/skinview3d.min.js");
|
|
|
|
|
2020-05-12 09:48:51 +02:00
|
|
|
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) => {
|
2020-05-12 19:02:20 +02:00
|
|
|
// 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
|
2020-05-12 09:48:51 +02:00
|
|
|
const url = JSON.parse(atob(data.data.properties[0].value)).textures.SKIN.url;
|
2020-05-12 19:02:20 +02:00
|
|
|
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;
|
|
|
|
|
2020-05-12 09:48:51 +02:00
|
|
|
|
2020-05-12 19:02:20 +02:00
|
|
|
// 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
|
2020-05-12 09:48:51 +02:00
|
|
|
document.querySelectorAll("div.content > button#download")[0].addEventListener("click", (e) => {
|
|
|
|
ipcRenderer.send("download", {
|
|
|
|
url: url,
|
|
|
|
properties: {
|
|
|
|
saveAs: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ipcRenderer.on("downloadResult", (event, arg) => {
|
2020-05-12 19:02:20 +02:00
|
|
|
var msg = document.querySelectorAll("div.content > p.message")[0];
|
2020-05-12 09:48:51 +02:00
|
|
|
console.log(msg);
|
|
|
|
msg.classList.add("success");
|
|
|
|
msg.innerHTML = "Downloaded successfully";
|
|
|
|
});
|
|
|
|
});
|
2020-05-12 19:02:20 +02:00
|
|
|
|
2020-05-12 09:48:51 +02:00
|
|
|
});
|
|
|
|
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`));
|
|
|
|
});
|