Skip to content

Commit

Permalink
Address PR remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
SleepyLeslie committed Jun 10, 2024
1 parent c4d53bf commit bc42f77
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ext/app/electron/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import * as path from "path";
import bluebird from 'bluebird';
import { commonUrls } from "app/common/gristUrls";

const CONFIG_DIR = path.join(electron.app.getPath("appData"), packageJson.name);

const APPDATA_DIR = (process.platform === "win32") ? electron.app.getPath("userData") :
path.join(electron.app.getPath("home"), ".local", "share", packageJson.name);
const APPDATA_DIR = (["win32", "darwin"].includes(process.platform))
? path.join(electron.app.getPath("appData"), packageJson.name)
: path.join(electron.app.getPath("home"), ".local", "share", packageJson.name);

// Electron's app.getPath("userData") uses productName instead of name
// but productName should be "full capitalized name", not ideal for naming our config directory.
const DEFAULT_CONFIG_FILE = path.join(CONFIG_DIR, "config.ini");
const DEFAULT_CONFIG_FILE = path.join(APPDATA_DIR, "config.ini");
const NO_VALIDATION = () => true;

/**
Expand Down Expand Up @@ -118,8 +117,13 @@ export async function loadConfig(filename: string = DEFAULT_CONFIG_FILE) {
const configBuffer = fse.readFileSync(filename);
config = new Config(ini.parse(configBuffer.toString("utf8")));
} catch (err) {
log.warn(`Failed to read configuration file: ${err}`);
config = new Config({});
if (err instanceof Error && err.message.startsWith("ENOENT")) {
log.warn(`Configuration file ${filename} does not exist, using default config`);
config = new Config({});
} else {
log.error(`Failed to read configuration file: ${err}`);
process.exit(1);
}
}
// Section: login
config.apply(
Expand Down

0 comments on commit bc42f77

Please sign in to comment.