Skip to content

Commit 694279d

Browse files
authored
Fetch settings directly from filesystem on launch (wavetermdev#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.
1 parent fe8773a commit 694279d

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

emain/emain.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import * as keyutil from "../frontend/util/keyutil";
2121
import { fireAndForget } from "../frontend/util/util";
2222
import { AuthKey, AuthKeyEnv, configureAuthKeyRequestInjection } from "./authkey";
2323
import { ElectronWshClient, initElectronWshClient } from "./emain-wsh";
24+
import { getLaunchSettings } from "./launchsettings";
2425
import { getAppMenu } from "./menu";
2526
import {
2627
getElectronAppBasePath,
@@ -840,6 +841,13 @@ process.on("uncaughtException", (error) => {
840841
});
841842

842843
async function appMain() {
844+
// Set disableHardwareAcceleration as early as possible, if required.
845+
const launchSettings = getLaunchSettings();
846+
if (launchSettings?.["window:disablehardwareacceleration"]) {
847+
console.log("disabling hardware acceleration, per launch settings");
848+
electronApp.disableHardwareAcceleration();
849+
}
850+
843851
const startTs = Date.now();
844852
const instanceLock = electronApp.requestSingleInstanceLock();
845853
if (!instanceLock) {
@@ -852,22 +860,13 @@ async function appMain() {
852860
fs.mkdirSync(waveHomeDir);
853861
}
854862
makeAppMenu();
855-
856863
try {
857864
await runWaveSrv();
858865
} catch (e) {
859866
console.log(e.toString());
860867
}
861868
const ready = await waveSrvReady;
862869
console.log("wavesrv ready signal received", ready, Date.now() - startTs, "ms");
863-
864-
const fullConfig = await services.FileService.GetFullConfig();
865-
const settings = fullConfig.settings;
866-
if (settings?.["window:disablehardwareacceleration"]) {
867-
console.log("disabling hardware acceleration");
868-
electronApp.disableHardwareAcceleration();
869-
}
870-
871870
await electronApp.whenReady();
872871
configureAuthKeyRequestInjection(electron.session.defaultSession);
873872
await relaunchBrowserWindows();

emain/launchsettings.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import { getWaveHomeDir } from "./platform";
4+
5+
/**
6+
* Get settings directly from the Wave Home directory on launch.
7+
* Only use this when the app is first starting up. Otherwise, prefer the settings.GetFullConfig function.
8+
* @returns The initial launch settings for the application.
9+
*/
10+
export function getLaunchSettings(): SettingsType {
11+
const settingsPath = path.join(getWaveHomeDir(), "config", "settings.json");
12+
try {
13+
const settingsContents = fs.readFileSync(settingsPath, "utf8");
14+
return JSON.parse(settingsContents);
15+
} catch (e) {
16+
console.error("Unable to load settings.json to get initial launch settings", e);
17+
}
18+
}

0 commit comments

Comments
 (0)