diff --git a/src/main.js b/src/main.js index aa278dd..6403c86 100644 --- a/src/main.js +++ b/src/main.js @@ -45,6 +45,40 @@ function createMainWindow() { }); } +function fetchPlutoniumManifest() { + return new Promise(function (resolve, reject) { + let request = https.request("https://cdn.plutonium.pw/updater/prod/info.json", { + "method": "GET" + }, function (response) { + if (response.statusCode !== 200) { + return reject(new Error("Failed to fetch the Plutonium launcher manifest.")); + } + + response.setEncoding("utf-8"); + + let body = ""; + response.on("data", function (chunk) { + body += chunk; + }); + response.on("end", function () { + try { + let data = JSON.parse(body); + + resolve(data); + } catch (error) { + reject(error); + } + }); + }); + + request.on("error", function (error) { + reject(error); + }); + + request.end(); + }); +} + electron.app.once("ready", function () { createMainWindow(); }); @@ -52,3 +86,59 @@ electron.app.once("ready", function () { electron.app.on("window-all-closed", function () { electron.app.quit(); }); + +electron.ipcMain.handle("login", function (event, username, password) { + return new Promise(function (resolve, reject) { + let payload = JSON.stringify({ + "username": username, + "password": password + }); + + let request = https.request("https://nix.plutonium.pw/api/auth/login", { + "method": "POST", + "headers": { + "Content-Type": "application/json", + "Content-Length": payload.length, + "Authorization": "UserToken", + "X-Plutonium-Revision": String(plutoniumManifest.revision), + "User-Agent": "Nix/3.0" + } + }, function (response) { + if (response.statusCode !== 200) { + return resolve({ + "status": "unauthenticated" + }); + } + + response.setEncoding("utf-8"); + + let body = ""; + response.on("data", function (chunk) { + body += chunk; + }); + response.on("end", function () { + try { + let data = JSON.parse(body); + + if (!("token" in data)) { + reject(new Error("Login seems to be successful but no token was returned.")); + } + + resolve({ + "status": "authenticated", + ...data + }); + } catch (error) { + reject(error); + } + }); + }); + + request.on("error", function (error) { + reject(error); + }); + + request.write(payload); + request.end(); + }); +}); diff --git a/src/styles/common.css b/src/styles/common.css index 00cf87c..86f9297 100644 --- a/src/styles/common.css +++ b/src/styles/common.css @@ -1,4 +1,12 @@ :root { background-color: #181820; color: #F8F8FC; + width: 100%; + height: 100%; +} + +body, main { + margin: 0px; + width: 100%; + height: 100%; } diff --git a/src/styles/login.css b/src/styles/login.css new file mode 100644 index 0000000..2e09409 --- /dev/null +++ b/src/styles/login.css @@ -0,0 +1,10 @@ +#login-container { + width: 256px; + height: 384px; + margin: auto; +} + +#login-form { + display: flex; + flex-direction: column; +} diff --git a/src/views/login.html b/src/views/login.html index a045baa..3277197 100644 --- a/src/views/login.html +++ b/src/views/login.html @@ -4,12 +4,13 @@ Open Plutonium Launcher +
-
-
+
+