From 9f6a25801f0fc61dcdc78813787d3b5d258ea014 Mon Sep 17 00:00:00 2001 From: smartfrigde <37928912+smartfrigde@users.noreply.github.com> Date: Sun, 16 Jun 2024 13:30:40 +0200 Subject: [PATCH] switch to electron-is-dev --- package.json | 1 + pnpm-lock.yaml | 3 +++ src/common/config.ts | 3 ++- src/common/version.ts | 7 ++++--- src/splash/main.ts | 6 +++++- src/splash/preload.mts | 1 + src/splash/splash.html | 2 +- 7 files changed, 17 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index df4a7f2..4a50bf1 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "arrpc": "github:OpenAsar/arrpc#c62ec6a04c8d870530aa6944257fe745f6c59a24", "cross-fetch": "^4.0.0", "electron-context-menu": "^4.0.0", + "electron-is-dev": "^3.0.1", "extract-zip": "^2.0.1", "v8-compile-cache": "^2.4.0", "ws": "^8.17.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0f696da..23cbe5f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: electron-context-menu: specifier: ^4.0.0 version: 4.0.0 + electron-is-dev: + specifier: ^3.0.1 + version: 3.0.1 extract-zip: specifier: ^2.0.1 version: 2.0.1 diff --git a/src/common/config.ts b/src/common/config.ts index 65b638d..75758e8 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -1,5 +1,6 @@ import {app, dialog} from "electron"; import path from "path"; +import isDev from "electron-is-dev"; import fs from "fs"; import type {Settings} from "../types/settings.d.js"; import {getWindowStateLocation} from "./windowState.js"; @@ -10,7 +11,7 @@ export function checkForDataFolder(): void { console.log("Found armcord-data folder. Running in portable mode."); app.setPath("userData", dataPath); } - if (path.join(app.getPath("appData"), "ArmCord")) { + if (path.join(app.getPath("appData"), "ArmCord") && !isDev) { console.log("Found existing ArmCord folder."); app.setPath("userData", path.join(app.getPath("appData"), "ArmCord")); } diff --git a/src/common/version.ts b/src/common/version.ts index 57055dd..d4e8954 100644 --- a/src/common/version.ts +++ b/src/common/version.ts @@ -1,13 +1,14 @@ import {app} from "electron"; +import isDev from "electron-is-dev"; export function getVersion(): string { - if ((app.getVersion() == process.versions.electron) == true) { - return "3.3.0"; + if (isDev) { + return "0.0.0"; } return app.getVersion(); } export function getDisplayVersion(): string { - if ((app.getVersion() == process.versions.electron) == true) { + if (isDev) { return "Dev Build"; } return app.getVersion(); diff --git a/src/splash/main.ts b/src/splash/main.ts index 0e47edc..e36a7f5 100644 --- a/src/splash/main.ts +++ b/src/splash/main.ts @@ -1,6 +1,7 @@ -import {BrowserWindow} from "electron"; +import {BrowserWindow, ipcMain} from "electron"; import {iconPath} from "../main.js"; import path from "path"; +import isDev from "electron-is-dev"; export let splashWindow: BrowserWindow; export async function createSplashWindow(): Promise { @@ -19,5 +20,8 @@ export async function createSplashWindow(): Promise { preload: path.join(import.meta.dirname, "preload.mjs") } }); + ipcMain.on("isDev", (event) => { + event.returnValue = isDev; + }); await splashWindow.loadFile(path.join(import.meta.dirname, "splash.html")); } diff --git a/src/splash/preload.mts b/src/splash/preload.mts index 2f584e1..c7695d6 100644 --- a/src/splash/preload.mts +++ b/src/splash/preload.mts @@ -4,6 +4,7 @@ contextBridge.exposeInMainWorld("internal", { restart: () => ipcRenderer.send("restart"), installState: ipcRenderer.sendSync("modInstallState") as string, version: ipcRenderer.sendSync("get-app-version", "app-version") as string, + isDev: ipcRenderer.sendSync("isDev") as string, getLang: (toGet: string) => ipcRenderer.invoke("getLang", toGet).then((result: string) => { return result; diff --git a/src/splash/splash.html b/src/splash/splash.html index e50adf4..bd0d817 100644 --- a/src/splash/splash.html +++ b/src/splash/splash.html @@ -35,7 +35,7 @@ window.internal.restart(); } else { text.innerHTML = await internal.getLang("loading_screen_start"); - if (window.internal.version === "3.3.0") { + if (internal.isDev) { console.log("Running a development build of ArmCord. Skipping updater."); } else { const response = await fetch("https://armcord.app/latest.json");