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); + } +}