add toggles for presence and patch

This commit is contained in:
HorizonCode 2024-01-19 15:04:58 +01:00
parent cef085c13d
commit 61d5182854
11 changed files with 138 additions and 161 deletions

View File

@ -1,9 +1,13 @@
const DiscordRPC = require("discord-auto-rpc");
const { appName, appVersion } = require("./appInfo.js");
const { get } = require("./config.js");
const clientId = "1032772293220384808";
let richPresence;
let showPresence = true;
let cleared = false;
let currentStatus = {
details: " ",
state: "Idle in Launcher...",
@ -32,7 +36,19 @@ module.exports = {
richPresence.endlessLogin({ clientId });
richPresence.once("ready", () => {
setInterval(() => {
richPresence.setActivity(currentStatus);
const settingPresence = get("presence");
showPresence = settingPresence != undefined
? settingPresence.val == "true"
: true;
if (showPresence) {
richPresence.setActivity(currentStatus);
cleared = false;
} else {
if (cleared) return;
cleared = true;
richPresence.clearActivity();
}
}, 2500);
});
}
@ -53,6 +69,8 @@ module.exports = {
currentStatus.smallImageText = osuVersion ? `osu! ${osuVersion}` : " ";
},
update: () => {
richPresence.setActivity(currentStatus);
}
};
if (showPresence) {
richPresence.setActivity(currentStatus);
}
},
};

18
electron/updateCheck.js Normal file
View File

@ -0,0 +1,18 @@
const semver = require("semver");
const { appVersion } = require("./appInfo");
const repoUrl =
"https://git.ez-pp.farm/api/v1/repos/EZPPFarm/EZPPLauncher/releases?limit=1";
module.exports = {
updateAvailable: async () => {
try {
const latestRelease = await fetch(repoUrl);
const json = await latestRelease.json();
if (json.length <= 0) return false;
return semver.lt(appVersion, json[0].tag_name);
} catch (err) {
return false;
}
},
};

55
main.js
View File

@ -29,6 +29,8 @@ const { runFileDetached } = require("./electron/executeUtil");
const richPresence = require("./electron/richPresence");
const cryptUtil = require("./electron/cryptoUtil");
const { getHwId } = require("./electron/hwidUtil");
const { appName, appVersion } = require("./electron/appInfo");
const { updateAvailable } = require("./electron/updateCheck");
// 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.
@ -73,18 +75,22 @@ function startOsuStatus() {
const windowTitle = firstInstance.processTitle;
lastOsuStatus = windowTitle;
const currentStatusRequest = await fetch("https://api.ez-pp.farm/get_player_status?name=" + currentUser.username);
const currentStatusRequest = await fetch(
"https://api.ez-pp.farm/get_player_status?name=" + currentUser.username,
);
const currentStatus = await currentStatusRequest.json();
if (!("player_status" in currentStatus)) return;
if (!("status" in currentStatus.player_status)) return;
let details = "Idle...";
let infoText = currentStatus.player_status.status.info_text.length > 0 ? currentStatus.player_status.status.info_text : " ";
let infoText = currentStatus.player_status.status.info_text.length > 0
? currentStatus.player_status.status.info_text
: " ";
switch (currentStatus.player_status.status.action) {
case 1:
details = "AFK..."
details = "AFK...";
infoText = " ";
break;
case 2:
@ -94,7 +100,7 @@ function startOsuStatus() {
details = "Editing...";
break;
case 4:
details = "Modding..."
details = "Modding...";
break;
case 5:
details = "Multiplayer: Selecting a Beatmap...";
@ -124,7 +130,7 @@ function startOsuStatus() {
richPresence.updateStatus({
details,
state: infoText
state: infoText,
});
richPresence.update();
@ -260,6 +266,17 @@ function registerIPCPipes() {
return config.all();
});
ipcMain.handle("ezpplauncher:setting-update", async (e, args) => {
for (const key of Object.keys(args)) {
const value = args[key];
if (typeof value == "boolean") {
config.set(key, value ? "true" : "false");
} else {
config.set(key, value);
}
}
});
ipcMain.handle("ezpplauncher:detect-folder", async (e) => {
const detected = await findOsuInstallation();
if (detected && await isValidOsuFolder(detected)) {
@ -295,8 +312,9 @@ function registerIPCPipes() {
return config.all();
});
ipcMain.handle("ezpplauncher:launch", async (e, args) => {
patch = args.patch;
ipcMain.handle("ezpplauncher:launch", async (e) => {
const configPatch = config.get("patch");
patch = configPatch != undefined ? configPatch.val == "true" : true;
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Checking osu! directory...",
});
@ -344,8 +362,9 @@ function registerIPCPipes() {
progress: Math.ceil(data.progress),
});
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
})...`,
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${
formatBytes(data.total)
})...`,
});
});
await uiDownloader.startDownload();
@ -374,8 +393,9 @@ function registerIPCPipes() {
progress: Math.ceil(data.progress),
});
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
})...`,
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${
formatBytes(data.total)
})...`,
});
});
await updateDownloader.startDownload();
@ -420,8 +440,9 @@ function registerIPCPipes() {
progress: Math.ceil(data.progress),
});
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${formatBytes(data.total)
})...`,
status: `Downloading ${data.fileName}(${formatBytes(data.loaded)}/${
formatBytes(data.total)
})...`,
});
});
await patcherDownloader.startDownload();
@ -466,7 +487,7 @@ function registerIPCPipes() {
richPresence.updateVersion();
richPresence.updateStatus({
state: "Idle in Launcher...",
details: undefined
details: undefined,
});
richPresence.update();
mainWindow.webContents.send("ezpplauncher:launchstatus", {
@ -483,7 +504,6 @@ function registerIPCPipes() {
mainWindow.hide();
startOsuStatus();
/* mainWindow.webContents.send("ezpplauncher:launchprogress", {
progress: 0,
});
@ -504,6 +524,7 @@ function createWindow() {
resizable: false,
frame: false,
titleBarStyle: "hidden",
title: `${appName} ${appVersion}`,
webPreferences: {
nodeIntegration: true,
preload: path.join(__dirname, "preload.js"),
@ -550,7 +571,9 @@ function createWindow() {
// Emitted when the window is ready to be shown
// This helps in showing the window gracefully.
mainWindow.once("ready-to-show", () => {
mainWindow.once("ready-to-show", async () => {
const hasUpdate = await updateAvailable();
console.log({ hasUpdate });
mainWindow.show();
});
}

140
package-lock.json generated
View File

@ -20,6 +20,7 @@
"electron-serve": "^1.1.0",
"get-window-by-name": "^2.0.0",
"regedit-rs": "^1.0.2",
"semver": "^7.5.4",
"svelte-french-toast": "^1.2.0",
"systeminformation": "^5.21.22"
},
@ -168,6 +169,14 @@
"global-agent": "^3.0.0"
}
},
"node_modules/@electron/get/node_modules/semver": {
"version": "6.3.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/@electron/notarize": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@electron/notarize/-/notarize-2.1.0.tgz",
@ -362,21 +371,6 @@
"graceful-fs": "^4.1.6"
}
},
"node_modules/@electron/rebuild/node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@electron/rebuild/node_modules/universalify": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
@ -1147,21 +1141,6 @@
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
}
},
"node_modules/@npmcli/fs/node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@npmcli/move-file": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@npmcli/move-file/-/move-file-2.0.1.tgz",
@ -2044,21 +2023,6 @@
"node": ">=10"
}
},
"node_modules/app-builder-lib/node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/app-builder-lib/node_modules/universalify": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
@ -4488,21 +4452,6 @@
"node": ">=10.0"
}
},
"node_modules/global-agent/node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"optional": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/globalthis": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.3.tgz",
@ -5728,20 +5677,6 @@
"node": ">=10"
}
},
"node_modules/node-abi/node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/node-addon-api": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.2.tgz",
@ -5756,21 +5691,6 @@
"semver": "^7.3.5"
}
},
"node_modules/node-api-version/node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/node-fetch": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
@ -5850,21 +5770,6 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/node-gyp/node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/node-releases": {
"version": "2.0.14",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.14.tgz",
@ -7712,11 +7617,17 @@
}
},
"node_modules/semver": {
"version": "6.3.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/semver-compare": {
@ -7852,21 +7763,6 @@
"node": ">=10"
}
},
"node_modules/simple-update-notifier/node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/sirv": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/sirv/-/sirv-2.0.4.tgz",

View File

@ -48,6 +48,7 @@
"electron-serve": "^1.1.0",
"get-window-by-name": "^2.0.0",
"regedit-rs": "^1.0.2",
"semver": "^7.5.4",
"svelte-french-toast": "^1.2.0",
"systeminformation": "^5.21.22"
},

View File

@ -1,5 +1,6 @@
const { Titlebar, TitlebarColor } = require("custom-electron-titlebar");
const { ipcRenderer } = require("electron");
const { appName, appVersion } = require("./electron/appInfo");
window.addEventListener("DOMContentLoaded", () => {
const titlebar = new Titlebar({
@ -9,6 +10,7 @@ window.addEventListener("DOMContentLoaded", () => {
enableMnemonics: false,
maximizable: false,
});
titlebar.updateTitle(`${appName} ${appVersion}`);
});
window.addEventListener("login-attempt", async (e) => {
@ -57,6 +59,11 @@ window.addEventListener("settings-get", async () => {
);
});
window.addEventListener("setting-update", async (e) => {
const detail = e.detail;
await ipcRenderer.invoke("ezpplauncher:setting-update", detail);
});
window.addEventListener("folder-auto", async (e) => {
const result = await ipcRenderer.invoke("ezpplauncher:detect-folder");
window.dispatchEvent(

View File

@ -5,13 +5,13 @@
DropdownItem,
DropdownHeader,
DropdownDivider,
Button
Button,
} from "flowbite-svelte";
import {
ArrowLeftSolid,
ArrowRightFromBracketSolid,
ArrowRightToBracketSolid,
UserSettingsSolid
UserSettingsSolid,
} from "flowbite-svelte-icons";
import ezppLogo from "../public/favicon.png";
import {
@ -19,7 +19,9 @@
currentUser,
launching,
launchPercentage,
launchStatus
launchStatus,
patch,
presence,
} from "./storage/localStore";
import { Page } from "./consts/pages";
import Login from "./pages/Login.svelte";
@ -36,6 +38,9 @@
user = newUser;
});
presence.subscribe((val) => {
});
const logout = () => {
window.dispatchEvent(new CustomEvent("logout"));
currentUser.set(undefined);
@ -44,7 +49,7 @@
position: "bottom-center",
className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 2000
duration: 2000,
});
};
@ -75,7 +80,7 @@
position: "bottom-center",
className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 2000
duration: 2000,
});
break;
}
@ -84,7 +89,7 @@
position: "bottom-center",
className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 4000
duration: 4000,
});
break;
}
@ -94,7 +99,7 @@
position: "bottom-center",
className:
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
duration: 1500
duration: 1500,
});
}
}
@ -123,7 +128,7 @@
</div>
{#if $currentPage == Page.Launch}
<div
class="flex flex-row gap-2 w-fill cursor-pointer md:order-2 animate-fadeIn opacity-0"
class="flex flex-row gap-2 w-fill cursor-pointer md:order-2 animate-lsideIn opacity-0"
>
<Avatar
class="rounded-lg border dark:border-gray-700 hover:ring-4 hover:ring-gray-200 dark:hover:ring-gray-800"

View File

@ -196,7 +196,7 @@
<Checkbox bind:checked={saveCredentials} disabled={loading}
>Save credentials</Checkbox
>
<div class="flex flex-col justify-center items-center gap-5 mt-1">
<div class="flex flex-col justify-center items-center gap-2 mt-1">
<Button
class="dark:active:!bg-gray-900 active:scale-95 transition-transform duration-75"
color="light"

View File

@ -1,12 +1,5 @@
<script lang="ts">
import {
Button,
ButtonGroup,
Input,
Label,
Toggle,
Tooltip
} from "flowbite-svelte";
import { Button, ButtonGroup, Input, Toggle } from "flowbite-svelte";
import { FileSearchSolid, FolderSolid } from "flowbite-svelte-icons";
import { patch, presence } from "./../storage/localStore";
@ -15,6 +8,12 @@
window.addEventListener("settings-result", (e) => {
const settings: Record<string, string>[] = (e as CustomEvent).detail;
const osuPath = settings.find((setting) => setting.key == "osuPath");
const settingPatch = settings.find((setting) => setting.key == "patch");
const settingPresence = settings.find(
(setting) => setting.key == "presence"
);
patch.set(settingPatch ? settingPatch.val == "true" : true);
presence.set(settingPresence ? settingPresence.val == "true" : true);
folderPath = osuPath ? osuPath.val : "";
});
window.dispatchEvent(new CustomEvent("settings-get"));
@ -29,12 +28,16 @@
const togglePatching = () => {
patch.set(!$patch);
//TODO: save in config
window.dispatchEvent(
new CustomEvent("setting-update", { detail: { patch: $patch } })
);
};
const togglePresence = () => {
presence.set(!$presence);
//TODO: save in config
window.dispatchEvent(
new CustomEvent("setting-update", { detail: { presence: $presence } })
);
};
</script>

View File

@ -3,6 +3,7 @@ import { Page } from "../consts/pages";
import type { User } from "../types/user";
export const startup = writable(false);
export const updateAvailable = writable(false);
export const launching = writable(false);
export const launchStatus = writable("Waiting...");
export const launchPercentage = writable(-1);

View File

@ -12,6 +12,10 @@ const config = {
"0%": { opacity: "0", transform: "translateX(-5px)" },
"100%": { opacity: "1" },
},
lslideIn: {
"0%": { opacity: "0", transform: "translateX(5px)" },
"100%": { opacity: "1" },
},
fadeIn: {
"0%": { opacity: "0", transform: "translateY(5px)" },
"100%": { opacity: "1" },
@ -23,6 +27,7 @@ const config = {
},
animation: {
sideIn: "slideIn 1s ease forwards",
lsideIn: "lslideIn 1s ease forwards",
fadeIn: "fadeIn 1s ease forwards",
fadeOut: "fadeOut 1s ease forwards",
},