chore: add reusable globalContext util

This commit is contained in:
NamesMT 2025-05-06 07:53:43 +00:00
parent b7fae4a325
commit 3dcb4534f8
3 changed files with 14 additions and 18 deletions

View file

@ -7,6 +7,7 @@ import { fileExistsAtPath } from "../../utils/fs"
import { arePathsEqual, getWorkspacePath } from "../../utils/path"
import { logger } from "../../utils/logging"
import { GlobalFileNames } from "../../shared/globalFileNames"
import { ensureSettingsDirectoryExists } from "../../utils/globalContext"
const ROOMODES_FILENAME = ".roomodes"
@ -114,7 +115,7 @@ export class CustomModesManager {
}
async getCustomModesFilePath(): Promise<string> {
const settingsDir = await this.ensureSettingsDirectoryExists()
const settingsDir = await ensureSettingsDirectoryExists(this.context)
const filePath = path.join(settingsDir, GlobalFileNames.customModes)
const fileExists = await fileExistsAtPath(filePath)
if (!fileExists) {
@ -329,12 +330,6 @@ export class CustomModesManager {
}
}
private async ensureSettingsDirectoryExists(): Promise<string> {
const settingsDir = path.join(this.context.globalStorageUri.fsPath, "settings")
await fs.mkdir(settingsDir, { recursive: true })
return settingsDir
}
async resetCustomModes(): Promise<void> {
try {
const filePath = await this.getCustomModesFilePath()

View file

@ -12,10 +12,11 @@ import {
InstallMarketplaceItemOptions,
} from "./types"
import { getUserLocale } from "./utils"
import { GlobalFileNames } from "../../../src/shared/globalFileNames"
import { GlobalFileNames } from "../../shared/globalFileNames"
import { assertsMpContext, createHookable, MarketplaceContext, registerMarketplaceHooks } from "roo-rocket"
import { assertsBinarySha256, unpackFromUint8, extractRocketConfigFromUint8 } from "config-rocket/cli"
import { getPanel } from "../../activate/registerCommands"
import { ensureSettingsDirectoryExists } from "../../utils/globalContext"
/**
* Service for managing marketplace data
@ -584,7 +585,7 @@ export class MarketplaceManager {
const cwd =
target === "project"
? vscode.workspace.workspaceFolders![0].uri.fsPath
: await this.ensureSettingsDirectoryExists()
: await ensureSettingsDirectoryExists(this.context)
if (!item.binaryUrl || !item.binaryHash)
return vscode.window.showErrorMessage("Item does not have a binary URL or hash")
@ -658,15 +659,6 @@ export class MarketplaceManager {
vscode.window.showInformationMessage(`"${item.name}" installed successfully`)
}
}
/**
* Copied from `src/core/config/CustomModesManager.ts`, if in the future we add ClineProvider ref to this class, we can remove this and use the one from there.
*/
private async ensureSettingsDirectoryExists(): Promise<string> {
const settingsDir = path.join(this.context.globalStorageUri.fsPath, "settings")
await fs.mkdir(settingsDir, { recursive: true })
return settingsDir
}
}
async function fetchBinary(url: string) {

View file

@ -0,0 +1,9 @@
import { mkdir } from "fs/promises"
import { join } from "path"
import { ExtensionContext } from "vscode"
export async function ensureSettingsDirectoryExists(context: ExtensionContext): Promise<string> {
const settingsDir = join(context.globalStorageUri.fsPath, "settings")
await mkdir(settingsDir, { recursive: true })
return settingsDir
}