Started work on main menu

Should probably start using partials, maybe hbs
fs is causing errors
This commit is contained in:
Arne van Iterson 2020-05-10 11:04:50 +02:00
parent 7737a2645f
commit d58b37ee33
13 changed files with 3246 additions and 60 deletions

34
.eslintrc.js Normal file
View File

@ -0,0 +1,34 @@
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
]
}
};

18
auth.js
View File

@ -1,18 +0,0 @@
const axios = require("axios").default;
var payload = {
"agent": {
"name": "Minecraft",
"version": 1
},
"username": "aardtaart1@gmail.com",
"password": "IHVpep11!"
}
//payload = JSON.stringify(payload);
axios({
method: "POST",
url: "https://authserver.mojang.com/authenticate",
data: payload,
}).then();

51
css/index.css Normal file
View File

@ -0,0 +1,51 @@
body {
font-family: Arial, Helvetica, sans-serif;
text-align: center;
}
body div.content {
display: none;
}
body div.content form label {
font-size: small;
}
body div.content input, body div.content button {
margin: 0.5em;
padding: 0.25em;
}
body div.content .message {
min-width: 80%;
height: auto;
margin: 5px auto;
padding: 5px;
font-size: small;
}
body div.content .message.info {
border: 1px solid blue;
background: rgba(0, 0, 255, 0.5);
}
body div.content .message.warning {
border: 1px solid red;
background: rgba(255, 0, 0, 0.5);
}
body div.content .message.success {
border: 1px solid green;
background: rgba(0, 255, 0, 0.5);
}
body.dark {
color: #a9a9a9;
background-color: #111;
}
body.light {
color: #000;
background: #fff;
}
/*# sourceMappingURL=index.css.map */

9
css/index.css.map Normal file
View File

@ -0,0 +1,9 @@
{
"version": 3,
"mappings": "AAAA,AAAA,IAAI,CAAC;EACD,WAAW,EAAE,4BAA4B;EACzC,UAAU,EAAE,MAAM;CAwCrB;;AA1CD,AAGI,IAHA,CAGA,GAAG,AAAA,QAAQ,CAAC;EACR,OAAO,EAAE,IAAI;CA6BhB;;AAjCL,AAMY,IANR,CAGA,GAAG,AAAA,QAAQ,CAEP,IAAI,CACA,KAAK,CAAC;EACF,SAAS,EAAE,KAAK;CACnB;;AARb,AAUQ,IAVJ,CAGA,GAAG,AAAA,QAAQ,CAOP,KAAK,EAVb,IAAI,CAGA,GAAG,AAAA,QAAQ,CAOA,MAAM,CAAC;EACV,MAAM,EAAE,KAAK;EACb,OAAO,EAAE,MAAM;CAClB;;AAbT,AAcQ,IAdJ,CAGA,GAAG,AAAA,QAAQ,CAWP,QAAQ,CAAC;EACL,SAAS,EAAE,GAAG;EACd,MAAM,EAAE,IAAI;EACZ,MAAM,EAAE,QAAQ;EAChB,OAAO,EAAE,GAAG;EACZ,SAAS,EAAE,KAAK;CAanB;;AAhCT,AAoBY,IApBR,CAGA,GAAG,AAAA,QAAQ,CAWP,QAAQ,AAMH,KAAK,CAAC;EACH,MAAM,EAAE,cAAc;EACtB,UAAU,EAAE,oBAAoB;CACnC;;AAvBb,AAwBY,IAxBR,CAGA,GAAG,AAAA,QAAQ,CAWP,QAAQ,AAUH,QAAQ,CAAC;EACN,MAAM,EAAE,aAAa;EACrB,UAAU,EAAE,oBAAoB;CACnC;;AA3Bb,AA4BY,IA5BR,CAGA,GAAG,AAAA,QAAQ,CAWP,QAAQ,AAcH,QAAQ,CAAC;EACN,MAAM,EAAE,eAAe;EACvB,UAAU,EAAE,oBAAoB;CACnC;;AA/Bb,AAkCI,IAlCA,AAkCC,KAAK,CAAC;EACH,KAAK,EAAE,OAAO;EACd,gBAAgB,EAAE,IAAI;CACzB;;AArCL,AAsCI,IAtCA,AAsCC,MAAM,CAAC;EACJ,KAAK,EAAE,IAAI;EACX,UAAU,EAAE,IAAI;CACnB",
"sources": [
"index.scss"
],
"names": [],
"file": "index.css"
}

43
css/index.scss Normal file
View File

@ -0,0 +1,43 @@
body {
font-family: Arial, Helvetica, sans-serif;
text-align: center;
div.content {
display: none;
form {
label {
font-size: small;
}
}
input, button {
margin: 0.5em;
padding: 0.25em;
}
.message {
min-width: 80%;
height: auto;
margin: 5px auto;
padding: 5px;
font-size: small;
&.info {
border: 1px solid blue;
background: rgba(0, 0, 255, 0.5);
}
&.warning {
border: 1px solid red;
background: rgba(255, 0, 0, 0.5);
}
&.success {
border: 1px solid green;
background: rgba(0, 255, 0, 0.5);
}
}
}
&.dark {
color: #a9a9a9;
background-color: #111;
}
&.light {
color: #000;
background: #fff;
}
}

1
data/data.json Normal file
View File

@ -0,0 +1 @@
{"theme":"dark","user":"","password":""}

View File

50
html/index.html Normal file
View File

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SkinSwitcher</title>
<link rel="stylesheet" href="../css/index.css">
</head>
<body>
<h1><br>SkinSwitcher</h1>
<div class="content" id="mainMenu">
<button id="button_current">Current Skin</button><br>
<button id="button_upload">Upload Skin</button><br>
<button id="button_random">Random Skin</button><br>
<button id="button_delete">Logout</button>
</div>
<div class="content" id="authForm">
<form action="#">
<label for="user">Username or E-mail</label><br>
<input type="text" id="user" placeholder="Username or E-mail" required><br>
<label for="password">Password:</label><br>
<input type="password" id="password" placeholder="Password" required><br>
<label for="save">Save password:</label>
<input type="checkbox" id="save">
<p class="message info">Your password will stored in plaintext because the Mojang API requires it, do not use this option unless you are on a private computer.</p>
<button type="submit">Submit</button>
</form>
</div>
<div class="content" id="skinCurrent">
<!-- Content here -->
</div>
<div class="content" id="skinUpload">
<!-- Content here -->
</div>
<div class="content" id="loader">
<p class="message info">Loading...<br>Please wait</p>
</div>
<script src="../src/index.js"></script>
</body>
</html>

View File

@ -1,39 +0,0 @@
const axios = require("axios").default;
const fs = require("fs");
const { PNG } = require("pngjs");
var payload = {
"agent": {
"name": "Minecraft",
"version": 1
},
"username": "aardtaart1@gmail.com",
"password": "IHVpep11!"
}
//payload = JSON.stringify(payload);
axios({
method: "POST",
url: "https://authserver.mojang.com/authenticate",
data: payload,
}).then((data) => {
fs.createReadStream("in.png")
.pipe(
new PNG({
filterType: 4,
})
)
.on("parsed", (image) => {
axios({
method: "PUT",
url: `https://api.mojang.com/user/profile/${data.data.selectedProfile.id}/skin`,
data: {
model: "",
file: image
},
headers: {"Authorization": "Bearer " + data.data.accessToken}
}).catch(console.log);
});
});

68
main.js Normal file
View File

@ -0,0 +1,68 @@
const { app, BrowserWindow, ipcMain } = require("electron");
const fs = require("fs");
const path = require("path");
if (process.env.NODE_ENV === "dev") {
require("electron-reload")(__dirname, {
electron: path.join(__dirname, "node_modules", ".bin", "electron")
});
}
function createWindow () {
// Create the browser window.
const win = new BrowserWindow({
width: 320,
height: 480,
backgroundColor: "#ffffff",
resizable: false,
frame: true,
webPreferences: {
nodeIntegration: true
}
});
// and load the index.html of the app.
win.loadFile(path.join("html/index.html"));
// Open the DevTools.
if (process.env.NODE_ENV === "dev") win.webContents.openDevTools();
}
var authData = JSON.parse(fs.readFileSync("./data/data.json"));
ipcMain.on("getAuth", (event) => {
event.returnValue = authData;
});
ipcMain.on("setAuth", (event, data) => {
if (data != authData) {
// TODO: The app reloads causing a loop when fs is completed both in async and sync mode
//fs.writeFileSync("./data/data.json", JSON.stringify(data));
}
event.returnValue = true;
});
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(createWindow);
// Quit when all windows are closed.
app.on("window-all-closed", () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

2855
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,15 +2,27 @@
"name": "skinswitcher", "name": "skinswitcher",
"version": "1.0.0", "version": "1.0.0",
"description": "Javascript UI for changing your Minecraft skin using the Mojang API", "description": "Javascript UI for changing your Minecraft skin using the Mojang API",
"main": "index.js", "main": "main.js",
"scripts": { "scripts": {
"start": "node index.js" "start": "npm run lint && cross-env NODE_ENV=dev electron .",
"lint": "eslint .",
"build:all": "npm run lint && electron-builder build -mwl",
"build:win": "npm run lint && electron-builder build --windows",
"build:mac": "npm run lint && electron-builder build --mac",
"build:linux": "npm run lint && electron-builder build --linux",
"postinstall": "electron-builder install-app-deps"
}, },
"keywords": [], "keywords": [],
"author": "Arne van Iterson", "author": "Arne van Iterson",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"axios": "^0.19.2" "axios": "^0.19.2",
"cross-env": "^7.0.2",
"electron": "^8.2.5",
"electron-builder": "^22.6.0",
"electron-reload": "^1.5.0",
"eslint": "^7.0.0",
"pngjs": "^5.0.0"
}, },
"devDependencies": {}, "devDependencies": {},
"repository": { "repository": {

120
src/index.js Normal file
View File

@ -0,0 +1,120 @@
/* eslint-disable no-unused-vars */
const { ipcRenderer } = require("electron");
const axios = require("axios").default;
const fs = require("fs");
const { PNG } = require("pngjs");
// Read auth data from storage and define variables
var authData = ipcRenderer.sendSync("getAuth");
var token;
var save = true;
// Set theme
document.body.classList.add(authData.theme);
// Function for easy switching between views
function setContent(id, message) {
document.querySelectorAll("div.content").forEach((element) => {
element.style.display = "none";
});
const element = document.querySelectorAll(`div.content#${id}`)[0];
if (message) {
var msg;
if (element.firstElementChild.classList.contains("message")) {
msg = element.firstElementChild;
} else {
msg = document.createElement("p");
}
msg.classList = `message ${message.type}`;
msg.innerHTML = message.text;
element.prepend(msg);
}
element.style.display = "block";
}
setContent("loader");
async function authenticate(user, password) {
var payload = {
"agent": {
"name": "Minecraft",
"version": 1
},
"username": user,
"password": password
};
axios({
method: "POST",
url: "https://authserver.mojang.com/authenticate",
data: payload,
}).then((data) => {
console.log("Login successfull");
token = data.data;
// Save username (& password) for future login
authData.user = user;
authData.password = (save) ? password : "";
if (ipcRenderer.sendSync("setAuth", authData)) {
setContent(
"mainMenu",
{
type: "success",
text: `Logged in as ${data.data.selectedProfile.name}`
}
);
}
}).catch((data) => {
console.log("Login failure");
console.log(data.response);
setContent(
"authForm",
{
type: "warning",
text: `Login failed<br>${data.response.data.errorMessage}`
}
);
});
}
// Get access token from Mojang Authserver
if (authData.password == "") {
// Display auth screen when no password data is found
const form = document.querySelectorAll("div.content#authForm")[0];
form.querySelectorAll("input#user")[0].value = authData.user;
setContent("authForm");
// Listen for form submit
form.addEventListener("submit", function(e) {
e.preventDefault();
authData.user = form.querySelectorAll("input#user")[0].value;
authData.password = form.querySelectorAll("input#password")[0].value;
save = form.querySelectorAll("input#save")[0].checked;
setContent("loader");
authenticate(authData.user, authData.password);
});
} else {
authenticate(authData.user, authData.password);
}
//fs.createReadStream("../data/in.png")
// .pipe(
// new PNG({
// filterType: 4,
// })
// )
// .on("parsed", (image) => {
// axios({
// method: "PUT",
// url: `https://api.mojang.com/user/profile/${data.data.selectedProfile.id}/skin`,
// data: {
// model: "",
// file: image
// },
// headers: {"Authorization": "Bearer " + data.data.accessToken}
// }).catch(console.log);
// });