Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make XDG directory specification support more convenient #1269

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/utils/userDataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
Expand All @@ -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');
Expand All @@ -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() {
Expand Down
Loading