mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-05 18:16:28 +00:00
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:
@@ -19,7 +19,8 @@ import * as crypto from 'crypto';
|
|||||||
import * as zlib from 'zlib';
|
import * as zlib from 'zlib';
|
||||||
import { ProgressIndicator } from '../utils/progress-indicator';
|
import { ProgressIndicator } from '../utils/progress-indicator';
|
||||||
import { ok, info } from '../utils/ui';
|
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 {
|
import {
|
||||||
BinaryInfo,
|
BinaryInfo,
|
||||||
BinaryManagerConfig,
|
BinaryManagerConfig,
|
||||||
@@ -103,17 +104,31 @@ export class BinaryManager {
|
|||||||
try {
|
try {
|
||||||
const updateResult = await this.checkForUpdates();
|
const updateResult = await this.checkForUpdates();
|
||||||
if (updateResult.hasUpdate) {
|
if (updateResult.hasUpdate) {
|
||||||
console.log(
|
// Check if CLIProxyAPI is currently running - can't update while running
|
||||||
info(
|
const proxyRunning = await isCliproxyRunning(CLIPROXY_DEFAULT_PORT);
|
||||||
`CLIProxyAPI update available: v${updateResult.currentVersion} -> v${updateResult.latestVersion}`
|
if (proxyRunning) {
|
||||||
)
|
// Proxy is running - can't update, just notify user
|
||||||
);
|
console.log(
|
||||||
console.log(info('Updating CLIProxyAPI...'));
|
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
|
// Delete old binary and download new version
|
||||||
this.deleteBinary();
|
this.deleteBinary();
|
||||||
this.config.version = updateResult.latestVersion;
|
this.config.version = updateResult.latestVersion;
|
||||||
await this.downloadAndInstall();
|
await this.downloadAndInstall();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Silent fail - don't block startup if update check fails
|
// Silent fail - don't block startup if update check fails
|
||||||
|
|||||||
Reference in New Issue
Block a user