70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
const { BrowserWindow, app, net, dialog } = require("electron")
|
|
const hwid = require("./modules/hwid")
|
|
const path = require("node:path")
|
|
const config = require("./config.json")
|
|
let launcherWindow
|
|
|
|
async function createLauncherWindow() {
|
|
if (net.isOnline()) {
|
|
const isLauncherNotBanned = await checkIfIAmBanned()
|
|
launcherWindow = new BrowserWindow({
|
|
frame: false,
|
|
width: 900,
|
|
height: 600,
|
|
minWidth: 900,
|
|
minHeight: 600,
|
|
titleBarStyle: "hidden",
|
|
autoHideMenuBar: true,
|
|
roundedCorners: false,
|
|
resizable: false,
|
|
webPreferences: {
|
|
nodeIntegration: false,
|
|
contextIsolation: true,
|
|
preload: path.join(__dirname, "app", "index.html")
|
|
}
|
|
})
|
|
if (isLauncherNotBanned.success) {
|
|
launcherWindow.loadFile(path.join(__dirname, "app", "index.html"))
|
|
} else {
|
|
launcherWindow.loadFile(path.join(__dirname, "app", "banned.html"))
|
|
launcherWindow.webContents.executeJavaScript(`
|
|
setBannedBy("${isLauncherNotBanned.banned_by}")
|
|
setBannedAt("${isLauncherNotBanned.banned_at}")
|
|
setBannedBecause("${isLauncherNotBanned.reason}")
|
|
`)
|
|
}
|
|
} else {
|
|
dialog.showErrorBox("Le launcher requiert une connexion internet.")
|
|
}
|
|
}
|
|
|
|
async function checkIfIAmBanned() {
|
|
if (net.isOnline()) {
|
|
try {
|
|
const reponse = await fetch(config, {
|
|
body: JSON.stringify({
|
|
hwid: hwid.getHWID()
|
|
})
|
|
})
|
|
const json = await reponse.json()
|
|
return json
|
|
} catch (error) {
|
|
dialog.showErrorBox("Impossible de contacter l'API, fermeture du launcher.")
|
|
console.error(error)
|
|
app.exit()
|
|
}
|
|
} else {
|
|
dialog.showErrorBox("Le launcher requiert une connexion internet.")
|
|
}
|
|
}
|
|
|
|
app.whenReady().then(() => {
|
|
createLauncherWindow()
|
|
app.on("activate", async () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) await createLauncherWindow()
|
|
})
|
|
})
|
|
|
|
app.on("window-all-closed", () => {
|
|
app.quit()
|
|
}) |