mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-26 03:31:24 +08:00
- Removed the getLatestBunVersion and getLatestUvVersion functions to streamline version handling. - Updated download functions to use temporary filenames and ensure proper cleanup of downloaded files. - Enhanced directory management by ensuring the output directory is correctly referenced and cleaned up if empty. - Refactored the install functions to directly use detected platform and architecture, improving readability and maintainability.
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { spawn } from 'child_process'
|
|
import log from 'electron-log'
|
|
import fs from 'fs'
|
|
import os from 'os'
|
|
import path from 'path'
|
|
|
|
import { getResourcePath } from '.'
|
|
|
|
export function runInstallScript(scriptPath: string): Promise<void> {
|
|
return new Promise<void>((resolve, reject) => {
|
|
const installScriptPath = path.join(getResourcePath(), 'scripts', scriptPath)
|
|
log.info(`Running script at: ${installScriptPath}`)
|
|
|
|
const nodeProcess = spawn(process.execPath, [installScriptPath], {
|
|
env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' }
|
|
})
|
|
|
|
nodeProcess.stdout.on('data', (data) => {
|
|
log.info(`Script output: ${data}`)
|
|
})
|
|
|
|
nodeProcess.stderr.on('data', (data) => {
|
|
log.error(`Script error: ${data}`)
|
|
})
|
|
|
|
nodeProcess.on('close', (code) => {
|
|
if (code === 0) {
|
|
log.info('Script completed successfully')
|
|
resolve()
|
|
} else {
|
|
log.error(`Script exited with code ${code}`)
|
|
reject(new Error(`Process exited with code ${code}`))
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
export async function getBinaryPath(name: string): Promise<string> {
|
|
let cmd = process.platform === 'win32' ? `${name}.exe` : name
|
|
const binariesDir = path.join(os.homedir(), '.cherrystudio', 'bin')
|
|
const binariesDirExists = await fs.existsSync(binariesDir)
|
|
cmd = binariesDirExists ? path.join(binariesDir, cmd) : name
|
|
return cmd
|
|
}
|
|
|
|
export async function isBinaryExists(name: string): Promise<boolean> {
|
|
const cmd = await getBinaryPath(name)
|
|
return await fs.existsSync(cmd)
|
|
}
|