9 Commits

21 changed files with 351 additions and 692 deletions

View File

@@ -1,4 +1,4 @@
const appName = "EZPPLauncher"; const appName = "EZPPLauncher";
const appVersion = "2.1.7"; const appVersion = "2.1.4";
module.exports = { appName, appVersion }; module.exports = { appName, appVersion };

View File

@@ -2,19 +2,19 @@ const childProcess = require("child_process");
const runFile = (folder, file, args, onExit) => { const runFile = (folder, file, args, onExit) => {
childProcess.execFile(file, args, { childProcess.execFile(file, args, {
cwd: folder, cwd: folder
}, (_err, _stdout, _stdin) => { }, (_err, _stdout, _stdin) => {
if (onExit) onExit(); if (onExit) onExit();
}); })
}; }
const runFileDetached = (folder, file, args) => { const runFileDetached = (folder, file, args) => {
const subProcess = childProcess.spawn(file + (args ? " " + args : ""), { const subProcess = childProcess.spawn(file + (args ? " " + args : ''), {
cwd: folder, cwd: folder,
detached: true, detached: true,
stdio: "ignore", stdio: 'ignore'
}); });
subProcess.unref(); subProcess.unref();
}; }
module.exports = { runFile, runFileDetached }; module.exports = { runFile, runFileDetached };

View File

@@ -1,15 +0,0 @@
const fs = require("fs");
function isWritable(filePath) {
let fileAccess = false;
try {
fs.closeSync(fs.openSync(filePath, "r+"));
fileAccess = true;
} catch {
}
return fileAccess;
}
module.exports = {
isWritable,
};

View File

@@ -1,13 +1,13 @@
function formatBytes(bytes, decimals = 2) { function formatBytes(bytes, decimals = 2) {
if (!+bytes) return "0 B"; if (!+bytes) return '0 Bytes'
const k = 1024; const k = 1024
const dm = decimals < 0 ? 0 : decimals; const dm = decimals < 0 ? 0 : decimals
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const i = Math.floor(Math.log(bytes) / Math.log(k)); const i = Math.floor(Math.log(bytes) / Math.log(k))
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))}${sizes[i]}`; return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))}${sizes[i]}`
} }
module.exports = { formatBytes }; module.exports = { formatBytes };

View File

@@ -16,24 +16,17 @@ const platforms = {
}; };
const crypto = require("crypto"); const crypto = require("crypto");
const defaultHWID = "recorderinthesandybridge";
/** /**
* Returns machine hardware id. * Returns machine hardware id.
* @return {Promise<string>} * Returns `undefined` if cannot determine.
* @return {string?}
*/ */
function getHwId() { function getHwId() {
return new Promise((resolve) => {
try {
const getter = platforms[process.platform]; const getter = platforms[process.platform];
if (getter) { if (!getter) return;
const result = getter[1].exec(child_process.execSync(getter[0], options)); const result = getter[1].exec(child_process.execSync(getter[0], options));
if (result) resolve(crypto.createHash("md5").update(result[1]).digest("hex")); if (!result) return;
} return crypto.createHash("md5").update(result[1]).digest("hex") ||
resolve(crypto.createHash("md5").update(defaultHWID).digest("hex")); undefined;
} catch {
resolve(crypto.createHash("md5").update(defaultHWID).digest("hex"));
}
})
} }
exports.getHwId = getHwId; exports.getHwId = getHwId;

View File

@@ -1,12 +1,6 @@
async function checkImageExists(url) { async function checkImageExists(url) {
try { try {
const response = await fetch(url, { const response = await fetch(url, { method: "HEAD" });
method: "HEAD",
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0",
},
});
if (!response.ok) { if (!response.ok) {
return false; return false;
} }

View File

@@ -1,44 +0,0 @@
const fs = require("fs");
const path = require("path");
class Logger {
constructor(directory) {
this.directory = directory;
this.enabled = false;
}
async init() {
const filename = `${new Date().toISOString().replace(/:/g, "-")}.log`;
this.logPath = path.join(this.directory, filename);
}
async log(message) {
if (this.logPath === undefined || this.enabled == false) {
return;
}
if (!fs.existsSync(this.logPath)) {
await fs.promises.mkdir(this.directory, { recursive: true });
await fs.promises.writeFile(this.logPath, "");
}
const logMessage = `[${new Date().toISOString()}] LOG: ${message}`;
await fs.promises.appendFile(this.logPath, `${logMessage}\n`);
console.log(logMessage);
}
async error(message, error) {
if (this.logPath === undefined || this.enabled == false) {
return;
}
if (!fs.existsSync(this.logPath)) {
await fs.promises.mkdir(this.directory, { recursive: true });
await fs.promises.writeFile(this.logPath, "");
}
const errorMessage = `[${
new Date().toISOString()
}] ERROR: ${message}\n${error.stack}`;
await fs.promises.appendFile(this.logPath, `${errorMessage}\n`);
console.error(errorMessage);
}
}
module.exports = Logger;

View File

@@ -1,8 +1,8 @@
const { exec } = require("child_process"); const { exec } = require("child_process");
async function isNet8Installed() { async function isNet8Installed() {
return new Promise((resolve) => { return new Promise((resolve, reject) => {
exec("dotnet --list-runtimes", (error, stdout, stderr) => { exec("dotnet --version", (error, stdout, stderr) => {
if (error) { if (error) {
resolve(false); resolve(false);
return; return;
@@ -12,13 +12,7 @@ async function isNet8Installed() {
return; return;
} }
const version = stdout.trim(); const version = stdout.trim();
for (const line of version.split('\n')) { resolve(version.startsWith("8."));
if (line.startsWith("Microsoft.WindowsDesktop.App 8.")) {
resolve(true);
break;
}
}
resolve(false);
}) })
}); });
} }

View File

@@ -18,8 +18,8 @@ const gamemodes = {
4: "osu!(rx)", 4: "osu!(rx)",
5: "taiko(rx)", 5: "taiko(rx)",
6: "catch(rx)", 6: "catch(rx)",
8: "osu!(ap)", 8: "osu!(ap)"
}; }
const osuEntities = [ const osuEntities = [
"avcodec-51.dll", "avcodec-51.dll",
"avformat-52.dll", "avformat-52.dll",
@@ -44,7 +44,7 @@ const osuEntities = [
"scores.db", "scores.db",
]; ];
const ezppLauncherUpdateList = "https://ez-pp.farm/ezpplauncher"; const ezppLauncherUpdateList = "https://ez-pp.farm/ezpplauncher"
async function isValidOsuFolder(path) { async function isValidOsuFolder(path) {
const allFiles = await fs.promises.readdir(path); const allFiles = await fs.promises.readdir(path);
@@ -152,12 +152,7 @@ function getUserConfig(osuPath) {
} }
async function getUpdateFiles(releaseStream) { async function getUpdateFiles(releaseStream) {
const releaseData = await fetch(checkUpdateURL + releaseStream, { const releaseData = await fetch(checkUpdateURL + releaseStream);
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0",
},
});
return releaseData.ok ? await releaseData.json() : undefined; return releaseData.ok ? await releaseData.json() : undefined;
} }
@@ -189,7 +184,6 @@ function downloadUpdateFiles(osuPath, updateFiles) {
const startDownload = async () => { const startDownload = async () => {
for (const updatePatch of updateFiles) { for (const updatePatch of updateFiles) {
try {
const fileName = updatePatch.filename; const fileName = updatePatch.filename;
const fileSize = updatePatch.filesize; const fileSize = updatePatch.filesize;
const fileURL = updatePatch.url_full; const fileURL = updatePatch.url_full;
@@ -206,7 +200,15 @@ function downloadUpdateFiles(osuPath, updateFiles) {
}); });
}, },
}); });
axiosDownloadWithProgress.data.on("end", () => {
eventEmitter.emit("data", {
fileName,
loaded: fileSize,
total: fileSize,
progress: 100,
});
});
try {
if (fs.existsSync(path.join(osuPath, fileName))) { if (fs.existsSync(path.join(osuPath, fileName))) {
await fs.promises.rm(path.join(osuPath, fileName), { await fs.promises.rm(path.join(osuPath, fileName), {
force: true, force: true,
@@ -220,7 +222,6 @@ function downloadUpdateFiles(osuPath, updateFiles) {
console.log(err); console.log(err);
eventEmitter.emit("error", { eventEmitter.emit("error", {
fileName, fileName,
error: err,
}); });
} }
} }
@@ -247,20 +248,10 @@ function runOsuWithDevServer(osuPath, serverDomain, onExit) {
async function getEZPPLauncherUpdateFiles(osuPath) { async function getEZPPLauncherUpdateFiles(osuPath) {
const filesToDownload = []; const filesToDownload = [];
const updateFilesRequest = await fetch(ezppLauncherUpdateList, { const updateFilesRequest = await fetch(ezppLauncherUpdateList, { method: "PATCH" });
method: "PATCH",
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0",
},
});
const updateFiles = await updateFilesRequest.json(); const updateFiles = await updateFilesRequest.json();
for (const updateFile of updateFiles) { for (const updateFile of updateFiles) {
const filePath = path.join( const filePath = path.join(osuPath, ...updateFile.folder.split("/"), updateFile.name);
osuPath,
...updateFile.folder.split("/"),
updateFile.name,
);
if (fs.existsSync(filePath)) { if (fs.existsSync(filePath)) {
const fileHash = updateFile.md5.toLowerCase(); const fileHash = updateFile.md5.toLowerCase();
const localFileHash = crypto.createHash("md5").update( const localFileHash = crypto.createHash("md5").update(
@@ -273,73 +264,30 @@ async function getEZPPLauncherUpdateFiles(osuPath) {
filesToDownload.push(updateFile); filesToDownload.push(updateFile);
} }
} }
return [filesToDownload, updateFiles]; return filesToDownload;
} }
async function downloadEZPPLauncherUpdateFiles(osuPath, updateFiles, allFiles) { async function downloadEZPPLauncherUpdateFiles(osuPath, updateFiles) {
const eventEmitter = new EventEmitter(); const eventEmitter = new EventEmitter();
const startDownload = async () => { const startDownload = async () => {
//NOTE: delete files that are not in the updateFiles array
const foldersToPrune = allFiles.map((file) =>
path.dirname(path.join(osuPath, ...file.folder.split("/"), file.name))
).filter((folder, index, self) => self.indexOf(folder) === index);
for (const pruneFolder of foldersToPrune) {
//NOTE: check if the folder is not the osu root folder.
if (path.basename(pruneFolder) == "osu!") {
continue;
}
if (fs.existsSync(pruneFolder)) {
for (const files of await fs.promises.readdir(pruneFolder)) {
const filePath = path.join(pruneFolder, files);
const validFolder = allFiles.find((file) =>
path.dirname(filePath).endsWith(file.folder)
);
if (!validFolder) {
if (
allFiles.find((file) => file.name == path.basename(filePath)) ===
undefined
) {
eventEmitter.emit("data", {
fileName: path.basename(filePath),
});
try {
await fs.promises.rm(filePath, {
recursive: true,
force: true,
});
} catch {}
}
}
}
}
}
for (const updateFile of updateFiles) { for (const updateFile of updateFiles) {
try { const filePath = path.join(osuPath, ...updateFile.folder.split("/"), updateFile.name);
const filePath = path.join(
osuPath,
...updateFile.folder.split("/"),
updateFile.name,
);
const folder = path.dirname(filePath); const folder = path.dirname(filePath);
if (!fs.existsSync(folder)) { if (!fs.existsSync(folder)) await fs.promises.mkdir(folder, { recursive: true });
await fs.promises.mkdir(folder, { recursive: true });
}
const axiosDownloadWithProgress = await axios.get(updateFile.url, { const axiosDownloadWithProgress = await axios.get(updateFile.url, {
responseType: "stream", responseType: "stream",
onDownloadProgress: (progressEvent) => { onDownloadProgress: (progressEvent) => {
const fileSize = updateFile.size; const { loaded, total } = progressEvent;
const { loaded } = progressEvent;
eventEmitter.emit("data", { eventEmitter.emit("data", {
fileName: path.basename(filePath), fileName: path.basename(filePath),
loaded, loaded,
total: fileSize, total,
progress: Math.floor((loaded / fileSize) * 100), progress: Math.floor((loaded / total) * 100),
}); });
}, },
}); });
try {
if (fs.existsSync(filePath)) { if (fs.existsSync(filePath)) {
await fs.promises.rm(filePath, { await fs.promises.rm(filePath, {
force: true, force: true,
@@ -353,11 +301,10 @@ async function downloadEZPPLauncherUpdateFiles(osuPath, updateFiles, allFiles) {
console.log(err); console.log(err);
eventEmitter.emit("error", { eventEmitter.emit("error", {
fileName: path.basename(filePath), fileName: path.basename(filePath),
error: err,
}); });
} }
} }
}; }
return { return {
eventEmitter, eventEmitter,
@@ -369,11 +316,7 @@ async function replaceUIFiles(osuPath, revert) {
if (!revert) { if (!revert) {
const ezppUIFile = path.join(osuPath, "EZPPLauncher", "ezpp!ui.dll"); const ezppUIFile = path.join(osuPath, "EZPPLauncher", "ezpp!ui.dll");
const oldOsuUIFile = path.join(osuPath, "osu!ui.dll"); const oldOsuUIFile = path.join(osuPath, "osu!ui.dll");
const ezppGameplayFile = path.join( const ezppGameplayFile = path.join(osuPath, "EZPPLauncher", "ezpp!gameplay.dll");
osuPath,
"EZPPLauncher",
"ezpp!gameplay.dll",
);
const oldOsuGameplayFile = path.join(osuPath, "osu!gameplay.dll"); const oldOsuGameplayFile = path.join(osuPath, "osu!gameplay.dll");
await fs.promises.rename( await fs.promises.rename(
@@ -391,11 +334,7 @@ async function replaceUIFiles(osuPath, revert) {
const oldOsuUIFile = path.join(osuPath, "osu!ui.dll"); const oldOsuUIFile = path.join(osuPath, "osu!ui.dll");
const ezppUIFile = path.join(osuPath, "EZPPLauncher", "ezpp!ui.dll"); const ezppUIFile = path.join(osuPath, "EZPPLauncher", "ezpp!ui.dll");
const oldOsuGameplayFile = path.join(osuPath, "osu!gameplay.dll"); const oldOsuGameplayFile = path.join(osuPath, "osu!gameplay.dll");
const ezppGameplayFile = path.join( const ezppGameplayFile = path.join(osuPath, "EZPPLauncher", "ezpp!gameplay.dll");
osuPath,
"EZPPLauncher",
"ezpp!gameplay.dll",
);
await fs.promises.rename(oldOsuUIFile, ezppUIFile); await fs.promises.rename(oldOsuUIFile, ezppUIFile);
await fs.promises.rename( await fs.promises.rename(
@@ -474,5 +413,5 @@ module.exports = {
runOsuUpdater, runOsuUpdater,
getEZPPLauncherUpdateFiles, getEZPPLauncherUpdateFiles,
downloadEZPPLauncherUpdateFiles, downloadEZPPLauncherUpdateFiles,
gamemodes, gamemodes
}; };

View File

@@ -35,9 +35,7 @@ module.exports = {
richPresence = new DiscordRPC.AutoClient({ transport: "ipc" }); richPresence = new DiscordRPC.AutoClient({ transport: "ipc" });
richPresence.endlessLogin({ clientId }); richPresence.endlessLogin({ clientId });
richPresence.once("ready", () => { richPresence.once("ready", () => {
console.log( console.log("connected presence with user " + richPresence.user.username);
"connected presence with user " + richPresence.user.username,
);
richPresence.setActivity(currentStatus); richPresence.setActivity(currentStatus);
intervalId = setInterval(() => { intervalId = setInterval(() => {
richPresence.setActivity(currentStatus); richPresence.setActivity(currentStatus);

View File

@@ -10,12 +10,7 @@ const releasesUrl =
module.exports = { module.exports = {
updateAvailable: async () => { updateAvailable: async () => {
try { try {
const latestRelease = await fetch(repoApiUrl, { const latestRelease = await fetch(repoApiUrl);
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0",
},
});
const json = await latestRelease.json(); const json = await latestRelease.json();
if (json.length <= 0) return false; if (json.length <= 0) return false;
return { return {

234
main.js
View File

@@ -20,6 +20,7 @@ const {
runOsuWithDevServer, runOsuWithDevServer,
replaceUIFiles, replaceUIFiles,
findOsuInstallation, findOsuInstallation,
updateOsuConfigHashes,
runOsuUpdater, runOsuUpdater,
gamemodes, gamemodes,
getEZPPLauncherUpdateFiles, getEZPPLauncherUpdateFiles,
@@ -37,8 +38,6 @@ const { updateAvailable, releasesUrl } = require("./electron/updateCheck");
const fkill = require("fkill"); const fkill = require("fkill");
const { checkImageExists } = require("./electron/imageUtil"); const { checkImageExists } = require("./electron/imageUtil");
const { isNet8Installed } = require("./electron/netUtils"); const { isNet8Installed } = require("./electron/netUtils");
const Logger = require("./electron/logging");
const { isWritable } = require("./electron/fileUtil");
// Keep a global reference of the window object, if you don't, the window will // Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected. // be closed automatically when the JavaScript object is garbage collected.
@@ -47,13 +46,6 @@ let osuCheckInterval;
let userOsuPath; let userOsuPath;
let osuLoaded = false; let osuLoaded = false;
let patch = false; let patch = false;
let logger = new Logger(path.join(
process.platform == "win32"
? process.env["LOCALAPPDATA"]
: process.env["HOME"],
"EZPPLauncher",
"logs",
));
let currentUser = undefined; let currentUser = undefined;
@@ -74,24 +66,10 @@ function startOsuStatus() {
osuLoaded = true; osuLoaded = true;
try { try {
const currentUserInfo = await fetch( const currentUserInfo = await fetch(`https://api.ez-pp.farm/get_player_info?name=${currentUser.username}&scope=info`);
`https://api.ez-pp.farm/get_player_info?name=${currentUser.username}&scope=info`,
{
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0",
},
},
);
const currentUserInfoJson = await currentUserInfo.json(); const currentUserInfoJson = await currentUserInfo.json();
if ( if ("player" in currentUserInfoJson && currentUserInfoJson.player != null) {
"player" in currentUserInfoJson && if ("info" in currentUserInfoJson.player && currentUserInfoJson.player.info != null) {
currentUserInfoJson.player != null
) {
if (
"info" in currentUserInfoJson.player &&
currentUserInfoJson.player.info != null
) {
const id = currentUserInfoJson.player.info.id; const id = currentUserInfoJson.player.info.id;
const username = currentUserInfoJson.player.info.name; const username = currentUserInfoJson.player.info.name;
richPresence.updateUser({ richPresence.updateUser({
@@ -102,6 +80,7 @@ function startOsuStatus() {
} }
} }
} catch { } catch {
} }
setTimeout(() => { setTimeout(() => {
@@ -122,14 +101,7 @@ function startOsuStatus() {
const windowTitle = firstInstance.processTitle; const windowTitle = firstInstance.processTitle;
lastOsuStatus = windowTitle; lastOsuStatus = windowTitle;
const currentStatusRequest = await fetch( const currentStatusRequest = await fetch(
"https://api.ez-pp.farm/v1/get_player_status?name=" + "https://api.ez-pp.farm/get_player_status?name=" + currentUser.username,
currentUser.username,
{
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0",
},
},
); );
const currentStatus = await currentStatusRequest.json(); const currentStatus = await currentStatusRequest.json();
@@ -140,14 +112,7 @@ function startOsuStatus() {
const currentModeString = gamemodes[currentMode]; const currentModeString = gamemodes[currentMode];
const currentInfoRequest = await fetch( const currentInfoRequest = await fetch(
"https://api.ez-pp.farm/v1/get_player_info?name=" + "https://api.ez-pp.farm/get_player_info?name=" + currentUser.username + "&scope=all",
currentUser.username + "&scope=all",
{
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0",
},
},
); );
const currentInfo = await currentInfoRequest.json(); const currentInfo = await currentInfoRequest.json();
let currentUsername = currentInfo.player.info.name; let currentUsername = currentInfo.player.info.name;
@@ -227,7 +192,7 @@ function startOsuStatus() {
richPresence.updateUser({ richPresence.updateUser({
username: currentUsername, username: currentUsername,
id: currentId, id: currentId,
}); })
richPresence.updateStatus({ richPresence.updateStatus({
details, details,
@@ -246,19 +211,9 @@ function stopOsuStatus() {
function registerIPCPipes() { function registerIPCPipes() {
ipcMain.handle("ezpplauncher:login", async (e, args) => { ipcMain.handle("ezpplauncher:login", async (e, args) => {
let hwid = ""; const hwid = getHwId();
try {
hwid = await getHwId();
} catch (err) {
logger.error(`Failed to get HWID.`, err);
return {
code: 500,
message: "Failed to get HWID.",
};
}
const timeout = new AbortController(); const timeout = new AbortController();
const timeoutId = setTimeout(() => timeout.abort(), 1000 * 10); const timeoutId = setTimeout(() => timeout.abort(), 8000);
logger.log(`Logging in with user ${args.username}...`);
try { try {
const fetchResult = await fetch("https://ez-pp.farm/login/check", { const fetchResult = await fetch("https://ez-pp.farm/login/check", {
signal: timeout.signal, signal: timeout.signal,
@@ -269,8 +224,6 @@ function registerIPCPipes() {
}), }),
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0",
}, },
}); });
@@ -285,20 +238,14 @@ function registerIPCPipes() {
} }
currentUser = args; currentUser = args;
config.remove("guest"); config.remove("guest");
logger.log(`Logged in as user ${args.username}!`); }
} else logger.log(`Login failed for user ${args.username}.`);
return result; return result;
} }
logger.log(
`Login failed for user ${args.username}.\nResponse:\n${await fetchResult
.text()}`,
);
return { return {
code: 500, code: 500,
message: "Something went wrong while logging you in.", message: "Something went wrong while logging you in.",
}; };
} catch (err) { } catch (err) {
logger.error("Error while logging in:", err);
return { return {
code: 500, code: 500,
message: "Something went wrong while logging you in.", message: "Something went wrong while logging you in.",
@@ -315,7 +262,7 @@ function registerIPCPipes() {
}); });
ipcMain.handle("ezpplauncher:autologin", async (e) => { ipcMain.handle("ezpplauncher:autologin", async (e) => {
const hwid = await getHwId(); const hwid = getHwId();
const username = config.get("username"); const username = config.get("username");
const guest = config.get("guest"); const guest = config.get("guest");
if (guest) return { code: 200, message: "Login as guest", guest: true }; if (guest) return { code: 200, message: "Login as guest", guest: true };
@@ -328,7 +275,6 @@ function registerIPCPipes() {
} }
const timeout = new AbortController(); const timeout = new AbortController();
const timeoutId = setTimeout(() => timeout.abort(), 8000); const timeoutId = setTimeout(() => timeout.abort(), 8000);
logger.log(`Logging in with user ${username}...`);
try { try {
const fetchResult = await fetch("https://ez-pp.farm/login/check", { const fetchResult = await fetch("https://ez-pp.farm/login/check", {
signal: timeout.signal, signal: timeout.signal,
@@ -339,8 +285,6 @@ function registerIPCPipes() {
}), }),
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0",
}, },
}); });
@@ -353,23 +297,16 @@ function registerIPCPipes() {
username: username, username: username,
password: password, password: password,
}; };
logger.log(`Logged in as user ${username}!`); }
} else logger.log(`Login failed for user ${username}.`);
return result; return result;
} else { } else {
config.remove("password"); config.remove("password");
} }
logger.log(
`Login failed for user ${username}.\nResponse:\n${await fetchResult
.text()}`,
);
return { return {
code: 500, code: 500,
message: "Something went wrong while logging you in.", message: "Something went wrong while logging you in.",
}; };
} catch (err) { } catch (err) {
logger.error("Error while logging in:", err);
return { return {
code: 500, code: 500,
message: "Something went wrong while logging you in.", message: "Something went wrong while logging you in.",
@@ -382,7 +319,6 @@ function registerIPCPipes() {
config.remove("password"); config.remove("password");
config.set("guest", "1"); config.set("guest", "1");
currentUser = undefined; currentUser = undefined;
logger.log("Logged in as guest user.");
}); });
ipcMain.handle("ezpplauncher:logout", (e) => { ipcMain.handle("ezpplauncher:logout", (e) => {
@@ -390,7 +326,6 @@ function registerIPCPipes() {
config.remove("password"); config.remove("password");
config.remove("guest"); config.remove("guest");
currentUser = undefined; currentUser = undefined;
logger.log("Loging out.");
return true; return true;
}); });
@@ -407,10 +342,6 @@ function registerIPCPipes() {
else richPresence.connect(); else richPresence.connect();
} }
if (key == "logging") {
logger.enabled = value;
}
if (typeof value == "boolean") { if (typeof value == "boolean") {
config.set(key, value ? "true" : "false"); config.set(key, value ? "true" : "false");
} else { } else {
@@ -454,31 +385,12 @@ function registerIPCPipes() {
return config.all(); return config.all();
}); });
ipcMain.handle("ezpplauncher:checkUpdate", async (e) => {
const updateInfo = await updateAvailable();
if (updateInfo.update) {
mainWindow.webContents.send("ezpplauncher:update", updateInfo.release);
}
});
ipcMain.handle("ezpplauncher:exitAndUpdate", async (e) => { ipcMain.handle("ezpplauncher:exitAndUpdate", async (e) => {
await shell.openExternal(releasesUrl); await shell.openExternal(releasesUrl);
app.exit(); app.exit();
}); });
ipcMain.handle("ezpplauncher:launch", async (e) => { ipcMain.handle("ezpplauncher:launch", async (e) => {
try {
const osuWindowTitle = windowName.getWindowText("osu!.exe");
if (osuWindowTitle.length > 0) {
mainWindow.webContents.send("ezpplauncher:alert", {
type: "error",
message: "osu! is running, please exit.",
});
mainWindow.webContents.send("ezpplauncher:launchabort");
return;
}
logger.log("Preparing launch...");
const configPatch = config.get("patch"); const configPatch = config.get("patch");
patch = configPatch != undefined ? configPatch == "true" : true; patch = configPatch != undefined ? configPatch == "true" : true;
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
@@ -494,7 +406,6 @@ function registerIPCPipes() {
message: "osu! path not set!", message: "osu! path not set!",
}); });
mainWindow.webContents.send("ezpplauncher:open-settings"); mainWindow.webContents.send("ezpplauncher:open-settings");
logger.log("osu! path is not set.");
return; return;
} }
if (!(await isValidOsuFolder(osuPath))) { if (!(await isValidOsuFolder(osuPath))) {
@@ -503,7 +414,6 @@ function registerIPCPipes() {
type: "error", type: "error",
message: "invalid osu! path!", message: "invalid osu! path!",
}); });
logger.log("osu! path is invalid.");
return; return;
} }
if (patch) { if (patch) {
@@ -514,31 +424,21 @@ function registerIPCPipes() {
message: ".NET 8 is not installed.", message: ".NET 8 is not installed.",
}); });
//open .net 8 download in browser //open .net 8 download in browser
shell.openExternal( shell.openExternal('https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-desktop-8.0.4-windows-x64-installer');
"https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-desktop-8.0.4-windows-x64-installer",
);
logger.log(".NET 8 is not installed.");
} }
} }
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Checking for osu! updates...", status: "Checking for osu! updates...",
}); });
await new Promise((res) => setTimeout(res, 1000)); await new Promise((res) => setTimeout(res, 1000));
const releaseStream = await getGlobalConfig(osuPath).get( const releaseStream = await getGlobalConfig(osuPath).get("_ReleaseStream");
"_ReleaseStream",
);
const latestFiles = await getUpdateFiles(releaseStream); const latestFiles = await getUpdateFiles(releaseStream);
const updateFiles = await getFilesThatNeedUpdate(osuPath, latestFiles); const updateFiles = await getFilesThatNeedUpdate(osuPath, latestFiles);
if (updateFiles.length > 0) { if (updateFiles.length > 0) {
logger.log("osu! updates found.");
const updateDownloader = downloadUpdateFiles(osuPath, updateFiles); const updateDownloader = downloadUpdateFiles(osuPath, updateFiles);
let errored = false; let errored = false;
updateDownloader.eventEmitter.on("error", (data) => { updateDownloader.eventEmitter.on("error", (data) => {
const filename = data.fileName; const filename = data.fileName;
logger.error(
`Failed to download/replace ${filename}!`,
data.error,
);
errored = true; errored = true;
mainWindow.webContents.send("ezpplauncher:alert", { mainWindow.webContents.send("ezpplauncher:alert", {
type: "error", type: "error",
@@ -547,15 +447,11 @@ function registerIPCPipes() {
}); });
}); });
updateDownloader.eventEmitter.on("data", (data) => { updateDownloader.eventEmitter.on("data", (data) => {
if (data.progress >= 100) {
logger.log(`Downloaded ${data.fileName} successfully.`);
}
mainWindow.webContents.send("ezpplauncher:launchprogress", { mainWindow.webContents.send("ezpplauncher:launchprogress", {
progress: Math.ceil(data.progress), progress: Math.ceil(data.progress),
}); });
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${ status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
formatBytes(data.total)
})...`, })...`,
}); });
}); });
@@ -583,20 +479,12 @@ function registerIPCPipes() {
status: "Looking for patcher updates...", status: "Looking for patcher updates...",
}); });
await new Promise((res) => setTimeout(res, 1000)); await new Promise((res) => setTimeout(res, 1000));
const [patchFiles, allUpdateFiles] = await getEZPPLauncherUpdateFiles( const patchFiles = await getEZPPLauncherUpdateFiles(osuPath);
osuPath,
);
if (patchFiles.length > 0) { if (patchFiles.length > 0) {
logger.log("EZPPLauncher updates found."); const patcherDownloader = await downloadEZPPLauncherUpdateFiles(osuPath, patchFiles);
const patcherDownloader = await downloadEZPPLauncherUpdateFiles(
osuPath,
patchFiles,
allUpdateFiles,
);
let errored = false; let errored = false;
patcherDownloader.eventEmitter.on("error", (data) => { patcherDownloader.eventEmitter.on("error", (data) => {
const filename = data.fileName; const filename = data.fileName;
logger.error(`Failed to download/replace ${filename}!`, data.error);
errored = true; errored = true;
mainWindow.webContents.send("ezpplauncher:alert", { mainWindow.webContents.send("ezpplauncher:alert", {
type: "error", type: "error",
@@ -605,25 +493,12 @@ function registerIPCPipes() {
}); });
}); });
patcherDownloader.eventEmitter.on("data", (data) => { patcherDownloader.eventEmitter.on("data", (data) => {
if (data.progress >= 100) {
logger.log(`Downloaded ${data.fileName} successfully.`);
}
mainWindow.webContents.send("ezpplauncher:launchprogress", { mainWindow.webContents.send("ezpplauncher:launchprogress", {
progress: Math.ceil(data.progress), progress: Math.ceil(data.progress),
}); });
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${ status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
formatBytes(data.loaded) })...`,
}/${formatBytes(data.total)})...`,
});
});
patcherDownloader.eventEmitter.on("delete", (data) => {
logger.log(`Deleting ${data.fileName}!`);
mainWindow.webContents.send("ezpplauncher:launchprogress", {
progress: -1,
});
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Deleting ${data.fileName}...`,
}); });
}); });
await patcherDownloader.startDownload(); await patcherDownloader.startDownload();
@@ -676,20 +551,8 @@ function registerIPCPipes() {
status: "Preparing launch...", status: "Preparing launch...",
}); });
/* await updateOsuConfigHashes(osuPath); */ await updateOsuConfigHashes(osuPath);
logger.log("Replacing UI files...");
try {
await replaceUIFiles(osuPath, false); await replaceUIFiles(osuPath, false);
logger.log("UI files replaced successfully.");
} catch (err) {
logger.error("Failed to replace UI files:", err);
mainWindow.webContents.send("ezpplauncher:alert", {
type: "error",
message: "Failed to replace UI files. try restarting EZPPLauncher.",
});
mainWindow.webContents.send("ezpplauncher:launchabort");
return;
}
const forceUpdateFiles = [ const forceUpdateFiles = [
".require_update", ".require_update",
@@ -703,13 +566,11 @@ function registerIPCPipes() {
if (fs.existsSync(updateFile)) { if (fs.existsSync(updateFile)) {
await fs.promises.rm(updateFile, { await fs.promises.rm(updateFile, {
force: true, force: true,
recursive: (await fs.promises.lstat(updateFile)).isDirectory(), recursive: (await fs.promises.lstat(updateFile)).isDirectory,
}); });
} }
} }
} catch (err) { } catch { }
logger.error("Failed to remove force update files:", err);
}
const userConfig = getUserConfig(osuPath); const userConfig = getUserConfig(osuPath);
if (richPresence.hasPresence) { if (richPresence.hasPresence) {
@@ -728,18 +589,13 @@ function registerIPCPipes() {
status: "Launching osu!...", status: "Launching osu!...",
}); });
await new Promise((res) => setTimeout(res, 1000));
logger.log("Launching osu!...");
const onExitHook = () => { const onExitHook = () => {
logger.log("osu! has exited.");
mainWindow.show(); mainWindow.show();
mainWindow.focus(); mainWindow.focus();
stopOsuStatus(); stopOsuStatus();
richPresence.updateUser({ richPresence.updateUser({
username: " ", username: " ",
id: undefined, id: undefined
}); });
richPresence.updateStatus({ richPresence.updateStatus({
state: "Idle in Launcher...", state: "Idle in Launcher...",
@@ -749,37 +605,24 @@ function registerIPCPipes() {
mainWindow.webContents.send("ezpplauncher:launchstatus", { mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Waiting for cleanup...", status: "Waiting for cleanup...",
}); });
const timeStart = performance.now();
logger.log("Waiting for cleanup...");
const cleanup = setInterval(async () => { setTimeout(async () => {
const osuUIFile = path.join(osuPath, "osu!ui.dll");
const osuGameplayFile = path.join(osuPath, "osu!gameplay.dll");
if (isWritable(osuUIFile) && isWritable(osuGameplayFile)) {
logger.log(
`Cleanup complete, took ${
((performance.now() - timeStart) / 1000).toFixed(3)
} seconds.`,
);
clearInterval(cleanup);
await replaceUIFiles(osuPath, true); await replaceUIFiles(osuPath, true);
mainWindow.webContents.send("ezpplauncher:launchabort"); mainWindow.webContents.send("ezpplauncher:launchabort");
osuLoaded = false; osuLoaded = false;
} }, 5000);
}, 1000);
}; };
runOsuWithDevServer(osuPath, "ez-pp.farm", onExitHook); runOsuWithDevServer(osuPath, "ez-pp.farm", onExitHook);
mainWindow.hide(); mainWindow.hide();
startOsuStatus(); startOsuStatus();
return true;
} catch (err) { /* mainWindow.webContents.send("ezpplauncher:launchprogress", {
logger.error("Failed to launch", err); progress: 0,
mainWindow.webContents.send("ezpplauncher:alert", {
type: "error",
message: "Failed to launch osu!. Please try again.",
}); });
mainWindow.webContents.send("ezpplauncher:launchabort"); mainWindow.webContents.send("ezpplauncher:launchprogress", {
} progress: 100,
}); */
return true;
}); });
} }
@@ -835,13 +678,6 @@ function createWindow() {
richPresence.connect(); richPresence.connect();
} }
} }
logger.init();
const loggingEnabled = config.get("logging");
if (loggingEnabled && loggingEnabled == "true") {
logger.enabled = true;
}
// Uncomment the following line of code when app is ready to be packaged. // Uncomment the following line of code when app is ready to be packaged.
// loadURL(mainWindow); // loadURL(mainWindow);
@@ -862,6 +698,10 @@ function createWindow() {
// Emitted when the window is ready to be shown // Emitted when the window is ready to be shown
// This helps in showing the window gracefully. // This helps in showing the window gracefully.
mainWindow.once("ready-to-show", async () => { mainWindow.once("ready-to-show", async () => {
const updateInfo = await updateAvailable();
if (updateInfo.update) {
mainWindow.webContents.send("ezpplauncher:update", updateInfo.release);
}
mainWindow.show(); mainWindow.show();
mainWindow.focus(); mainWindow.focus();
}); });

8
package-lock.json generated
View File

@@ -24,7 +24,7 @@
"regedit-rs": "^1.0.2", "regedit-rs": "^1.0.2",
"semver": "^7.5.4", "semver": "^7.5.4",
"svelte-french-toast": "^1.2.0", "svelte-french-toast": "^1.2.0",
"sweetalert2": "^11.10.8", "sweetalert2": "^11.10.3",
"systeminformation": "^5.21.22" "systeminformation": "^5.21.22"
}, },
"devDependencies": { "devDependencies": {
@@ -8533,9 +8533,9 @@
"dev": true "dev": true
}, },
"node_modules/sweetalert2": { "node_modules/sweetalert2": {
"version": "11.10.8", "version": "11.10.7",
"resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.10.8.tgz", "resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.10.7.tgz",
"integrity": "sha512-oAkYROBfXBY+4sVbQEIcN+ZxAx69lsmz5WEBwdEpyS4m59vOBNlRU5/fJpAI1MVfiDwFZiGwVzB/KBpOyfLNtg==", "integrity": "sha512-5Jlzrmaitay6KzU+2+LhYu9q+L4v/dZ8oZyEDH14ep0C/QilCnFLHmqAyD/Lhq/lm5DiwsOs6Tr58iv8k3wyGg==",
"funding": { "funding": {
"type": "individual", "type": "individual",
"url": "https://github.com/sponsors/limonte" "url": "https://github.com/sponsors/limonte"

View File

@@ -1,6 +1,6 @@
{ {
"name": "ezpplauncher-next", "name": "ezpplauncher-next",
"version": "2.1.7", "version": "2.1.4",
"description": "EZPPLauncher rewritten with Svelte.", "description": "EZPPLauncher rewritten with Svelte.",
"private": false, "private": false,
"license": "MIT", "license": "MIT",
@@ -51,7 +51,7 @@
"regedit-rs": "^1.0.2", "regedit-rs": "^1.0.2",
"semver": "^7.5.4", "semver": "^7.5.4",
"svelte-french-toast": "^1.2.0", "svelte-french-toast": "^1.2.0",
"sweetalert2": "^11.10.8", "sweetalert2": "^11.10.3",
"systeminformation": "^5.21.22" "systeminformation": "^5.21.22"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -82,10 +82,6 @@ window.addEventListener("settings-set", async (e) => {
await ipcRenderer.invoke("ezpplauncher:settings-set", e.detail); await ipcRenderer.invoke("ezpplauncher:settings-set", e.detail);
}); });
window.addEventListener("updateCheck", async () => {
await ipcRenderer.invoke("ezpplauncher:checkUpdate");
})
window.addEventListener("updateExit", async () => { window.addEventListener("updateExit", async () => {
await ipcRenderer.invoke("ezpplauncher:exitAndUpdate"); await ipcRenderer.invoke("ezpplauncher:exitAndUpdate");
}); });

View File

@@ -69,7 +69,6 @@ export default {
resolve({ resolve({
browser: true, browser: true,
dedupe: ["svelte"], dedupe: ["svelte"],
exportConditions: ["svelte"],
}), }),
typescript({ typescript({
sourceMap: !production, sourceMap: !production,

View File

@@ -1,16 +1,20 @@
<script lang="ts"> <script lang="ts">
import Avatar from "flowbite-svelte/Avatar.svelte"; import {
import Dropdown from "flowbite-svelte/Dropdown.svelte"; Avatar,
import DropdownItem from "flowbite-svelte/DropdownItem.svelte"; Dropdown,
import DropdownHeader from "flowbite-svelte/DropdownHeader.svelte"; DropdownItem,
import DropdownDivider from "flowbite-svelte/DropdownDivider.svelte"; DropdownHeader,
import Button from "flowbite-svelte/Button.svelte"; DropdownDivider,
import Indicator from "flowbite-svelte/Indicator.svelte"; Button,
import ArrowLeftSolid from "flowbite-svelte-icons/ArrowLeftSolid.svelte"; Indicator,
import ArrowRightFromBracketSolid from "flowbite-svelte-icons/ArrowRightFromBracketSolid.svelte"; } from "flowbite-svelte";
import ArrowRightToBracketSolid from "flowbite-svelte-icons/ArrowRightToBracketSolid.svelte"; import {
import HeartSolid from "flowbite-svelte-icons/HeartSolid.svelte"; ArrowLeftSolid,
import UserSettingsSolid from "flowbite-svelte-icons/UserSettingsSolid.svelte"; ArrowRightFromBracketSolid,
ArrowRightToBracketSolid,
HeartSolid,
UserSettingsSolid,
} from "flowbite-svelte-icons";
import ezppLogo from "../public/favicon.png"; import ezppLogo from "../public/favicon.png";
import { import {
currentPage, currentPage,
@@ -62,8 +66,6 @@
window.dispatchEvent(new CustomEvent("updateExit")); window.dispatchEvent(new CustomEvent("updateExit"));
}); });
window.dispatchEvent(new CustomEvent("updateCheck"));
window.addEventListener("open-settings", (e) => { window.addEventListener("open-settings", (e) => {
currentPage.set(Page.Settings); currentPage.set(Page.Settings);
}); });

View File

@@ -1,11 +1,11 @@
<script lang="ts"> <script lang="ts">
import Button from "flowbite-svelte/Button.svelte"; import { Button } from "flowbite-svelte";
import Progressbar from "../lib/Progressbar.svelte"; import Progressbar from "../lib/Progressbar.svelte";
import { import {
launching, launching,
patch, patch,
launchStatus, launchStatus,
launchPercentage, launchPercentage
} from "./../storage/localStore"; } from "./../storage/localStore";
let progressbarFix = true; let progressbarFix = true;

View File

@@ -1,14 +1,10 @@
<script lang="ts"> <script lang="ts">
import Input from "flowbite-svelte/Input.svelte"; import { Input, Button, Spinner, Checkbox } from "flowbite-svelte";
import Button from "flowbite-svelte/Button.svelte";
import Spinner from "flowbite-svelte/Spinner.svelte";
import Checkbox from "flowbite-svelte/Checkbox.svelte";
import { type User } from "../types/user"; import { type User } from "../types/user";
import { currentPage, currentUser, startup } from "../storage/localStore"; import { currentPage, currentUser, startup } from "../storage/localStore";
import toast from "svelte-french-toast"; import toast from "svelte-french-toast";
import { Page } from "../consts/pages"; import { Page } from "../consts/pages";
import EyeSolid from "flowbite-svelte-icons/EyeSolid.svelte"; import { EyeSlashSolid, EyeSolid } from "flowbite-svelte-icons";
import EyeSlashSolid from "flowbite-svelte-icons/EyeSlashSolid.svelte";
let loading = false; let loading = false;
let username = ""; let username = "";
@@ -17,20 +13,11 @@
let showPassword = false; let showPassword = false;
const processLogin = async () => { const processLogin = async () => {
if (username.length <= 0 || password.length <= 0) {
toast.error(`Please provice a valid Username and Password!`, {
position: "bottom-center",
className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 3000,
});
return;
}
loading = true; loading = true;
const loginPromise = new Promise<string>((res, rej) => { const loginPromise = new Promise<void>((res, rej) => {
window.addEventListener( window.addEventListener(
"login-result", "login-result",
async (e) => { (e) => {
const customEvent = e as CustomEvent; const customEvent = e as CustomEvent;
const resultData = customEvent.detail; const resultData = customEvent.detail;
const wasSuccessful = "user" in resultData; const wasSuccessful = "user" in resultData;
@@ -43,26 +30,26 @@
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 1500, duration: 1500,
}); */ }); */
rej(resultData.message); rej();
loading = false; loading = false;
return; return;
} }
const userResult = resultData.user as User; const userResult = resultData.user as User;
currentUser.set(userResult); currentUser.set(userResult);
currentPage.set(Page.Launch); currentPage.set(Page.Launch);
res(""); res();
toast.success(`Welcome back, ${userResult.name}!`, { toast.success(`Welcome back, ${userResult.name}!`, {
position: "bottom-center", position: "bottom-center",
className: className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 3000, duration: 3000
}); });
}, },
{ once: true } { once: true }
); );
window.dispatchEvent( window.dispatchEvent(
new CustomEvent("login-attempt", { new CustomEvent("login-attempt", {
detail: { username, password, saveCredentials }, detail: { username, password, saveCredentials }
}) })
); );
}); });
@@ -71,20 +58,20 @@
{ {
loading: "Logging in...", loading: "Logging in...",
success: "Successfully logged in!", success: "Successfully logged in!",
error: (e) => e, error: "Invalid Username or Password!"
}, },
{ {
position: "bottom-center", position: "bottom-center",
className: className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 0, duration: 3000
} }
); );
}; };
const tryAutoLogin = async () => { const tryAutoLogin = async () => {
loading = true; loading = true;
const loginPromise = new Promise<string>((res, rej) => { const loginPromise = new Promise<void>((res, rej) => {
window.addEventListener( window.addEventListener(
"login-result", "login-result",
(e) => { (e) => {
@@ -94,29 +81,29 @@
const wasSuccessful = "user" in resultData; const wasSuccessful = "user" in resultData;
if (isGuest) { if (isGuest) {
currentPage.set(Page.Launch); currentPage.set(Page.Launch);
res(""); res();
toast.success(`Logged in as Guest`, { toast.success(`Logged in as Guest`, {
position: "bottom-center", position: "bottom-center",
className: className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 3000, duration: 3000
}); });
return; return;
} }
if (!wasSuccessful) { if (!wasSuccessful) {
loading = false; loading = false;
rej(resultData.message); rej();
return; return;
} }
const userResult = resultData.user as User; const userResult = resultData.user as User;
currentUser.set(userResult); currentUser.set(userResult);
currentPage.set(Page.Launch); currentPage.set(Page.Launch);
res(""); res();
toast.success(`Welcome back, ${userResult.name}!`, { toast.success(`Welcome back, ${userResult.name}!`, {
position: "bottom-center", position: "bottom-center",
className: className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 3000, duration: 3000
}); });
loading = false; loading = false;
}, },
@@ -129,13 +116,13 @@
{ {
loading: "Logging in...", loading: "Logging in...",
success: "Successfully logged in!", success: "Successfully logged in!",
error: (e) => e, error: "Failed to login."
}, },
{ {
position: "bottom-center", position: "bottom-center",
className: className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 0, duration: 3000
} }
); );
}; };
@@ -147,7 +134,7 @@
position: "bottom-center", position: "bottom-center",
className: className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 3000, duration: 3000
}); });
}; };

View File

@@ -1,11 +1,7 @@
<script lang="ts"> <script lang="ts">
import Button from "flowbite-svelte/Button.svelte"; import { Button, ButtonGroup, Input, Toggle } from "flowbite-svelte";
import ButtonGroup from "flowbite-svelte/ButtonGroup.svelte"; import { FileSearchSolid, FolderSolid } from "flowbite-svelte-icons";
import Input from "flowbite-svelte/Input.svelte"; import { patch, presence } from "./../storage/localStore";
import Toggle from "flowbite-svelte/Toggle.svelte";
import FileSearchSolid from "flowbite-svelte-icons/FileSearchSolid.svelte";
import FolderSolid from "flowbite-svelte-icons/FolderSolid.svelte";
import { patch, presence, logging } from "./../storage/localStore";
let folderPath: string = ""; let folderPath: string = "";
@@ -16,10 +12,8 @@
const settingPresence = settings.find( const settingPresence = settings.find(
(setting) => setting.key == "presence" (setting) => setting.key == "presence"
); );
const settingLogging = settings.find((setting) => setting.key == "logging");
patch.set(settingPatch ? settingPatch.val == "true" : true); patch.set(settingPatch ? settingPatch.val == "true" : true);
presence.set(settingPresence ? settingPresence.val == "true" : true); presence.set(settingPresence ? settingPresence.val == "true" : true);
logging.set(settingLogging ? settingLogging.val == "true" : false);
folderPath = osuPath ? osuPath.val : ""; folderPath = osuPath ? osuPath.val : "";
}); });
window.dispatchEvent(new CustomEvent("settings-get")); window.dispatchEvent(new CustomEvent("settings-get"));
@@ -45,18 +39,19 @@
new CustomEvent("setting-update", { detail: { presence: $presence } }) new CustomEvent("setting-update", { detail: { presence: $presence } })
); );
}; };
const toggleLogging = () => {
logging.set(!$logging);
window.dispatchEvent(
new CustomEvent("setting-update", { detail: { logging: $logging } })
);
};
</script> </script>
<main <main
class="h-[265px] flex flex-col justify-start p-3 animate-fadeIn opacity-0" class="h-[265px] flex flex-col justify-start p-3 animate-fadeIn opacity-0"
> >
<div class="flex flex-col gap-2 p-3">
<Toggle class="w-fit" bind:checked={$presence} on:click={togglePresence}
>Discord Presence</Toggle
>
<Toggle class="w-fit" bind:checked={$patch} on:click={togglePatching}
>Patching</Toggle
>
</div>
<div <div
class="container flex flex-col items-center justify-center gap-5 rounded-lg p-3" class="container flex flex-col items-center justify-center gap-5 rounded-lg p-3"
> >
@@ -82,15 +77,4 @@
</Button> </Button>
</ButtonGroup> </ButtonGroup>
</div> </div>
<div class="flex flex-col gap-2 p-3">
<Toggle class="w-fit" bind:checked={$presence} on:click={togglePresence}
>Discord Presence</Toggle
>
<Toggle class="w-fit" bind:checked={$patch} on:click={togglePatching}
>Patching</Toggle
>
<Toggle class="w-fit" bind:checked={$logging} on:click={toggleLogging}
>Debug Logging</Toggle
>
</div>
</main> </main>

View File

@@ -7,11 +7,8 @@ export const updateAvailable = writable(false);
export const launching = writable(false); export const launching = writable(false);
export const launchStatus = writable("Waiting..."); export const launchStatus = writable("Waiting...");
export const launchPercentage = writable(-1); export const launchPercentage = writable(-1);
export const currentUser: Writable<undefined | User> = writable(undefined);
export const currentPage = writable(Page.Login);
export const osuPath: Writable<undefined | string> = writable(undefined); export const osuPath: Writable<undefined | string> = writable(undefined);
export const patch = writable(true); export const patch = writable(true);
export const presence = writable(true); export const presence = writable(true);
export const logging = writable(false); export const currentUser: Writable<undefined | User> = writable(undefined);
export const currentPage = writable(Page.Login);