Skip to content

Commit

Permalink
feat: add function to check if Claude is running before prompting for…
Browse files Browse the repository at this point in the history
… restart

- Implemented `isClaudeRunning` function to determine if the Claude application is active on Windows, macOS, or Linux.
- Integrated this check into the `promptForRestart` function to enhance user experience by preventing unnecessary prompts when Claude is not running.

Fixes #21
  • Loading branch information
michaellatman committed Dec 4, 2024
1 parent 7ce42e0 commit a27b7cf
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/utils/package-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,33 @@ async function promptForEnvVars(packageName: string): Promise<Record<string, str
return envVars;
}

async function isClaudeRunning(): Promise<boolean> {
try {
const platform = process.platform;
if (platform === 'win32') {
const { stdout } = await execAsync('tasklist /FI "IMAGENAME eq Claude.exe" /NH');
return stdout.includes('Claude.exe');
} else if (platform === 'darwin') {
const { stdout } = await execAsync('pgrep -x "Claude"');
return !!stdout.trim();
} else if (platform === 'linux') {
const { stdout } = await execAsync('pgrep -f "claude"');
return !!stdout.trim();
}
return false;
} catch (error) {
// If the command fails, assume Claude is not running
return false;
}
}

async function promptForRestart(): Promise<boolean> {
// Check if Claude is running first
const claudeRunning = await isClaudeRunning();
if (!claudeRunning) {
return false;
}

const { shouldRestart } = await inquirer.prompt<{ shouldRestart: boolean }>([
{
type: 'confirm',
Expand Down

0 comments on commit a27b7cf

Please sign in to comment.