fix(cliproxy): prevent misleading update message when proxy is running

When CLIProxyAPI is already running as a background process, the update
cannot be applied because the old process is still in memory. Previously,
the CLI would download the new binary and show "Updating CLIProxyAPI..."
even though the running process remained on the old version.

Now checks if proxy is running before attempting update:
- If running: shows update available message with instruction to stop first
- If not running: proceeds with update as before

Fixes #143
This commit is contained in:
kaitranntt
2025-12-18 22:52:12 -05:00
parent 248d970cba
commit 2adc272f27
+26 -11
View File
@@ -19,7 +19,8 @@ import * as crypto from 'crypto';
import * as zlib from 'zlib';
import { ProgressIndicator } from '../utils/progress-indicator';
import { ok, info } from '../utils/ui';
import { getBinDir, getCliproxyDir } from './config-generator';
import { getBinDir, getCliproxyDir, CLIPROXY_DEFAULT_PORT } from './config-generator';
import { isCliproxyRunning } from './stats-fetcher';
import {
BinaryInfo,
BinaryManagerConfig,
@@ -103,17 +104,31 @@ export class BinaryManager {
try {
const updateResult = await this.checkForUpdates();
if (updateResult.hasUpdate) {
console.log(
info(
`CLIProxyAPI update available: v${updateResult.currentVersion} -> v${updateResult.latestVersion}`
)
);
console.log(info('Updating CLIProxyAPI...'));
// Check if CLIProxyAPI is currently running - can't update while running
const proxyRunning = await isCliproxyRunning(CLIPROXY_DEFAULT_PORT);
if (proxyRunning) {
// Proxy is running - can't update, just notify user
console.log(
info(
`CLIProxyAPI update available: v${updateResult.currentVersion} -> v${updateResult.latestVersion}`
)
);
console.log(info('Run "ccs cliproxy stop" then restart to apply update'));
this.log('Skipping update: CLIProxyAPI is currently running');
} else {
// Proxy not running - safe to update
console.log(
info(
`CLIProxyAPI update available: v${updateResult.currentVersion} -> v${updateResult.latestVersion}`
)
);
console.log(info('Updating CLIProxyAPI...'));
// Delete old binary and download new version
this.deleteBinary();
this.config.version = updateResult.latestVersion;
await this.downloadAndInstall();
// Delete old binary and download new version
this.deleteBinary();
this.config.version = updateResult.latestVersion;
await this.downloadAndInstall();
}
}
} catch (error) {
// Silent fail - don't block startup if update check fails