Update config logging to specify config file path

This commit is contained in:
Nick Bolton 2025-03-31 16:09:57 +01:00
parent 2cdf1cf3b6
commit 30a464fcdc
2 changed files with 17 additions and 6 deletions

View File

@ -32,7 +32,7 @@ import { getProfileFromDeeplink, protocolInit } from "./protocol.js";
import { _t, AppLocalization } from "./language-helper.js"; import { _t, AppLocalization } from "./language-helper.js";
import { setDisplayMediaCallback } from "./displayMediaCallback.js"; import { setDisplayMediaCallback } from "./displayMediaCallback.js";
import { setupMacosTitleBar } from "./macos-titlebar.js"; import { setupMacosTitleBar } from "./macos-titlebar.js";
import { loadJsonFile } from "./utils.js"; import { Json, loadJsonFile } from "./utils.js";
import { setupMediaAuth } from "./media-auth.js"; import { setupMediaAuth } from "./media-auth.js";
const __dirname = dirname(fileURLToPath(import.meta.url)); const __dirname = dirname(fileURLToPath(import.meta.url));
@ -63,6 +63,7 @@ if (argv["help"]) {
} }
const LocalConfigLocation = process.env.ELEMENT_DESKTOP_CONFIG_JSON ?? argv["config"]; const LocalConfigLocation = process.env.ELEMENT_DESKTOP_CONFIG_JSON ?? argv["config"];
const LocalConfigFilename = "config.json";
// Electron creates the user data directory (with just an empty 'Dictionaries' directory...) // Electron creates the user data directory (with just an empty 'Dictionaries' directory...)
// as soon as the app path is set, so pick a random path in it that must exist if it's a // as soon as the app path is set, so pick a random path in it that must exist if it's a
@ -141,6 +142,17 @@ function getAsarPath(): Promise<string> {
return asarPathPromise; return asarPathPromise;
} }
function loadLocalConfigFile(): Json {
if (LocalConfigLocation) {
console.log("Loading local config: " + LocalConfigLocation);
return loadJsonFile(LocalConfigLocation);
} else {
const configDir = app.getPath("userData");
console.log(`Loading local config: ${path.join(configDir, LocalConfigFilename)}`);
return loadJsonFile(configDir, LocalConfigFilename);
}
}
// Loads the config from asar, and applies a config.json from userData atop if one exists // Loads the config from asar, and applies a config.json from userData atop if one exists
// Writes config to `global.vectorConfig`. Does nothing if `global.vectorConfig` is already set. // Writes config to `global.vectorConfig`. Does nothing if `global.vectorConfig` is already set.
async function loadConfig(): Promise<void> { async function loadConfig(): Promise<void> {
@ -149,7 +161,8 @@ async function loadConfig(): Promise<void> {
const asarPath = await getAsarPath(); const asarPath = await getAsarPath();
try { try {
global.vectorConfig = loadJsonFile(asarPath, "config.json"); console.log(`Loading global config: ${path.join(asarPath, LocalConfigFilename)}`);
global.vectorConfig = loadJsonFile(asarPath, LocalConfigFilename);
} catch { } catch {
// it would be nice to check the error code here and bail if the config // it would be nice to check the error code here and bail if the config
// is unparsable, but we get MODULE_NOT_FOUND in the case of a missing // is unparsable, but we get MODULE_NOT_FOUND in the case of a missing
@ -160,9 +173,7 @@ async function loadConfig(): Promise<void> {
try { try {
// Load local config and use it to override values from the one baked with the build // Load local config and use it to override values from the one baked with the build
const localConfig = LocalConfigLocation const localConfig = loadLocalConfigFile();
? loadJsonFile(LocalConfigLocation)
: loadJsonFile(app.getPath("userData"), "config.json");
// If the local config has a homeserver defined, don't use the homeserver from the build // If the local config has a homeserver defined, don't use the homeserver from the build
// config. This is to avoid a problem where Riot thinks there are multiple homeservers // config. This is to avoid a problem where Riot thinks there are multiple homeservers

View File

@ -26,7 +26,7 @@ type JsonArray = Array<JsonValue | JsonObject | JsonArray>;
interface JsonObject { interface JsonObject {
[key: string]: JsonObject | JsonArray | JsonValue; [key: string]: JsonObject | JsonArray | JsonValue;
} }
type Json = JsonArray | JsonObject; export type Json = JsonArray | JsonObject;
/** /**
* Synchronously load a JSON file from the local filesystem. * Synchronously load a JSON file from the local filesystem.