Compare commits

...

2 Commits

Author SHA1 Message Date
0a664d1f64 add tray icon, fix login if password changed 2023-05-31 07:02:05 +02:00
232043d686 remove old launcher design 2023-05-31 07:01:33 +02:00
4 changed files with 56 additions and 69 deletions

43
app.js
View File

@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const { app, BrowserWindow, ipcMain, dialog, Tray, Menu } = require('electron');
const { setupTitlebar, attachTitlebarToWindow } = require('custom-electron-titlebar/main');
const windowManager = require('./ui/windowManager');
const osuUtil = require('./osuUtil');
@ -9,6 +9,7 @@ const rpc = require('./discordPresence');
const windowName = require('get-window-by-name');
const terminalUtil = require('./terminalUtil');
const osUtil = require('./osUtil');
const appInfo = require('./appInfo');
let tempOsuPath;
let osuWindowInfo;
@ -119,10 +120,37 @@ const run = () => {
let mainWindow;
let tray = null
app.whenReady().then(() => {
tray = new Tray('./assets/logo.png');
const trayMenuTemplate = [
{
label: `EZPPLauncher ${appInfo.appVersion}`,
enabled: false
},
{
label: "Show/Hide",
click: function () {
if (mainWindow.isVisible()) mainWindow.hide();
else mainWindow.show();
}
},
{
label: 'Exit',
click: function () {
app.exit(0);
}
}
]
let trayMenu = Menu.buildFromTemplate(trayMenuTemplate)
tray.setContextMenu(trayMenu)
mainWindow = createWindow();
mainWindow.on('show', async () => {
mainWindow.once('show', async () => {
await updateConfigVars(mainWindow);
await tryLogin(mainWindow);
await doUpdateCheck(mainWindow);
@ -161,7 +189,7 @@ const run = () => {
const osuFolder = await config.get("osuPath");
if (!osuFolder || osuFolder == "") {
const foundFolder = await osuUtil.findOsuInstallation();
console.log("osu! Installation located at: ",foundFolder);
console.log("osu! Installation located at: ", foundFolder);
}
}
})
@ -187,10 +215,10 @@ const run = () => {
}
rpc.updateState("Launching osu!...");
isIngame = true;
mainWindow.hide();
if (mainWindow.isVisible()) mainWindow.hide();
const result = await osuUtil.startOsuWithDevServer(tempOsuPath, "ez-pp.farm", async () => {
isIngame = false;
mainWindow.show();
if (!mainWindow.isVisible()) mainWindow.show();
await doUpdateCheck(mainWindow);
});
return result;
@ -287,8 +315,11 @@ async function tryLogin(window) {
user: loginResponse.user
})
} else {
await config.remove("username");
await config.remove("password");
window.webContents.send('account_update', {
type: "login-failed"
type: "login-failed",
message: loginResponse.message
})
}
} else {

View File

@ -1,10 +1,18 @@
const axios = require('axios').default;
const loginCheckEndpoint = 'https://ez-pp.farm/login/check';
let retries = 0;
const performLogin = async (username, password) => {
const result = await axios.post(loginCheckEndpoint, { username, password });
const code = result.data.code ?? 404;
if (code === 200 || code === 403) {
retries = 0;
return result.data;
} else {
if (retries++ >= 5) return { code: 403, message: "Login failed." }
return await performLogin(username, password);
}
}
module.exports = { performLogin };

View File

@ -1,62 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>EZPPLauncher</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/png" href="../assets/logo.png" />
<link href="../assets/mdb.min.css" rel="stylesheet" />
<style>
* {
user-select: none;
-webkit-user-select: none;
}
</style>
</head>
<body class="fixed-sn mdb-skin-custom" data-spy="scroll" data-target="#scrollspy" data-offset="15"
oncontextmenu="return false;">
<main>
<div class="noselect">
<div class="position-relative overflow-hidden p-3 p-md-5 m-md-3 text-center text-lg-end d-flex align-items-center justify-content-center"
style="border-radius: 0.5em;">
<div class="position-relative overflow-hidden p-3 p-md-5 m-md-3">
<div class="container py-2 h-100">
<div class="row d-flex justify-content-center align-items-center h-100">
<div class="col col-xl-10">
<div class="card" style="border-radius: 1rem;">
<div class="row g-0">
<div class="card-body p-4 p-lg-5 text-black">
<div class="d-flex align-items-center mb-2 pb-1 text-white">
<span class="h1 fw-bold mb-0">EZPPLauncher</span>
</div>
<h5 class="fw-lighter fs-5 mb-3 pb-3 text-white text-start"
style="letter-spacing: 1px;">
Launch osu! with connection to the EZPPFarm server
</h5>
<div class="pt-1 mb-4">
<button id="launch-btn" class="btn btn-primary btn-lg btn-block"
type="button" style="background-color:#d6016f" disabled>Looking for
updates...</button>
</div>
<button class="btn btn-dark btn-sm float-start" id="account-btn" disabled>
set account
</button>
<button class="btn btn-dark btn-sm float-end" id="folder-btn">
set osu! directory
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
</body>
<script type="text/javascript" src="../assets/mdb.min.js"></script>
</html>

View File

@ -152,6 +152,16 @@ window.addEventListener('DOMContentLoaded', () => {
ipcRenderer.on('account_update', (event, data) => {
switch (data.type) {
case "login-failed":
console.log(data);
Swal.fire({
title: 'Uh oh!',
text: data.message,
icon: 'error',
confirmButtonText: 'Okay'
});
changePage("launch");
break;
case "not-loggedin":
changePage("launch");
break;