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.
This commit is contained in:
Evan Simkowitz 2024-09-25 14:43:05 -07:00 committed by GitHub
parent 6dc738c3c8
commit d35f022b5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 9 deletions

View file

@ -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();

18
emain/launchsettings.ts Normal file
View file

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