From 27f1fbb5bb5227be5a8d54b6ba93591e11d2e959 Mon Sep 17 00:00:00 2001 From: Tony-Sol Date: Mon, 6 May 2024 20:09:40 +0300 Subject: [PATCH] Make XDG directory specification support more convenient --- src/utils/userDataManager.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/utils/userDataManager.ts b/src/utils/userDataManager.ts index 4eec86d7..d1c33ae2 100644 --- a/src/utils/userDataManager.ts +++ b/src/utils/userDataManager.ts @@ -5,7 +5,9 @@ import { HistoricalHttpRequest } from '../models/httpRequest'; import { JsonFileUtility } from './jsonFileUtility'; const restClientDir = 'rest-client'; -const rootPath = path.join(os.homedir(), `.${restClientDir}`); +const rootPath = process.env.VSC_REST_CLIENT_HOME !== undefined + ? process.env.VSC_REST_CLIENT_HOME + : path.join(os.homedir(), `.${restClientDir}`); function getCachePath(): string { if (fs.existsSync(rootPath)) { @@ -19,13 +21,13 @@ function getCachePath(): string { return rootPath; } -function getConfigPath(): string { +function getStatePath(): string { if (fs.existsSync(rootPath)) { return rootPath; } - if (process.env.XDG_CONFIG_HOME !== undefined) { - return path.join(process.env.XDG_CONFIG_HOME, restClientDir); + if (process.env.XDG_STATE_HOME !== undefined) { + return path.join(process.env.XDG_STATE_HOME, restClientDir); } return rootPath; @@ -36,7 +38,7 @@ export class UserDataManager { private static readonly historyItemsMaxCount = 50; private static readonly cachePath: string = getCachePath(); - private static readonly configPath: string = getConfigPath(); + private static readonly statePath: string = getStatePath(); public static get cookieFilePath() { return path.join(this.cachePath, 'cookie.json'); @@ -47,7 +49,7 @@ export class UserDataManager { } private static get environmentFilePath() { - return path.join(this.configPath, 'environment.json'); + return path.join(this.statePath, 'environment.json'); } private static get responseSaveFolderPath() {