10 Commits
1.1.2 ... 1.1.4

Author SHA1 Message Date
769a88521e fix tray logo 2023-06-02 12:42:12 +02:00
f5287b6378 bump back version, apply fix version to appinfo 2023-06-02 12:30:57 +02:00
dd6866f680 change exe output file 2023-06-02 12:29:21 +02:00
cb1a05d58c titlebar fixes 2023-06-02 12:22:28 +02:00
fdfedab77f add update checking using gitea api 2023-05-31 19:03:11 +02:00
fc284e08f0 remove unused imports 2023-05-31 19:02:06 +02:00
361db1df17 bump version 2023-05-31 07:05:34 +02:00
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
10a4c540dd remove arm from build script 2023-05-04 22:04:02 +02:00
9 changed files with 630 additions and 598 deletions

659
app.js
View File

@@ -1,14 +1,17 @@
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 { setupTitlebar } = require('custom-electron-titlebar/main');
const windowManager = require('./ui/windowManager'); const windowManager = require('./ui/windowManager');
const osuUtil = require('./osuUtil'); const osuUtil = require('./osuUtil');
const ezppUtil = require('./ezppUtil'); const ezppUtil = require('./ezppUtil');
const config = require('./config'); const config = require('./config');
const fs = require('fs'); const fs = require('fs');
const path = require('path');
const rpc = require('./discordPresence'); const rpc = require('./discordPresence');
const windowName = require('get-window-by-name'); const windowName = require('get-window-by-name');
const terminalUtil = require('./terminalUtil'); const terminalUtil = require('./terminalUtil');
const osUtil = require('./osUtil'); const osUtil = require('./osUtil');
const appInfo = require('./appInfo');
const { DownloaderHelper } = require('node-downloader-helper');
let tempOsuPath; let tempOsuPath;
let osuWindowInfo; let osuWindowInfo;
@@ -18,336 +21,376 @@ let linuxWMCtrlFound = false;
let osuLoaded = false; let osuLoaded = false;
const run = () => { const run = () => {
const gotTheLock = app.requestSingleInstanceLock() const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) { if (!gotTheLock) {
app.quit(); app.quit();
return;
}
setInterval(async () => {
if (platform == "win32") {
osuWindowInfo = windowName.getWindowText("osu!.exe");
const firstInstance = osuWindowInfo[0];
if (firstInstance) {
if (firstInstance.processTitle && firstInstance.processTitle.length > 0) {
if (!osuLoaded) {
osuLoaded = true;
//TODO: do patch
}
const windowTitle = firstInstance.processTitle;
let rpcOsuVersion = "";
let currentMap = undefined;
if (!windowTitle.includes("-")) {
rpcOsuVersion = windowTitle;
rpc.updateState("Idle...");
} else {
var string = windowTitle;
var components = string.split(' - ');
const splitArray = [components.shift(), components.join(' - ')];
rpcOsuVersion = splitArray[0];
currentMap = splitArray[1];
if (currentMap.endsWith(".osu")) {
rpc.updateState("Editing...");
currentMap = currentMap.substring(0, currentMap.length - 4);
} else rpc.updateState("Playing...");
}
rpc.updateStatus(currentMap, rpcOsuVersion);
} else {
if (osuLoaded) osuLoaded = false;
rpc.updateState("Idle in Launcher...");
rpc.updateStatus(undefined, undefined);
}
} else {
if (osuLoaded) osuLoaded = false;
rpc.updateState("Idle in Launcher...");
rpc.updateStatus(undefined, undefined);
}
} else if (platform == "linux") {
if (!linuxWMCtrlFound) {
if (isIngame) {
rpc.updateState("Playing...");
rpc.updateStatus("Clicking circles!", "runningunderwine");
} else {
rpc.updateState("Idle in Launcher...");
rpc.updateStatus(undefined, undefined);
}
return; return;
} }
const processesOutput = await terminalUtil.execCommand(`wmctrl -l|awk '{$3=""; $2=""; $1=""; print $0}'`);
setInterval(async () => { const allLines = processesOutput.split("\n");
if (platform == "win32") { const filteredProcesses = allLines.filter((line) => line.trim().startsWith("osu!"));
osuWindowInfo = windowName.getWindowText("osu!.exe"); if (filteredProcesses.length > 0) {
const firstInstance = osuWindowInfo[0]; const windowTitle = filteredProcesses[0].trim();
if (firstInstance) { let rpcOsuVersion = "";
if (firstInstance.processTitle && firstInstance.processTitle.length > 0) { let currentMap = undefined;
if (!osuLoaded) { if (!windowTitle.includes("-")) {
osuLoaded = true; rpcOsuVersion = windowTitle;
//TODO: do patch rpc.updateState("Idle...");
}
const windowTitle = firstInstance.processTitle;
let rpcOsuVersion = "";
let currentMap = undefined;
if (!windowTitle.includes("-")) {
rpcOsuVersion = windowTitle;
rpc.updateState("Idle...");
} else {
var string = windowTitle;
var components = string.split(' - ');
const splitArray = [components.shift(), components.join(' - ')];
rpcOsuVersion = splitArray[0];
currentMap = splitArray[1];
if (currentMap.endsWith(".osu")) {
rpc.updateState("Editing...");
currentMap = currentMap.substring(0, currentMap.length - 4);
} else rpc.updateState("Playing...");
}
rpc.updateStatus(currentMap, rpcOsuVersion);
} else {
if (osuLoaded) osuLoaded = false;
rpc.updateState("Idle in Launcher...");
rpc.updateStatus(undefined, undefined);
}
} else {
if (osuLoaded) osuLoaded = false;
rpc.updateState("Idle in Launcher...");
rpc.updateStatus(undefined, undefined);
}
} else if (platform == "linux") {
if (!linuxWMCtrlFound) {
if (isIngame) {
rpc.updateState("Playing...");
rpc.updateStatus("Clicking circles!", "runningunderwine");
} else {
rpc.updateState("Idle in Launcher...");
rpc.updateStatus(undefined, undefined);
}
return;
}
const processesOutput = await terminalUtil.execCommand(`wmctrl -l|awk '{$3=""; $2=""; $1=""; print $0}'`);
const allLines = processesOutput.split("\n");
const filteredProcesses = allLines.filter((line) => line.trim().startsWith("osu!"));
if (filteredProcesses.length > 0) {
const windowTitle = filteredProcesses[0].trim();
let rpcOsuVersion = "";
let currentMap = undefined;
if (!windowTitle.includes("-")) {
rpcOsuVersion = windowTitle;
rpc.updateState("Idle...");
} else {
var string = windowTitle;
var components = string.split(' - ');
const splitArray = [components.shift(), components.join(' - ')];
rpcOsuVersion = splitArray[0];
currentMap = splitArray[1];
if (currentMap.endsWith(".osu")) {
rpc.updateState("Editing/Modding...");
currentMap = currentMap.substring(0, currentMap.length - 4);
}
else rpc.updateState("Playing...");
}
rpc.updateStatus(currentMap, rpcOsuVersion);
} else {
rpc.updateState("Idle in Launcher...");
rpc.updateStatus(undefined, undefined);
}
} else { } else {
if (isIngame) { var string = windowTitle;
rpc.updateState("Playing..."); var components = string.split(' - ');
rpc.updateStatus("Clicking circles!", "runningunderwine"); const splitArray = [components.shift(), components.join(' - ')];
} else { rpcOsuVersion = splitArray[0];
rpc.updateState("Idle in Launcher..."); currentMap = splitArray[1];
rpc.updateStatus(undefined, undefined); if (currentMap.endsWith(".osu")) {
} rpc.updateState("Editing/Modding...");
currentMap = currentMap.substring(0, currentMap.length - 4);
}
else rpc.updateState("Playing...");
} }
}, 2000);
setupTitlebar(); rpc.updateStatus(currentMap, rpcOsuVersion);
} else {
rpc.connect(); rpc.updateState("Idle in Launcher...");
rpc.updateStatus(undefined, undefined);
}
let mainWindow;
app.whenReady().then(() => {
mainWindow = createWindow();
mainWindow.on('show', async () => {
await updateConfigVars(mainWindow);
await tryLogin(mainWindow);
await doUpdateCheck(mainWindow);
if (platform === "linux") {
const linuxDistroInfo = await osUtil.getLinuxDistroInfo();
if (linuxDistroInfo?.id != "arch") {
if (linuxDistroInfo?.id_like != "arch") {
mainWindow.webContents.send('status_update', {
type: "info",
message: "We detected that you are running the Launcher under Linux. It's currently just compatible with Arch like distributions!"
});
}
}
try {
await terminalUtil.execCommand(`osu-stable -h`);
} catch (err) {
mainWindow.webContents.send('status_update', {
type: "package-issue",
message: "Seems like you dont have the osu AUR Package installed, please install it."
});
return;
}
/* mainWindow.webContents.send('status_update', {
type: "info",
message: "We detected that you are running the Launcher under Linux. It's currently just compatible with Arch and the osu AUR package!"
}); */
const terminalTest = await terminalUtil.execCommand(`wmctrl -l|awk '{$3=""; $2=""; $1=""; print $0}'`);
const isFailed = terminalTest.trim() == "";
if (isFailed) {
mainWindow.webContents.send('status_update', {
type: "info",
message: "Seems like you are missing the wmctrl package, please install it for the RPC to work!"
});
} else linuxWMCtrlFound = true;
} else {
const osuFolder = await config.get("osuPath");
if (!osuFolder || osuFolder == "") {
const foundFolder = await osuUtil.findOsuInstallation();
console.log("osu! Installation located at: ",foundFolder);
}
}
})
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) mainWindow = createWindow();
})
app.on('window-all-closed', () => {
app.quit()
})
ipcMain.handle('launch', async () => {
const osuConfig = await osuUtil.getLatestConfig(tempOsuPath);
const username = await config.get('username');
const password = await config.get('password');
if (password && username) {
await osuUtil.setConfigValue(osuConfig.path, "SaveUsername", "1");
await osuUtil.setConfigValue(osuConfig.path, "SavePassword", "1");
await osuUtil.setConfigValue(osuConfig.path, "Username", username);
await osuUtil.setConfigValue(osuConfig.path, "Password", password);
await osuUtil.setConfigValue(osuConfig.path, "CredentialEndpoint", "ez-pp.farm");
} else {
await osuUtil.setConfigValue(osuConfig.path, "Username", "");
await osuUtil.setConfigValue(osuConfig.path, "Password", "");
}
rpc.updateState("Launching osu!...");
isIngame = true;
mainWindow.hide();
const result = await osuUtil.startOsuWithDevServer(tempOsuPath, "ez-pp.farm", async () => {
isIngame = false;
mainWindow.show();
await doUpdateCheck(mainWindow);
});
return result;
})
ipcMain.on('do-update-check', async () => {
await doUpdateCheck(mainWindow);
})
ipcMain.on('do-update', async () => {
const osuPath = await config.get("osuPath", "");
const isValid = await osuUtil.isValidOsuFolder(osuPath);
if (osuPath.trim == "" || !isValid) {
mainWindow.webContents.send('status_update', {
type: "error",
message: "Invalid osu! folder"
});
return;
}
if (fs.existsSync(osuPath)) {
tempOsuPath = osuPath;
const osuConfig = await osuUtil.getLatestConfig(tempOsuPath);
const lastVersion = await osuConfig.get("LastVersion");
let releaseStream = "stable40";
if (lastVersion.endsWith("cuttingedge"))
releaseStream = "cuttingedge"
else if (lastVersion.endsWith("beta"))
releaseStream = "beta";
const releaseFiles = await osuUtil.getUpdateFiles(releaseStream);
const filesToDownload = await osuUtil.filesThatNeedUpdate(tempOsuPath, releaseFiles);
const downloadTask = await osuUtil.downloadUpdateFiles(osuPath, filesToDownload);
downloadTask.on('completed', () => {
mainWindow.webContents.send('status_update', {
type: "update-complete"
})
});
downloadTask.on('error', () => {
mainWindow.webContents.send('status_update', {
type: "error",
message: "An error occured while updating."
});
});
} else
mainWindow.webContents.send('status_update', {
type: "error",
message: "Invalid osu! folder"
});
})
ipcMain.handle('set-osu-dir', async (event) => {
const yes = await dialog.showOpenDialog({
properties: ['openDirectory']
})
if (yes.filePaths.length <= 0)
return undefined;
const folderPath = yes.filePaths[0];
const validOsuDir = await osuUtil.isValidOsuFolder(folderPath);
if (validOsuDir) await config.set("osuPath", folderPath);
return { validOsuDir, folderPath };
})
ipcMain.handle('perform-login', async (event, data) => {
const { username, password } = data;
const loginData = await ezppUtil.performLogin(username, password);
if (loginData && loginData.code === 200) {
await config.set("username", username);
await config.set("password", password);
}
return loginData;
})
ipcMain.on('perform-logout', async (event) => {
await config.remove("username");
await config.remove("password");
})
})
}
async function updateConfigVars(window) {
const osuPath = await config.get("osuPath", "");
window.webContents.send('config_update', {
osuPath: osuPath
})
}
async function tryLogin(window) {
const username = await config.get("username", "");
const password = await config.get("password", "");
if ((username && username.length > 0) && (password && password.length > 0)) {
const passwordPlain = password;
const loginResponse = await ezppUtil.performLogin(username, passwordPlain);
if (loginResponse && loginResponse.code === 200) {
window.webContents.send('account_update', {
type: "loggedin",
user: loginResponse.user
})
} else {
window.webContents.send('account_update', {
type: "login-failed"
})
}
} else { } else {
window.webContents.send('account_update', { if (isIngame) {
type: "not-loggedin" rpc.updateState("Playing...");
}) rpc.updateStatus("Clicking circles!", "runningunderwine");
} else {
rpc.updateState("Idle in Launcher...");
rpc.updateStatus(undefined, undefined);
}
} }
} }, 2000);
async function doUpdateCheck(window) { setupTitlebar();
const osuPath = await config.get("osuPath");
if (!osuPath || osuPath.trim == "") { rpc.connect();
window.webContents.send('status_update', {
type: "missing-folder"
}) let mainWindow;
return; let tray = null
app.whenReady().then(async () => {
const logoFile = path.join(config.configFolder, "logo.png");
if (!fs.existsSync(logoFile)) {
const logoDownload = new DownloaderHelper("https://ez-pp.farm/assets/img/icon.png", config.configFolder, {
fileName: "logo.png",
})
await logoDownload.start();
} }
const isValid = await osuUtil.isValidOsuFolder(osuPath); tray = new Tray(logoFile);
if (!isValid) { const trayMenuTemplate = [
window.webContents.send('status_update', { {
type: "missing-folder" 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.once('show', async () => {
await updateConfigVars(mainWindow);
await tryLogin(mainWindow);
await doUpdateCheck(mainWindow);
if (platform === "linux") {
const linuxDistroInfo = await osUtil.getLinuxDistroInfo();
if (linuxDistroInfo?.id != "arch") {
if (linuxDistroInfo?.id_like != "arch") {
mainWindow.webContents.send('status_update', {
type: "info",
message: "We detected that you are running the Launcher under Linux. It's currently just compatible with Arch like distributions!"
});
}
}
try {
await terminalUtil.execCommand(`osu-stable -h`);
} catch (err) {
mainWindow.webContents.send('status_update', {
type: "package-issue",
message: "Seems like you dont have the osu AUR Package installed, please install it."
});
return;
}
/* mainWindow.webContents.send('status_update', {
type: "info",
message: "We detected that you are running the Launcher under Linux. It's currently just compatible with Arch and the osu AUR package!"
}); */
const terminalTest = await terminalUtil.execCommand(`wmctrl -l|awk '{$3=""; $2=""; $1=""; print $0}'`);
const isFailed = terminalTest.trim() == "";
if (isFailed) {
mainWindow.webContents.send('status_update', {
type: "info",
message: "Seems like you are missing the wmctrl package, please install it for the RPC to work!"
});
} else linuxWMCtrlFound = true;
} else {
const osuFolder = await config.get("osuPath");
if (!osuFolder || osuFolder == "") {
const foundFolder = await osuUtil.findOsuInstallation();
console.log("osu! Installation located at: ", foundFolder);
}
}
})
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) mainWindow = createWindow();
})
app.on('window-all-closed', () => {
app.quit()
})
ipcMain.handle('launch', async () => {
const osuConfig = await osuUtil.getLatestConfig(tempOsuPath);
const username = await config.get('username');
const password = await config.get('password');
if (password && username) {
await osuUtil.setConfigValue(osuConfig.path, "SaveUsername", "1");
await osuUtil.setConfigValue(osuConfig.path, "SavePassword", "1");
await osuUtil.setConfigValue(osuConfig.path, "Username", username);
await osuUtil.setConfigValue(osuConfig.path, "Password", password);
await osuUtil.setConfigValue(osuConfig.path, "CredentialEndpoint", "ez-pp.farm");
} else {
await osuUtil.setConfigValue(osuConfig.path, "Username", "");
await osuUtil.setConfigValue(osuConfig.path, "Password", "");
}
rpc.updateState("Launching osu!...");
isIngame = true;
if (mainWindow.isVisible()) mainWindow.hide();
const result = await osuUtil.startOsuWithDevServer(tempOsuPath, "ez-pp.farm", async () => {
isIngame = false;
if (!mainWindow.isVisible()) mainWindow.show();
await doUpdateCheck(mainWindow);
});
return result;
})
ipcMain.on('do-update-check', async () => {
await doUpdateCheck(mainWindow);
})
ipcMain.on('do-update', async () => {
const osuPath = await config.get("osuPath", "");
const isValid = await osuUtil.isValidOsuFolder(osuPath);
if (osuPath.trim == "" || !isValid) {
mainWindow.webContents.send('status_update', {
type: "error",
message: "Invalid osu! folder"
});
return; return;
} }
if (fs.existsSync(osuPath)) { if (fs.existsSync(osuPath)) {
tempOsuPath = osuPath; tempOsuPath = osuPath;
const osuConfig = await osuUtil.getLatestConfig(tempOsuPath); const osuConfig = await osuUtil.getLatestConfig(tempOsuPath);
const lastVersion = await osuConfig.get("LastVersion"); const lastVersion = await osuConfig.get("LastVersion");
let releaseStream = "stable40"; let releaseStream = "stable40";
if (lastVersion.endsWith("cuttingedge")) if (lastVersion.endsWith("cuttingedge"))
releaseStream = "cuttingedge" releaseStream = "cuttingedge"
else if (lastVersion.endsWith("beta")) else if (lastVersion.endsWith("beta"))
releaseStream = "beta"; releaseStream = "beta";
const releaseFiles = await osuUtil.getUpdateFiles(releaseStream); const releaseFiles = await osuUtil.getUpdateFiles(releaseStream);
const filesToDownload = await osuUtil.filesThatNeedUpdate(tempOsuPath, releaseFiles); const filesToDownload = await osuUtil.filesThatNeedUpdate(tempOsuPath, releaseFiles);
window.webContents.send('status_update', { const downloadTask = await osuUtil.downloadUpdateFiles(osuPath, filesToDownload);
type: filesToDownload.length > 0 ? "update-available" : "up-to-date" downloadTask.on('completed', () => {
}) mainWindow.webContents.send('status_update', {
} else type: "update-complete"
window.webContents.send('status_update', { })
type: "missing-folder" });
}) downloadTask.on('error', () => {
mainWindow.webContents.send('status_update', {
type: "error",
message: "An error occured while updating."
});
});
} else
mainWindow.webContents.send('status_update', {
type: "error",
message: "Invalid osu! folder"
});
})
ipcMain.handle('set-osu-dir', async (event) => {
const yes = await dialog.showOpenDialog({
properties: ['openDirectory']
})
if (yes.filePaths.length <= 0)
return undefined;
const folderPath = yes.filePaths[0];
const validOsuDir = await osuUtil.isValidOsuFolder(folderPath);
if (validOsuDir) await config.set("osuPath", folderPath);
return { validOsuDir, folderPath };
})
ipcMain.handle('perform-login', async (event, data) => {
const { username, password } = data;
const loginData = await ezppUtil.performLogin(username, password);
if (loginData && loginData.code === 200) {
await config.set("username", username);
await config.set("password", password);
}
return loginData;
})
ipcMain.on('perform-logout', async (event) => {
await config.remove("username");
await config.remove("password");
})
})
}
async function updateConfigVars(window) {
const osuPath = await config.get("osuPath", "");
window.webContents.send('config_update', {
osuPath: osuPath
})
}
async function tryLogin(window) {
const username = await config.get("username", "");
const password = await config.get("password", "");
if ((username && username.length > 0) && (password && password.length > 0)) {
const passwordPlain = password;
const loginResponse = await ezppUtil.performLogin(username, passwordPlain);
if (loginResponse && loginResponse.code === 200) {
window.webContents.send('account_update', {
type: "loggedin",
user: loginResponse.user
});
} else {
await config.remove("username");
await config.remove("password");
window.webContents.send('account_update', {
type: "login-failed",
message: loginResponse.message
})
}
} else {
window.webContents.send('account_update', {
type: "not-loggedin"
})
}
const checkUpdate = await appInfo.hasUpdate();
if (checkUpdate) {
window.webContents.send('launcher_update', checkUpdate);
}
}
async function doUpdateCheck(window) {
const osuPath = await config.get("osuPath");
if (!osuPath || osuPath.trim == "") {
window.webContents.send('status_update', {
type: "missing-folder"
})
return;
}
const isValid = await osuUtil.isValidOsuFolder(osuPath);
if (!isValid) {
window.webContents.send('status_update', {
type: "missing-folder"
})
return;
}
if (fs.existsSync(osuPath)) {
tempOsuPath = osuPath;
const osuConfig = await osuUtil.getLatestConfig(tempOsuPath);
const lastVersion = await osuConfig.get("LastVersion");
let releaseStream = "stable40";
if (lastVersion.endsWith("cuttingedge"))
releaseStream = "cuttingedge"
else if (lastVersion.endsWith("beta"))
releaseStream = "beta";
const releaseFiles = await osuUtil.getUpdateFiles(releaseStream);
const filesToDownload = await osuUtil.filesThatNeedUpdate(tempOsuPath, releaseFiles);
window.webContents.send('status_update', {
type: filesToDownload.length > 0 ? "update-available" : "up-to-date"
})
} else
window.webContents.send('status_update', {
type: "missing-folder"
})
} }
function createWindow() { function createWindow() {
// Create the browser window. // Create the browser window.
const win = windowManager.createWindow(700, 460); const win = windowManager.createWindow(700, 460);
win.loadFile('./html/index.html'); win.loadFile('./html/index.html');
attachTitlebarToWindow(win); win.webContents.setWindowOpenHandler(() => "deny");
win.webContents.setWindowOpenHandler(() => "deny"); win.webContents.on('did-finish-load', function () {
win.webContents.on('did-finish-load', function () { if (win.webContents.getZoomFactor() != 0.9)
if (win.webContents.getZoomFactor() != 0.9) win.webContents.setZoomFactor(0.9)
win.webContents.setZoomFactor(0.9) });
});
return win; return win;
} }
run(); run();

View File

@@ -1,4 +1,20 @@
const appName = "EZPPLauncher" const { default: axios } = require("axios");
const appVersion = "1.1.2"; const { compareVersions } = require("compare-versions");
module.exports = { appName, appVersion }; const appName = "EZPPLauncher"
const appVersion = "1.1.4";
const hasUpdate = async () => {
const releaseInfo = await axios.get(`https://git.ez-pp.farm/api/v1/repos/EZPPFarm/${appName}/releases/latest`);
if (releaseInfo.status !== 200) return false;
const latestReleaseVersion = releaseInfo.data.tag_name;
const updateAvailable = compareVersions(latestReleaseVersion, appVersion);
if(updateAvailable > 0)
return {
version: latestReleaseVersion,
url: releaseInfo.data.html_url,
}
return undefined;
}
module.exports = { appName, appVersion, hasUpdate };

View File

@@ -68,4 +68,4 @@ async function remove(key) {
await fs.promises.writeFile(configLocation, arr.join('\n')); await fs.promises.writeFile(configLocation, arr.join('\n'));
} }
module.exports = { get, set, remove } module.exports = { get, set, remove, configFolder }

View File

@@ -1,7 +1,5 @@
const appInfo = require('./appInfo.js'); const appInfo = require('./appInfo.js');
const DiscordAutoRPC = require("discord-auto-rpc"); const DiscordAutoRPC = require("discord-auto-rpc");
const { app } = require('electron');
const DiscordRPC = require("discord-rpc").default;
const clientId = "1032772293220384808"; const clientId = "1032772293220384808";
let client = undefined; let client = undefined;
let lastState = "Idle in Launcher..."; let lastState = "Idle in Launcher...";

View File

@@ -1,10 +1,18 @@
const axios = require('axios').default; const axios = require('axios').default;
const loginCheckEndpoint = 'https://ez-pp.farm/login/check'; const loginCheckEndpoint = 'https://ez-pp.farm/login/check';
let retries = 0;
const performLogin = async (username, password) => { const performLogin = async (username, password) => {
const result = await axios.post(loginCheckEndpoint, { username, password }); const result = await axios.post(loginCheckEndpoint, { username, password });
return result.data; 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 }; 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

@@ -1,6 +1,6 @@
{ {
"name": "ezpplauncher", "name": "ezpplauncher",
"version": "1.1.2", "version": "1.1.4",
"main": "app.js", "main": "app.js",
"license": "MIT", "license": "MIT",
"author": "HorizonCode", "author": "HorizonCode",
@@ -22,7 +22,7 @@
"runAfterFinish": true "runAfterFinish": true
}, },
"portable": { "portable": {
"artifactName": "EZPPLauncher.exe" "artifactName": "ezpplauncher-${version}.exe"
} }
}, },
"frontend": { "frontend": {
@@ -33,9 +33,9 @@
"scripts": { "scripts": {
"start": "electron .", "start": "electron .",
"rebuild": "electron-rebuild -f -w get-window-by-name", "rebuild": "electron-rebuild -f -w get-window-by-name",
"pack-win": "electron-builder --win --arm64 --x64", "pack-win": "electron-builder --win --x64",
"pack-linux": "electron-builder --linux --arm64 --x64", "pack-linux": "electron-builder --linux --x64",
"pack-mac": "electron-builder --mac --arm64 --x64", "pack-mac": "electron-builder --mac --x64",
"dist": "electron-builder" "dist": "electron-builder"
}, },
"devDependencies": { "devDependencies": {
@@ -46,6 +46,7 @@
}, },
"dependencies": { "dependencies": {
"axios": "^0.27.2", "axios": "^0.27.2",
"compare-versions": "^6.0.0-rc.1",
"custom-electron-titlebar": "^4.1.1", "custom-electron-titlebar": "^4.1.1",
"discord-auto-rpc": "^1.0.17", "discord-auto-rpc": "^1.0.17",
"discord-rpc": "^4.0.1", "discord-rpc": "^4.0.1",

View File

@@ -1,233 +1,256 @@
const { ipcRenderer } = require('electron'); const { ipcRenderer, shell } = require('electron');
const { Titlebar, Color } = require('custom-electron-titlebar'); const { Titlebar, TitlebarColor } = require('custom-electron-titlebar');
const appInfo = require('../appInfo'); const appInfo = require('../appInfo');
let titlebar;
let currentPage = "loading"; let currentPage = "loading";
let loggedIn = false; let loggedIn = false;
window.addEventListener('DOMContentLoaded', () => { window.addEventListener('DOMContentLoaded', () => {
titlebar = new Titlebar({ const titlebar = new Titlebar({
backgroundColor: Color.fromHex("#24283B"), backgroundColor: TitlebarColor.fromHex("#24283B"),
itemBackgroundColor: Color.fromHex("#121212"), itemBackgroundColor: TitlebarColor.fromHex("#121212"),
menu: null, menu: null,
maximizable: false enableMnemonics: false,
}); maximizable: false,
});
titlebar.updateTitle(`${appInfo.appName} ${appInfo.appVersion}`); titlebar.updateTitle(`${appInfo.appName} ${appInfo.appVersion}`);
const $ = require('jquery'); const $ = require('jquery');
const Swal = require('sweetalert2'); const Swal = require('sweetalert2');
$('#account-action').on('click', () => { $('#account-action').on('click', () => {
if (!loggedIn) { if (!loggedIn) {
changePage('login'); changePage('login');
} else {
$('#welcome-text').text(`Nice to see you!`);
$('#account-action').text('Click to login');
$('.user-image').css('background-image', `url(https://a.ez-pp.farm/0)`)
loggedIn = false;
ipcRenderer.send("perform-logout");
Swal.fire({
title: 'See ya soon!',
text: "Successfully logged out!",
icon: 'success',
confirmButtonText: 'Okay'
});
}
});
$('#action-cancel').on('click', () => {
if (!loggedIn) {
changePage('launch');
}
});
let currentState;
$("#launch-btn").on('click', async () => {
switch (currentState) {
case "up-to-date":
$("#launch-btn").attr('disabled', true);
$('#launch-btn').html('Launching...');
const result = await ipcRenderer.invoke("launch");
if (!result) {
Swal.fire({
title: 'Uh oh!',
text: "Something went wrong while launching!",
icon: 'error',
confirmButtonText: 'Okay'
});
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Launch');
} else { } else {
$('#welcome-text').text(`Nice to see you!`); $("#launch-btn").attr('disabled', true);
$('#account-action').text('Click to login'); $('#launch-btn').html('Running...');
$('.user-image').css('background-image', `url(https://a.ez-pp.farm/0)`)
loggedIn = false;
ipcRenderer.send("perform-logout");
Swal.fire({
title: 'See ya soon!',
text: "Successfully logged out!",
icon: 'success',
confirmButtonText: 'Okay'
});
} }
}); break;
case "update-available":
$('#action-cancel').on('click', () => { $("#launch-btn").attr('disabled', true);
if (!loggedIn) { $('#launch-btn').html('Updating...');
changePage('launch'); ipcRenderer.send("do-update");
} break;
}); case "missing-folder":
let currentState;
$("#launch-btn").on('click', async () => {
switch (currentState) {
case "up-to-date":
$("#launch-btn").attr('disabled', true);
$('#launch-btn').html('Launching...');
const result = await ipcRenderer.invoke("launch");
if (!result) {
Swal.fire({
title: 'Uh oh!',
text: "Something went wrong while launching!",
icon: 'error',
confirmButtonText: 'Okay'
});
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Launch');
} else {
$("#launch-btn").attr('disabled', true);
$('#launch-btn').html('Running...');
}
break;
case "update-available":
$("#launch-btn").attr('disabled', true);
$('#launch-btn').html('Updating...');
ipcRenderer.send("do-update");
break;
case "missing-folder":
const responseData = await ipcRenderer.invoke('set-osu-dir');
if (!responseData)
return;
if (responseData.validOsuDir) {
Swal.fire({
title: 'Success!',
text: 'osu! folder set.',
icon: 'success',
confirmButtonText: 'Cool'
})
$('#currentOsuPath').text(responseData.folderPath);
ipcRenderer.send("do-update-check");
} else {
Swal.fire({
title: 'Uh oh!',
text: 'The selected folder is not a osu! directory.',
icon: 'error',
confirmButtonText: 'Oops.. my bad!'
})
}
break;
}
});
$("#action-login").on('click', async () => {
const username = $('#login-username').val();
const password = $('#login-password').val();
$("#action-login").attr('disabled', true);
$("#action-cancel").attr('disabled', true);
const responseData = await ipcRenderer.invoke('perform-login', { username, password });
$("#action-login").attr('disabled', false);
$("#action-cancel").attr('disabled', false);
if (!responseData)
return;
if (responseData.code != 200) {
Swal.fire({
title: 'Uh oh!',
text: responseData.message,
icon: 'error',
confirmButtonText: 'Oops.. my bad!'
})
return;
}
$('#login-username').val("");
$('#login-password').val("");
$('#welcome-text').text(`Welcome back, ${responseData.user.name}!`);
$('#account-action').text('Not you?');
$('.user-image').css('background-image', `url(https://a.ez-pp.farm/${responseData.user.id})`);
loggedIn = true;
changePage('launch');
})
$("#change-folder-btn").on('click', async () => {
const responseData = await ipcRenderer.invoke('set-osu-dir'); const responseData = await ipcRenderer.invoke('set-osu-dir');
if (!responseData) if (!responseData)
return; return;
if (responseData.validOsuDir) { if (responseData.validOsuDir) {
Swal.fire({ Swal.fire({
title: 'Success!', title: 'Success!',
text: 'osu! folder set.', text: 'osu! folder set.',
icon: 'success', icon: 'success',
confirmButtonText: 'Cool' confirmButtonText: 'Cool'
}) })
$('#currentOsuPath').text(responseData.folderPath); $('#currentOsuPath').text(responseData.folderPath);
ipcRenderer.send("do-update-check"); ipcRenderer.send("do-update-check");
} else { } else {
Swal.fire({ Swal.fire({
title: 'Uh oh!', title: 'Uh oh!',
text: 'The selected folder is not a osu! directory.', text: 'The selected folder is not a osu! directory.',
icon: 'error', icon: 'error',
confirmButtonText: 'Oops.. my bad!' confirmButtonText: 'Oops.. my bad!'
}) })
} }
}); break;
ipcRenderer.on('config_update', (event, data) => {
if (data.osuPath) {
$('#currentOsuPath').text(data.osuPath);
}
})
ipcRenderer.on('account_update', (event, data) => {
switch (data.type) {
case "not-loggedin":
changePage("launch");
break;
case "loggedin":
changePage("launch");
$('#welcome-text').text(`Welcome back, ${data.user.name}!`);
$('#account-action').text('Not you?');
$('.user-image').css('background-image', `url(https://a.ez-pp.farm/${data.user.id})`);
loggedIn = true;
break;
}
})
ipcRenderer.on('status_update', (event, status) => {
switch (status.type) {
case "up-to-date":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Launch');
currentState = status.type;
break;
case "update-available":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Update');
currentState = status.type;
break;
case "missing-folder":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('set your osu! folder');
currentState = status.type;
break;
case "error":
Swal.fire({
title: 'Uh oh!',
text: status.message,
icon: 'error',
confirmButtonText: 'Okay'
});
ipcRenderer.send("do-update-check");
break;
case "info":
Swal.fire({
title: 'Info!',
text: status.message,
icon: 'info',
confirmButtonText: 'Okay'
});
break;
case "package-issue":
Swal.fire({
title: 'Uh oh!',
text: status.message,
icon: 'error',
confirmButtonText: 'Okay'
});
$("#launch-btn").attr('disabled', true);
$('#launch-btn').html('missing packages');
break;
case "update-complete":
Swal.fire({
title: 'Yaaay!',
text: "Your osu! client has been successfully updated!",
icon: 'success',
confirmButtonText: 'Thanks :3'
});
ipcRenderer.send("do-update-check");
break;
}
})
function changePage(page) {
$(`#${currentPage}-page`).fadeOut(50, "swing", () => {
$(`#${page}-page`).fadeIn(350);
});
currentPage = page;
} }
});
// workaround for the dark theme $("#action-login").on('click', async () => {
$('head').append($('<link href="../assets/sweetalert2.dark.css" rel="stylesheet" />')); const username = $('#login-username').val();
const password = $('#login-password').val();
$("#action-login").attr('disabled', true);
$("#action-cancel").attr('disabled', true);
const responseData = await ipcRenderer.invoke('perform-login', { username, password });
$("#action-login").attr('disabled', false);
$("#action-cancel").attr('disabled', false);
if (!responseData)
return;
if (responseData.code != 200) {
Swal.fire({
title: 'Uh oh!',
text: responseData.message,
icon: 'error',
confirmButtonText: 'Oops.. my bad!'
})
return;
}
$('#login-username').val("");
$('#login-password').val("");
$('#welcome-text').text(`Welcome back, ${responseData.user.name}!`);
$('#account-action').text('Not you?');
$('.user-image').css('background-image', `url(https://a.ez-pp.farm/${responseData.user.id})`);
loggedIn = true;
changePage('launch');
})
$("#change-folder-btn").on('click', async () => {
const responseData = await ipcRenderer.invoke('set-osu-dir');
if (!responseData)
return;
if (responseData.validOsuDir) {
Swal.fire({
title: 'Success!',
text: 'osu! folder set.',
icon: 'success',
confirmButtonText: 'Cool'
})
$('#currentOsuPath').text(responseData.folderPath);
ipcRenderer.send("do-update-check");
} else {
Swal.fire({
title: 'Uh oh!',
text: 'The selected folder is not a osu! directory.',
icon: 'error',
confirmButtonText: 'Oops.. my bad!'
})
}
});
ipcRenderer.on('config_update', (event, data) => {
if (data.osuPath) {
$('#currentOsuPath').text(data.osuPath);
}
})
ipcRenderer.on('launcher_update', async (event, data) => {
const res = await Swal.fire({
title: 'Update available!',
text: `Version ${data.version} has been released!`,
icon: 'info',
showCancelButton: true,
confirmButtonText: 'Download',
cancelButtonText: 'Remind me later',
});
if (res.isConfirmed) {
shell.openExternal(data.url);
}
})
ipcRenderer.on('account_update', (event, data) => {
switch (data.type) {
case "login-failed":
Swal.fire({
title: 'Uh oh!',
text: data.message,
icon: 'error',
confirmButtonText: 'Okay'
});
changePage("launch");
break;
case "not-loggedin":
changePage("launch");
break;
case "loggedin":
changePage("launch");
$('#welcome-text').text(`Welcome back, ${data.user.name}!`);
$('#account-action').text('Not you?');
$('.user-image').css('background-image', `url(https://a.ez-pp.farm/${data.user.id})`);
loggedIn = true;
break;
}
})
ipcRenderer.on('status_update', (event, status) => {
switch (status.type) {
case "up-to-date":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Launch');
currentState = status.type;
break;
case "update-available":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('Update');
currentState = status.type;
break;
case "missing-folder":
$("#launch-btn").attr('disabled', false);
$('#launch-btn').html('set your osu! folder');
currentState = status.type;
break;
case "error":
Swal.fire({
title: 'Uh oh!',
text: status.message,
icon: 'error',
confirmButtonText: 'Okay'
});
ipcRenderer.send("do-update-check");
break;
case "info":
Swal.fire({
title: 'Info!',
text: status.message,
icon: 'info',
confirmButtonText: 'Okay'
});
break;
case "package-issue":
Swal.fire({
title: 'Uh oh!',
text: status.message,
icon: 'error',
confirmButtonText: 'Okay'
});
$("#launch-btn").attr('disabled', true);
$('#launch-btn').html('missing packages');
break;
case "update-complete":
Swal.fire({
title: 'Yaaay!',
text: "Your osu! client has been successfully updated!",
icon: 'success',
confirmButtonText: 'Thanks :3'
});
ipcRenderer.send("do-update-check");
break;
}
})
function changePage(page) {
$(`#${currentPage}-page`).fadeOut(50, "swing", () => {
$(`#${page}-page`).fadeIn(350);
});
currentPage = page;
}
// workaround for the dark theme
$('head').append($('<link href="../assets/sweetalert2.dark.css" rel="stylesheet" />'));
}) })

View File

@@ -1,6 +1,6 @@
const path = require("path"); const path = require("path");
const appInfo = require('../appInfo'); const appInfo = require('../appInfo');
const { BrowserWindow } = require('electron'); const { BrowserWindow, Menu } = require('electron');
const { attachTitlebarToWindow } = require('custom-electron-titlebar/main'); const { attachTitlebarToWindow } = require('custom-electron-titlebar/main');
module.exports = { module.exports = {
@@ -26,6 +26,10 @@ module.exports = {
}, },
icon: './assets/logo.png' icon: './assets/logo.png'
}) })
const menu = Menu.buildFromTemplate([])
Menu.setApplicationMenu(menu);
window.hide(); window.hide();
window.webContents.once("did-finish-load", function (event, input) { window.webContents.once("did-finish-load", function (event, input) {
@@ -33,6 +37,7 @@ module.exports = {
}); });
window.webContents.setUserAgent(`${appInfo.appName} ${appInfo.appVersion}`); window.webContents.setUserAgent(`${appInfo.appName} ${appInfo.appVersion}`);
attachTitlebarToWindow(window); attachTitlebarToWindow(window);
return window; return window;