From d35f022b5c66955f821fd0a678b9a9c90a3e653f Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Wed, 25 Sep 2024 14:43:05 -0700 Subject: [PATCH] Fetch settings directly from filesystem on launch (#855) This bypasses the Go backend when fetching the settings for the app on first launch. This allows for actions that need to be performed before the app is ready, such as disabling hardware acceleration. --- emain/emain.ts | 17 ++++++++--------- emain/launchsettings.ts | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 emain/launchsettings.ts diff --git a/emain/emain.ts b/emain/emain.ts index f951e97df..50de420bd 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -21,6 +21,7 @@ import * as keyutil from "../frontend/util/keyutil"; import { fireAndForget } from "../frontend/util/util"; import { AuthKey, AuthKeyEnv, configureAuthKeyRequestInjection } from "./authkey"; import { ElectronWshClient, initElectronWshClient } from "./emain-wsh"; +import { getLaunchSettings } from "./launchsettings"; import { getAppMenu } from "./menu"; import { getElectronAppBasePath, @@ -840,6 +841,13 @@ process.on("uncaughtException", (error) => { }); async function appMain() { + // Set disableHardwareAcceleration as early as possible, if required. + const launchSettings = getLaunchSettings(); + if (launchSettings?.["window:disablehardwareacceleration"]) { + console.log("disabling hardware acceleration, per launch settings"); + electronApp.disableHardwareAcceleration(); + } + const startTs = Date.now(); const instanceLock = electronApp.requestSingleInstanceLock(); if (!instanceLock) { @@ -852,7 +860,6 @@ async function appMain() { fs.mkdirSync(waveHomeDir); } makeAppMenu(); - try { await runWaveSrv(); } catch (e) { @@ -860,14 +867,6 @@ async function appMain() { } const ready = await waveSrvReady; console.log("wavesrv ready signal received", ready, Date.now() - startTs, "ms"); - - const fullConfig = await services.FileService.GetFullConfig(); - const settings = fullConfig.settings; - if (settings?.["window:disablehardwareacceleration"]) { - console.log("disabling hardware acceleration"); - electronApp.disableHardwareAcceleration(); - } - await electronApp.whenReady(); configureAuthKeyRequestInjection(electron.session.defaultSession); await relaunchBrowserWindows(); diff --git a/emain/launchsettings.ts b/emain/launchsettings.ts new file mode 100644 index 000000000..7600c39c4 --- /dev/null +++ b/emain/launchsettings.ts @@ -0,0 +1,18 @@ +import fs from "fs"; +import path from "path"; +import { getWaveHomeDir } from "./platform"; + +/** + * Get settings directly from the Wave Home directory on launch. + * Only use this when the app is first starting up. Otherwise, prefer the settings.GetFullConfig function. + * @returns The initial launch settings for the application. + */ +export function getLaunchSettings(): SettingsType { + const settingsPath = path.join(getWaveHomeDir(), "config", "settings.json"); + try { + const settingsContents = fs.readFileSync(settingsPath, "utf8"); + return JSON.parse(settingsContents); + } catch (e) { + console.error("Unable to load settings.json to get initial launch settings", e); + } +}