Added function to menu buttons and download option

This commit is contained in:
Arne van Iterson 2020-05-12 09:48:51 +02:00
parent 52f3cd1f15
commit 9dd358e097
12 changed files with 232 additions and 1 deletions

View File

@ -48,6 +48,16 @@ body div.content .message.success {
background: rgba(0, 255, 0, 0.5);
}
body div.content img.skin {
width: 60%;
padding: 0 1em 1em 1em;
-ms-interpolation-mode: nearest-neighbor;
image-rendering: -webkit-optimize-contrast;
image-rendering: -moz-crisp-edges;
image-rendering: -o-pixelated;
image-rendering: pixelated;
}
body.dark {
color: #a9a9a9;
background-color: #111;

View File

@ -1,6 +1,6 @@
{
"version": 3,
"mappings": "AAAA,AAAA,IAAI,CAAC;EACD,WAAW,EAAE,4BAA4B;EACzC,UAAU,EAAE,MAAM;CA4DrB;;AA9DD,AAIQ,IAJJ,CAGA,MAAM,CACF,EAAE,CAAC;EACC,aAAa,EAAE,CAAC;CACnB;;AANT,AAOQ,IAPJ,CAGA,MAAM,CAIF,EAAE,CAAC;EACC,MAAM,EAAE,CAAC;CACZ;;AATT,AAaY,IAbR,CAWA,GAAG,AAAA,QAAQ,CACP,IAAI,CACA,KAAK,CAAC;EACF,SAAS,EAAE,KAAK;CACnB;;AAfb,AAiBQ,IAjBJ,CAWA,GAAG,AAAA,QAAQ,CAMP,KAAK,EAjBb,IAAI,CAWA,GAAG,AAAA,QAAQ,CAMA,MAAM,CAAC;EACV,MAAM,EAAE,KAAK;EACb,OAAO,EAAE,MAAM;CAClB;;AApBT,AAqBQ,IArBJ,CAWA,GAAG,AAAA,QAAQ,CAUP,MAAM,CAAC;EACH,KAAK,EAAE,GAAG;CACb;;AAvBT,AAwBQ,IAxBJ,CAWA,GAAG,AAAA,QAAQ,CAaP,QAAQ,CAAC;EACL,SAAS,EAAE,GAAG;EACd,MAAM,EAAE,IAAI;EACZ,MAAM,EAAE,QAAQ;EAChB,OAAO,EAAE,GAAG;EACZ,SAAS,EAAE,KAAK;EAChB,KAAK,EAAE,KAAK;CAaf;;AA3CT,AA+BY,IA/BR,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EACX,MAAM,EAAE,IAAI;EACZ,QAAQ,EAAE,QAAQ;EAClB,MAAM,EAAE,CAAC;EACT,IAAI,EAAE,CAAC;EACP,UAAU,EAAE,MAAM;CACrB",
"sources": [
"index.scss"
],

View File

@ -42,6 +42,11 @@ body {
background: rgba(0, 255, 0, 0.5);
}
}
img.skin {
width: 60%;
padding: 0 1em 1em 1em;
image-rendering: pixelated;
}
}
&.dark {
color: #a9a9a9;

29
html/skin_current.hbs Normal file
View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title>
<link rel="stylesheet" href="{{ css }}">
</head>
<body class="{{ theme }}">
<header>
<h1>{{ header }}</h1>
<h3>Current Skin</h3>
</header>
<div class="content">
<p class="message"></p>
<img src="" class="skin" alt="Current Skin">
<button id="render">Switch to 3D</button>
<button id="download">Download</button>
<button id="main">Back</button>
</div>
<script src="../src/skin.js"></script>
<footer>
{{ footer }}
</footer>
</body>
</html>

25
html/skin_random.hbs Normal file
View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title>
<link rel="stylesheet" href="{{ css }}">
</head>
<body class="{{ theme }}">
<header>
<h1>{{ header }}</h1>
<h3>Random Skin</h3>
</header>
<div class="content" id="current">
</div>
<script src="../src/skin.js"></script>
<footer>
{{ footer }}
</footer>
</body>
</html>

28
html/skin_upload.hbs Normal file
View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }}</title>
<link rel="stylesheet" href="{{ css }}">
</head>
<body class="{{ theme }}">
<header>
<h1>{{ header }}</h1>
<h3>Upload Skin</h3>
</header>
<div class="content" id="current">
<form action="#">
<input type="file" id="skin">
<button type="submit">Submit</button>
</form>
</div>
<script src="../src/skin.js"></script>
<footer>
{{ footer }}
</footer>
</body>
</html>

View File

@ -1,4 +1,5 @@
const { app, BrowserWindow, ipcMain } = require("electron");
const { download } = require("electron-dl");
const fs = require("fs");
const path = require("path");
@ -54,6 +55,11 @@ ipcMain.on("setAuth", (event, data) => {
event.returnValue = true;
});
ipcMain.on("download", (event, info) => {
download(BrowserWindow.getFocusedWindow(), info.url, info.properties)
.then(dl => event.reply("downloadResult", dl.getSavePath()));
});
// Create session variables for uuid storage
var session = {};

67
package-lock.json generated
View File

@ -1016,6 +1016,16 @@
}
}
},
"electron-dl": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/electron-dl/-/electron-dl-3.0.0.tgz",
"integrity": "sha512-TeBRv+vQgNVLGf/XLV4EYfYIBMI4TQcw84aDlM8xEm/1Lgxux3PUXDzaingivf+6jMvRojXSRPTHmiWI/6LrqQ==",
"requires": {
"ext-name": "^5.0.0",
"pupa": "^2.0.1",
"unused-filename": "^2.1.0"
}
},
"electron-handlebars": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/electron-handlebars/-/electron-handlebars-2.0.0.tgz",
@ -1253,6 +1263,23 @@
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",
"integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g=="
},
"ext-list": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/ext-list/-/ext-list-2.2.2.tgz",
"integrity": "sha512-u+SQgsubraE6zItfVA0tBuCBhfU9ogSRnsvygI7wht9TS510oLkBRXBsqopeUG/GBOIQyKZO9wjTqIu/sf5zFA==",
"requires": {
"mime-db": "^1.28.0"
}
},
"ext-name": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/ext-name/-/ext-name-5.0.0.tgz",
"integrity": "sha512-yblEwXAbGv1VQDmow7s38W77hzAgJAO50ztBLMcUyUBfxv1HC+LGwtiEN+Co6LtlqT/5uwVOxsD4TNIilWhwdQ==",
"requires": {
"ext-list": "^2.0.0",
"sort-keys-length": "^1.0.0"
}
},
"external-editor": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.1.0.tgz",
@ -1728,6 +1755,11 @@
"resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.2.tgz",
"integrity": "sha512-/2UGPSgmtqwo1ktx8NDHjuPwZWmHhO+gj0f93EkhLB5RgW9RZevWYYlIkS6zePc6U2WpOdQYIwHe9YC4DWEBVg=="
},
"is-plain-obj": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz",
"integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4="
},
"is-typedarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
@ -1917,6 +1949,11 @@
"resolved": "https://registry.npmjs.org/mime/-/mime-2.4.5.tgz",
"integrity": "sha512-3hQhEUF027BuxZjQA3s7rIv/7VCQPa27hN9u9g87sEkWaKwQPuXOkVKtOeiyUrnWqTDiOs8Ed2rwg733mB0R5w=="
},
"mime-db": {
"version": "1.44.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz",
"integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg=="
},
"mimic-fn": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",
@ -1948,6 +1985,11 @@
"minimist": "^1.2.5"
}
},
"modify-filename": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/modify-filename/-/modify-filename-1.1.0.tgz",
"integrity": "sha1-mi3sg4Bvuy2XXyK+7IWcoms5OqE="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
@ -2437,6 +2479,22 @@
}
}
},
"sort-keys": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-1.1.2.tgz",
"integrity": "sha1-RBttTTRnmPG05J6JIK37oOVD+a0=",
"requires": {
"is-plain-obj": "^1.0.0"
}
},
"sort-keys-length": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/sort-keys-length/-/sort-keys-length-1.0.1.tgz",
"integrity": "sha1-nLb09OnkgVWmqgZx7dM2/xR5oYg=",
"requires": {
"sort-keys": "^1.0.0"
}
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
@ -2710,6 +2768,15 @@
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
},
"unused-filename": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/unused-filename/-/unused-filename-2.1.0.tgz",
"integrity": "sha512-BMiNwJbuWmqCpAM1FqxCTD7lXF97AvfQC8Kr/DIeA6VtvhJaMDupZ82+inbjl5yVP44PcxOuCSxye1QMS0wZyg==",
"requires": {
"modify-filename": "^1.1.0",
"path-exists": "^4.0.0"
}
},
"update-notifier": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/update-notifier/-/update-notifier-4.1.0.tgz",

View File

@ -20,6 +20,7 @@
"cross-env": "^7.0.2",
"electron": "^8.2.5",
"electron-builder": "^22.6.0",
"electron-dl": "^3.0.0",
"electron-handlebars": "^2.0.0",
"electron-reload": "^1.5.0",
"eslint": "^7.0.0",

View File

@ -17,14 +17,17 @@ msg.innerHTML = `Logged in as ${session.selectedProfile.name}`;
document.querySelectorAll("div.content > button#current")[0].addEventListener("click", (e) => {
console.log("Clicked current button");
remote.getCurrentWindow().loadURL(path.join(`file://${__dirname}/skin_current.hbs`));
});
document.querySelectorAll("div.content > button#upload")[0].addEventListener("click", (e) => {
console.log("Clicked upload button");
remote.getCurrentWindow().loadURL(path.join(`file://${__dirname}/skin_upload.hbs`));
});
document.querySelectorAll("div.content > button#random")[0].addEventListener("click", (e) => {
console.log("Clicked random button");
remote.getCurrentWindow().loadURL(path.join(`file://${__dirname}/skin_random.hbs`));
});
document.querySelectorAll("div.content > button#logout")[0].addEventListener("click", (e) => {

57
src/skin.js Normal file
View File

@ -0,0 +1,57 @@
/* eslint-disable no-unused-vars */
const { BrowserWindow, ipcRenderer, remote } = require("electron");
const axios = require("axios").default;
const path = require("path");
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) => {
const url = JSON.parse(atob(data.data.properties[0].value)).textures.SKIN.url;
document.querySelectorAll("div.content > img.skin")[0].src = url;
document.querySelectorAll("div.content > button#download")[0].addEventListener("click", (e) => {
ipcRenderer.send("download", {
url: url,
properties: {
saveAs: true
}
});
ipcRenderer.on("downloadResult", (event, arg) => {
const msg = document.querySelectorAll("div.content > p.message")[0];
console.log(msg);
msg.classList.add("success");
msg.innerHTML = "Downloaded successfully";
});
});
document.querySelectorAll("div.content > button#render")[0].addEventListener("click", (e) => {
console.log("Switch to 3D clicked");
});
});
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`));
});