4
0
mirror of https://github.com/AltarikMC/Launcher synced 2025-12-13 11:41:45 +00:00

add support to microsoft auth (untested cause I haven't minecraft on a microsoft account)

This commit is contained in:
2021-08-10 20:35:13 +02:00
parent 2105ebb88a
commit cac1afbd31
7 changed files with 121 additions and 133 deletions

View File

@@ -20,7 +20,7 @@ body{
height:100%;
}
#login {
#content > * {
position:relative;
width: 300px;
top:50%;
@@ -30,6 +30,11 @@ body{
padding: 8px;
}
#microsoft-button {
border-width: 0;
cursor: pointer;
}
#login input[type="text"],
#login input[type="password"]{
width:100%;

View File

@@ -1,25 +1,36 @@
const form = document.querySelector('#login-form')
const user = document.querySelector('#nickname')
const password = document.querySelector('#password')
const microsoftButton = document.querySelector("#microsoft-button")
form.addEventListener("submit", (e) => {
e.preventDefault()
form.disabled = true
if(user.value) {
ipcRenderer.send("login", {
user: user.value,
pass: password.value
})
}else{
ipcRenderer.send("notification", {
title: "error",
body: "Veuillez entrer des identifiants"
})
if(!microsoftButton.disabled) {
form.disabled = true
if(user.value) {
ipcRenderer.send("login", {
user: user.value,
pass: password.value
})
}else{
ipcRenderer.send("notification", {
title: "error",
body: "Veuillez entrer des identifiants"
})
}
}
})
microsoftButton.addEventListener("click", (e) => {
e.preventDefault()
if(!form.disabled) {
microsoftButton.disabled = true
form.disabled = true
ipcRenderer.send("microsoft-login")
}
})
ipcRenderer.on("loginError", event => {
form.disabled = false
microsoftButton.disabled = false
})

View File

@@ -30,6 +30,7 @@
<input type="submit" value="Se connecter">
</form>
</div>
<button id="microsoft-button">Connexion avec un compte Microsoft</button>
</div>
<script src="assets/js/script.js"></script>

View File

@@ -2,9 +2,9 @@ const { app, BrowserWindow, Menu, ipcMain, Notification, autoUpdater, dialog } =
const logger = require('electron-log')
const { join } = require('path')
if (require('electron-squirrel-startup')) {
require("./install.js").handleSquirrelEvent(app)
app.quit()
return;
require("./install.js").handleSquirrelEvent(app)
app.quit()
return
}
require('./updater.js').configUpdater(app, autoUpdater, dialog, logger)
@@ -14,22 +14,25 @@ const iconPath = join(__dirname, "icon.ico")
let win = null
function createWindow () {
win = new BrowserWindow({
width: 1000,
minWidth: 1000,
maxWidth: 1000,
height: 600,
minHeight: 600,
maxHeight: 600,
icon: iconPath,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
frame: false,
})
// Menu.setApplicationMenu(null)
win.loadFile('src/client/login.html')
win = new BrowserWindow({
width: 1000,
minWidth: 1000,
maxWidth: 1000,
height: 600,
minHeight: 600,
maxHeight: 600,
icon: iconPath,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
frame: false,
})
// Menu.setApplicationMenu(null)
win.loadFile('src/client/login.html')
win.on("close", () => {
app.quit()
})
}
const { setWindow, minimizeWindow, closeWindow } = require("./menubar.js");
@@ -37,33 +40,37 @@ const { setWindow, minimizeWindow, closeWindow } = require("./menubar.js");
setWindow(win)
app.whenReady().then(() => {
createWindow()
createWindow()
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
if (process.platform !== 'darwin') {
app.quit()
}
})
ipcMain.on('minimizeWindow', () => {
minimizeWindow(win)
minimizeWindow(win)
})
ipcMain.on('closeWindow', () => {
closeWindow(win)
closeWindow(win)
})
app.on('activate', () => {
if (win === null){
createWindow()
}
if (win === null){
createWindow()
}
})
ipcMain.on("login", (event, args) => {
minecraft.login(event, win, showNotification, args.user, args.pass)
})
ipcMain.on("microsoft-login", (event, args) => {
minecraft.microsoftLogin(event, win, showNotification)
})
ipcMain.on("invalidateData", event => {
minecraft.invalidateData(event)
})
@@ -73,15 +80,15 @@ ipcMain.on("launch", (event, args) => {
})
function showNotification(title, body="") {
new Notification({ title: title, body: body }).show()
new Notification({ title: title, body: body }).show()
}
ipcMain.on("notification", (event, args) => {
showNotification(args.title, args.body)
showNotification(args.title, args.body)
})
ipcMain.on("disconnect", (e) => {
win.loadFile('src/client/login.html')
win.loadFile('src/client/login.html')
})

View File

@@ -3,10 +3,11 @@ const { Client, Authenticator } = require('minecraft-launcher-core')
const axios = require('axios').default
const hasha = require('hasha');
const fs = require('fs')
const { join, resolve } = require('path')
const { join } = require('path')
const constants = require("constants")
const zip = require('extract-zip')
const logger = require('electron-log')
const msmc = require('msmc')
class Minecraft {
@@ -16,6 +17,9 @@ class Minecraft {
auth = null
modsList = undefined
/**
* Used to login through Mojang account
*/
login(event, win, showNotification, username, password) {
this.auth = null
if(isDev || password.trim() !== "") {
@@ -34,6 +38,42 @@ class Minecraft {
}
}
/**
* Used to login through a Microsoft account
*/
microsoftLogin(event, win, showNotification) {
msmc.getElectron().FastLaunch(
(callback) => {
this.auth = msmc.getMCLC().getAuth(callback)
this.auth.then(v => {
win.loadFile('src/client/index.html').then(() => {
event.sender.send("nick", { name: v.name })
})
}).catch((err) => {
event.sender.send("loginError")
logger.error(err)
showNotification("Erreur de connexion")
})
},
(update) => {
switch (update.type) {
case "Rejection":
event.sender.send("loginError")
showNotification("Connexion rejetée")
logger.error("Fetch rejected!", update.data);
break;
case "Error":
event.sender.send("loginError")
showNotification("Une erreur est survenue", update.data)
logger.error("MC-Account error:", update.data);
break;
case "Cancelled":
logger.warn("Connexion annulée");
event.sender.send("loginError")
}
}, "login")
}
launch(event, showNotification, args) {
this.extractJava(Number(args.chapter), event).then((javaPath) => {
this.extractMods(Number(args.chapter), event).then((chapter) => {