fix autologin, add osu folder detection

This commit is contained in:
HorizonCode 2024-01-18 16:32:57 +01:00
parent d5b2b8012c
commit 94fa7e7bd8
11 changed files with 163 additions and 17 deletions

View File

@ -401,6 +401,29 @@ async function replaceUIFile(osuPath, revert) {
} }
} }
async function findOsuInstallation() {
const regedit = require("regedit-rs");
const osuLocationFromDefaultIcon =
"HKLM\\SOFTWARE\\Classes\\osu\\DefaultIcon";
const osuKey = regedit.listSync(osuLocationFromDefaultIcon);
if (osuKey[osuLocationFromDefaultIcon].exists) {
const key = osuKey[osuLocationFromDefaultIcon].values[""];
let value = key.value;
value = value.substring(1, value.length - 3);
return path.dirname(value.trim());
}
/* const osuStruct = await regedit.listValuesSync(osuLocationFromDefaultIcon);
for (const line of osuStruct.split("\n")) {
if (line.includes("REG_SZ")) {
let value = line.trim().split(" ")[2];
value = value.substring(1, value.length - 3);
return path.dirname(value.trim());
}
} */
return undefined;
}
module.exports = { module.exports = {
isValidOsuFolder, isValidOsuFolder,
getUserConfig, getUserConfig,
@ -414,4 +437,5 @@ module.exports = {
downloadUIFiles, downloadUIFiles,
getUIFiles, getUIFiles,
replaceUIFile, replaceUIFile,
findOsuInstallation,
}; };

23
main.js
View File

@ -20,6 +20,7 @@ const {
getUIFiles, getUIFiles,
downloadUIFiles, downloadUIFiles,
replaceUIFile, replaceUIFile,
findOsuInstallation,
} = require("./electron/osuUtil"); } = require("./electron/osuUtil");
const { formatBytes } = require("./electron/formattingUtil"); const { formatBytes } = require("./electron/formattingUtil");
const windowName = require("get-window-by-name"); const windowName = require("get-window-by-name");
@ -140,18 +141,20 @@ function registerIPCPipes() {
ipcMain.handle("ezpplauncher:autologin-active", async (e) => { ipcMain.handle("ezpplauncher:autologin-active", async (e) => {
const username = config.get("username"); const username = config.get("username");
const password = config.get("password"); const password = config.get("password");
const guest = config.get("guest");
if (guest != undefined) return true;
return username != undefined && password != undefined; return username != undefined && password != undefined;
}); });
ipcMain.handle("ezpplauncher:autologin", async (e) => { ipcMain.handle("ezpplauncher:autologin", async (e) => {
const hwid = getHwId(); const hwid = getHwId();
const username = config.get("username"); const username = config.get("username");
const guest = config.get("guest");
if (guest) return { code: 200, message: "Login as guest", guest: true };
if (username == undefined) { if (username == undefined) {
return { code: 200, message: "No autologin" }; return { code: 200, message: "No autologin" };
} }
const password = cryptUtil.decrypt(config.get("password"), hwid); const password = cryptUtil.decrypt(config.get("password"), hwid);
const guest = config.get("guest");
if (guest) return { code: 200, message: "Login as guest", guest: true };
if (username == undefined || password == undefined) { if (username == undefined || password == undefined) {
return { code: 200, message: "No autologin" }; return { code: 200, message: "No autologin" };
} }
@ -215,6 +218,18 @@ function registerIPCPipes() {
return config.all(); return config.all();
}); });
ipcMain.handle("ezpplauncher:detect-folder", async (e) => {
const detected = await findOsuInstallation();
if (detected && await isValidOsuFolder(detected)) {
mainWindow.webContents.send("ezpplauncher:alert", {
type: "success",
message: "osu! path successfully saved!",
});
config.set("osuPath", detected);
}
return config.all();
});
ipcMain.handle("ezpplauncher:set-folder", async (e) => { ipcMain.handle("ezpplauncher:set-folder", async (e) => {
const folderResult = await dialog.showOpenDialog({ const folderResult = await dialog.showOpenDialog({
title: "Select osu! installation directory", title: "Select osu! installation directory",
@ -441,8 +456,8 @@ function createWindow() {
// Create the browser window. // Create the browser window.
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
width: 600, width: 550,
height: 380, height: 350,
resizable: false, resizable: false,
frame: false, frame: false,
titleBarStyle: "hidden", titleBarStyle: "hidden",

60
package-lock.json generated
View File

@ -7,6 +7,7 @@
"": { "": {
"name": "ezpplauncher-next", "name": "ezpplauncher-next",
"version": "2.0.0", "version": "2.0.0",
"hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@types/better-sqlite3": "^7.6.8", "@types/better-sqlite3": "^7.6.8",
@ -18,6 +19,7 @@
"discord-auto-rpc": "^1.0.17", "discord-auto-rpc": "^1.0.17",
"electron-serve": "^1.1.0", "electron-serve": "^1.1.0",
"get-window-by-name": "^2.0.0", "get-window-by-name": "^2.0.0",
"regedit-rs": "^1.0.2",
"svelte-french-toast": "^1.2.0", "svelte-french-toast": "^1.2.0",
"systeminformation": "^5.21.22" "systeminformation": "^5.21.22"
}, },
@ -7051,6 +7053,64 @@
"node": ">=8.10.0" "node": ">=8.10.0"
} }
}, },
"node_modules/regedit-rs": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/regedit-rs/-/regedit-rs-1.0.2.tgz",
"integrity": "sha512-4vEgiZNO1FCG8z/Zx3v/6PU1+eZ+ELe6R0ca+VB96Vw+Mi3M0IVHAjtMFbl97lUSX11dJqpyousX/wY8QcI1lA==",
"engines": {
"node": ">= 10"
},
"optionalDependencies": {
"regedit-rs-win32-arm64-msvc": "1.0.2",
"regedit-rs-win32-ia32-msvc": "1.0.2",
"regedit-rs-win32-x64-msvc": "1.0.2"
}
},
"node_modules/regedit-rs-win32-arm64-msvc": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/regedit-rs-win32-arm64-msvc/-/regedit-rs-win32-arm64-msvc-1.0.2.tgz",
"integrity": "sha512-hM1sxazOJWKmiC9DM8QXW9Iqm50Mh/Y9G4/rRYQpWXjMzq7lTqjwVZRkAoBrHliFS6d1Lt4qkm5+Ybt6GkbDpw==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/regedit-rs-win32-ia32-msvc": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/regedit-rs-win32-ia32-msvc/-/regedit-rs-win32-ia32-msvc-1.0.2.tgz",
"integrity": "sha512-FLINrCJ30wm6NYw7skQUDET8NP1N46kH77dqesCiU+/FjWzzPE5luZYY+j4uf+hKjPY6/MCj2CB9l9VdPhaBVQ==",
"cpu": [
"ia32"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/regedit-rs-win32-x64-msvc": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/regedit-rs-win32-x64-msvc/-/regedit-rs-win32-x64-msvc-1.0.2.tgz",
"integrity": "sha512-ccCSyd5vWBKVWftBKLKzegqwwPMWcQtIW0ub66dCFFuv2s+x2EcZZWGdD9dVXX2Z6V9DU2JRPKgWUNjVPaj6Xg==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/regenerator-runtime": { "node_modules/regenerator-runtime": {
"version": "0.14.1", "version": "0.14.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz",

View File

@ -47,6 +47,7 @@
"discord-auto-rpc": "^1.0.17", "discord-auto-rpc": "^1.0.17",
"electron-serve": "^1.1.0", "electron-serve": "^1.1.0",
"get-window-by-name": "^2.0.0", "get-window-by-name": "^2.0.0",
"regedit-rs": "^1.0.2",
"svelte-french-toast": "^1.2.0", "svelte-french-toast": "^1.2.0",
"systeminformation": "^5.21.22" "systeminformation": "^5.21.22"
}, },

View File

@ -57,6 +57,13 @@ window.addEventListener("settings-get", async () => {
); );
}); });
window.addEventListener("folder-auto", async (e) => {
const result = await ipcRenderer.invoke("ezpplauncher:detect-folder");
window.dispatchEvent(
new CustomEvent("settings-result", { detail: result }),
);
});
window.addEventListener("folder-set", async (e) => { window.addEventListener("folder-set", async (e) => {
const result = await ipcRenderer.invoke("ezpplauncher:set-folder"); const result = await ipcRenderer.invoke("ezpplauncher:set-folder");
window.dispatchEvent( window.dispatchEvent(

View File

@ -18,5 +18,5 @@
<script defer src="/build/bundle.js"></script> <script defer src="/build/bundle.js"></script>
</head> </head>
<body class="select-none bg-gray-100 dark:bg-gray-900"></body> <body class="select-none bg-gray-100 dark:bg-gray-900 overflow-hidden"></body>
</html> </html>

View File

@ -5,8 +5,10 @@
DropdownItem, DropdownItem,
DropdownHeader, DropdownHeader,
DropdownDivider, DropdownDivider,
Button,
} from "flowbite-svelte"; } from "flowbite-svelte";
import { import {
ArrowLeftSolid,
ArrowRightFromBracketSolid, ArrowRightFromBracketSolid,
ArrowRightToBracketSolid, ArrowRightToBracketSolid,
UserSettingsSolid, UserSettingsSolid,
@ -103,6 +105,17 @@
<div class="p-2 flex flex-row justify-between items-center"> <div class="p-2 flex flex-row justify-between items-center">
<div class="flex flex-row items-center animate-fadeIn opacity-0"> <div class="flex flex-row items-center animate-fadeIn opacity-0">
{#if $currentPage == Page.Settings}
<Button
class="dark:!bg-gray-800 dark:active:!bg-gray-950 !ring-0 outline-none !border-none dark:text-white w-10 h-10 mr-1 rounded-lg animate-sideIn opacity-0"
color="none"
on:click={() => {
currentPage.set(Page.Launch);
}}
>
<ArrowLeftSolid class="outline-none border-none" size="sm" />
</Button>
{/if}
<img src={ezppLogo} alt="EZPPFarm Logo" class="w-12 h-12 mr-2" /> <img src={ezppLogo} alt="EZPPFarm Logo" class="w-12 h-12 mr-2" />
<span class="text-gray-700 dark:text-gray-100 text-xl font-extralight"> <span class="text-gray-700 dark:text-gray-100 text-xl font-extralight">
EZPPLauncher EZPPLauncher

View File

@ -20,6 +20,10 @@ html .cet-titlebar .cet-control-icon svg {
display: none; display: none;
} }
.cet-container {
overflow: hidden !important;
}
.indeterminate { .indeterminate {
background-image: repeating-linear-gradient( background-image: repeating-linear-gradient(
90deg, 90deg,

View File

@ -80,6 +80,7 @@
const resultData = customEvent.detail; const resultData = customEvent.detail;
const isGuest = "guest" in resultData; const isGuest = "guest" in resultData;
const wasSuccessful = "user" in resultData; const wasSuccessful = "user" in resultData;
console.log(resultData);
if (isGuest) { if (isGuest) {
currentPage.set(Page.Launch); currentPage.set(Page.Launch);
res(); res();

View File

@ -1,6 +1,13 @@
<script lang="ts"> <script lang="ts">
import { Button, ButtonGroup, Input, Toggle } from "flowbite-svelte"; import {
import { FolderSolid } from "flowbite-svelte-icons"; Button,
ButtonGroup,
Input,
Label,
Toggle,
Tooltip,
} from "flowbite-svelte";
import { FileSearchSolid, FolderSolid } from "flowbite-svelte-icons";
import { currentPage } from "../storage/localStore"; import { currentPage } from "../storage/localStore";
import { Page } from "../consts/pages"; import { Page } from "../consts/pages";
@ -20,6 +27,10 @@
window.dispatchEvent(new CustomEvent("folder-set")); window.dispatchEvent(new CustomEvent("folder-set"));
}; };
const detectFolderPath = () => {
window.dispatchEvent(new CustomEvent("folder-auto"));
};
const togglePatching = () => { const togglePatching = () => {
patching = !patching; patching = !patching;
}; };
@ -46,6 +57,7 @@
<ButtonGroup class="w-full"> <ButtonGroup class="w-full">
<Input <Input
type="text" type="text"
id="oip"
placeholder="Path to your osu! installation" placeholder="Path to your osu! installation"
value={folderPath} value={folderPath}
readonly readonly
@ -53,19 +65,23 @@
<Button <Button
color="light" color="light"
class="dark:active:!bg-gray-900" class="dark:active:!bg-gray-900"
on:click={setFolderPath} on:click={detectFolderPath}
><FolderSolid >
<FileSearchSolid
size="sm" size="sm"
class="dark:text-gray-300 text-gray-500 outline-none border-none select-none pointer-events-none" class="dark:text-gray-300 text-gray-500 outline-none border-none select-none pointer-events-none"
/></Button />
> </Button>
</ButtonGroup>
<div class="flex flex-row justify-center items-center gap-5">
<Button <Button
color="light" color="light"
class="dark:active:!bg-gray-900" class="dark:active:!bg-gray-900 active:!rounded-lg"
on:click={() => currentPage.set(Page.Launch)}>Go Back</Button on:click={setFolderPath}
> >
</div> <FolderSolid
size="sm"
class="dark:text-gray-300 text-gray-500 outline-none border-none select-none pointer-events-none"
/>
</Button>
</ButtonGroup>
</div> </div>
</main> </main>

View File

@ -8,6 +8,10 @@ const config = {
theme: { theme: {
extend: { extend: {
keyframes: { keyframes: {
slideIn: {
"0%": { opacity: "0", transform: "translateX(-5px)" },
"100%": { opacity: "1" },
},
fadeIn: { fadeIn: {
"0%": { opacity: "0", transform: "translateY(5px)" }, "0%": { opacity: "0", transform: "translateY(5px)" },
"100%": { opacity: "1" }, "100%": { opacity: "1" },
@ -18,11 +22,12 @@ const config = {
}, },
}, },
animation: { animation: {
sideIn: "slideIn 1s ease forwards",
fadeIn: "fadeIn 1s ease forwards", fadeIn: "fadeIn 1s ease forwards",
fadeOut: "fadeOut 1s ease forwards", fadeOut: "fadeOut 1s ease forwards",
}, },
transitionProperty: { transitionProperty: {
'width': 'width', "width": "width",
}, },
colors: { colors: {
// flowbite-svelte // flowbite-svelte