diff --git a/electron/richPresence.js b/electron/richPresence.js index 5378cf3..48eac62 100644 --- a/electron/richPresence.js +++ b/electron/richPresence.js @@ -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); + } + }, +}; diff --git a/electron/updateCheck.js b/electron/updateCheck.js new file mode 100644 index 0000000..c033f60 --- /dev/null +++ b/electron/updateCheck.js @@ -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; + } + }, +}; diff --git a/main.js b/main.js index 2e565ce..4743e9e 100644 --- a/main.js +++ b/main.js @@ -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(); }); } diff --git a/package-lock.json b/package-lock.json index 595d3d3..e8e3b38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 49e9a40..9766c6c 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/preload.js b/preload.js index add59e5..4bf8c20 100644 --- a/preload.js +++ b/preload.js @@ -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( diff --git a/src/App.svelte b/src/App.svelte index 0c4edf8..7970f4b 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -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 @@ {#if $currentPage == Page.Launch}
Save credentials -
+