refactor: update MCPService and process utilities for improved binary management

- Refactored MCPService to streamline command handling for 'npx' and 'uvx', removing unnecessary installation checks and directly retrieving binary paths.
- Updated getBinaryPath and isBinaryExists functions to be asynchronous, enhancing their reliability in checking binary existence and paths.
- Cleaned up imports and removed unused dependencies for better code clarity.
This commit is contained in:
kangfenmao
2025-03-17 13:47:33 +08:00
parent 1223b2689d
commit cf7e1fb162
2 changed files with 16 additions and 27 deletions
+7 -8
View File
@@ -35,16 +35,15 @@ export function runInstallScript(scriptPath: string): Promise<void> {
})
}
export function getBinaryPath(name: string): string {
export async function getBinaryPath(name: string): Promise<string> {
let cmd = process.platform === 'win32' ? `${name}.exe` : name
const binariesDir = path.join(os.homedir(), '.cherrystudio', 'bin')
let cmd = path.join(binariesDir, name)
cmd = process.platform === 'win32' ? `${cmd}.exe` : cmd
const binariesDirExists = await fs.existsSync(binariesDir)
cmd = binariesDirExists ? path.join(binariesDir, name) : name
return cmd
}
export function isBinaryExists(name: string): Promise<boolean> {
return new Promise((resolve) => {
const cmd = getBinaryPath(name)
resolve(fs.existsSync(cmd))
})
export async function isBinaryExists(name: string): Promise<boolean> {
const cmd = await getBinaryPath(name)
return await fs.existsSync(cmd)
}