Improve valid vencord install checks

This commit is contained in:
V 2023-08-12 03:13:03 +02:00
parent c5ac3e64a6
commit 28ad4a6f73
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
3 changed files with 9 additions and 7 deletions

View file

@ -1,6 +1,6 @@
{
"name": "VencordDesktop",
"version": "0.2.9",
"version": "0.2.8",
"private": true,
"description": "",
"keywords": [],

View file

@ -5,7 +5,7 @@
*/
import { app, dialog, ipcMain, session, shell } from "electron";
import { existsSync, mkdirSync, readFileSync, watch } from "fs";
import { mkdirSync, readFileSync, watch } from "fs";
import { open, readFile } from "fs/promises";
import { release } from "os";
import { join } from "path";
@ -17,7 +17,7 @@ import { autoStart } from "./autoStart";
import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants";
import { mainWin } from "./mainWindow";
import { Settings } from "./settings";
import { FILES_TO_DOWNLOAD } from "./utils/vencordLoader";
import { isValidVencordInstall } from "./utils/vencordLoader";
ipcMain.on(IpcEvents.GET_VENCORD_PRELOAD_FILE, e => {
e.returnValue = join(VENCORD_FILES_DIR, "vencordDesktopPreload.js");
@ -112,9 +112,7 @@ ipcMain.handle(IpcEvents.SELECT_VENCORD_DIR, async () => {
if (!res.filePaths.length) return "cancelled";
const dir = res.filePaths[0];
for (const file of FILES_TO_DOWNLOAD) {
if (!existsSync(join(dir, file))) return "invalid";
}
if (!isValidVencordInstall(dir)) return "invalid";
return dir;
});

View file

@ -55,8 +55,12 @@ export async function downloadVencordFiles() {
);
}
export function isValidVencordInstall(dir: string) {
return FILES_TO_DOWNLOAD.every(f => existsSync(join(dir, f)));
}
export async function ensureVencordFiles() {
if (existsSync(join(VENCORD_FILES_DIR, "vencordDesktopMain.js"))) return;
if (isValidVencordInstall(VENCORD_FILES_DIR)) return;
mkdirSync(VENCORD_FILES_DIR, { recursive: true });
await downloadVencordFiles();