Skip to content

Commit 6a6ec06

Browse files
author
Willow P.
committed
fix: stop button and Makefile name change issues
1 parent 2fe3d56 commit 6a6ec06

File tree

6 files changed

+93
-44
lines changed

6 files changed

+93
-44
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Change Log
22

3+
### [v3.3.1](https://github.com/drizzy/code-make/releases/tag/v3.3.1)
4+
5+
> 16 May 2025
6+
7+
### Fixes
8+
9+
- Fixed stop button bug when reloading vscode
10+
- Fixed error when changing the name of the executable in Makefile
11+
312
### [v3.3.0](https://github.com/drizzy/code-make/releases/tag/v3.3.0)
413

514
> 5 May 2025

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "code-make",
33
"displayName": "Code Make",
44
"description": "Simplify C, C++, Go, and Java project creation and compilation with Make.",
5-
"version": "3.3.0",
5+
"version": "3.3.1",
66
"publisher": "drizzy",
77
"license": "MIT",
88
"icon": "icon/makefile.png",
@@ -90,6 +90,7 @@
9090
"eslint": "^8.54.0",
9191
"glob": "^11.0.1",
9292
"lodash": "^4.17.21",
93+
"ps-list": "^8.1.1",
9394
"typescript": "^5.3.2"
9495
}
95-
}
96+
}

src/manager/MakefileManager.ts

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from 'vscode';
2+
import * as os from 'os';
23
import * as path from 'path';
34
import { FileManager } from '../manager/FileManager';
45
import { ConfigManager } from '../manager/ConfigManager';
@@ -11,7 +12,6 @@ export class MakefileManager {
1112
private _config: ConfigManager;
1213
private _terminal: TerminalManager;
1314
private _watcher: WatcherManager;
14-
private _isRunning: boolean = false;
1515

1616
constructor() {
1717
this._file = new FileManager();
@@ -75,27 +75,66 @@ export class MakefileManager {
7575
return;
7676
}
7777

78-
this._isRunning = true;
7978
this._watcher.updateStatusBar();
8079
this._terminal.runCommand('make run');
8180
}
8281

83-
public stop() {
84-
if (!this._isRunning) {
82+
public async stop() {
83+
const programName = this._file.getProgramNameFromMakefile();
84+
85+
if (!programName) {
86+
vscode.window.showErrorMessage('The name of the program to stop could not be determined.');
8587
return;
8688
}
87-
88-
this._isRunning = false;
89-
89+
9090
try {
91+
const isWin = os.platform() === 'win32';
92+
const psList = (await import('ps-list')).default;
93+
const processes = await psList();
94+
let processFound = false;
95+
96+
for (const p of processes) {
97+
const nameMatch = p.name === programName || p.name === `${programName}.exe`;
98+
const cmdMatch = p.cmd && p.cmd.includes(programName);
99+
100+
if (nameMatch || cmdMatch) {
101+
processFound = true;
102+
try {
103+
process.kill(p.pid, isWin ? undefined : 'SIGKILL');
104+
console.log(`Killed process: ${p.name} (PID: ${p.pid})`);
105+
} catch (killError) {
106+
console.error(`Failed to kill process ${p.pid}:`, killError);
107+
}
108+
}
109+
}
110+
111+
const orphanedTerminals = vscode.window.terminals.filter(t => t.name === 'CodeMake');
112+
for (const terminal of orphanedTerminals) {
113+
try {
114+
terminal.dispose();
115+
console.log(`Disposed orphaned terminal: ${terminal.name}`);
116+
} catch (disposeError) {
117+
console.error('Failed to dispose terminal:', disposeError);
118+
}
119+
}
120+
91121
if (this._terminal) {
92-
this._terminal.dispose;
122+
try {
123+
this._terminal.dispose();
124+
} catch (disposeError) {
125+
console.error('Failed to dispose current terminal:', disposeError);
126+
}
93127
}
128+
129+
if (!processFound) {
130+
vscode.window.showWarningMessage('No running process was found to stop.');
131+
}
132+
94133
} catch (e) {
95-
vscode.window.showErrorMessage('Failed to stop project.');
134+
const error = e as Error;
135+
vscode.window.showErrorMessage(`Failed to stop process: ${error.message}`);
96136
} finally {
97-
this._watcher.updateStatusBar();
137+
this._watcher?.updateStatusBar();
98138
}
99139
}
100-
101140
}

src/manager/ProcessManager.ts

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import * as vscode from 'vscode';
2-
import * as process from 'child_process';
3-
import * as os from 'os';
42
import { StatusBarItems } from '../utils/types';
53

64
export class ProcessManager {
@@ -24,44 +22,33 @@ export class ProcessManager {
2422
return this._isProcessRunning;
2523
}
2624

27-
private isProcessRunning(processName: string): boolean {
28-
29-
try {
30-
31-
const isWindows = os.platform() === "win32";
32-
33-
let command = isWindows ? `tasklist /FI "IMAGENAME eq ${processName}.exe"` : `ps aux`;
34-
35-
const output = process.execSync(command, { stdio: 'pipe' }).toString();
25+
private async isProcessRunning(processName: string): Promise<boolean> {
26+
const psList = (await import('ps-list')).default;
3627

37-
const lines = output.split('\n');
38-
for (const line of lines) {
39-
if (line.includes(processName) && !line.includes('grep')) {
40-
return true;
41-
}
42-
}
43-
return false;
44-
} catch (e) {
45-
return false;
46-
}
28+
const processes = await psList();
29+
return processes.some(p =>
30+
p.name === processName || p.name === `${processName}.exe`
31+
);
4732
}
4833

49-
public monitorProcess(processName: string) {
50-
34+
public async monitorProcess(processName: string) {
5135
if (!this._isProcessRunning) {
52-
this.toggleProcessButtons(this.isProcessRunning(processName));
36+
const running = await this.isProcessRunning(processName);
37+
this.toggleProcessButtons(running);
38+
this._isProcessRunning = running;
5339
}
5440

5541
if (this._isRunningCheckInterval) {
5642
clearInterval(this._isRunningCheckInterval);
5743
}
5844

59-
this._isRunningCheckInterval = setInterval(() => {
60-
const isRunning = this.isProcessRunning(processName);
45+
this._isRunningCheckInterval = setInterval(async () => {
46+
const isRunning = await this.isProcessRunning(processName);
6147
if (isRunning !== this._isProcessRunning) {
6248
this.toggleProcessButtons(isRunning);
49+
this._isProcessRunning = isRunning;
6350
}
64-
}, 1000);
51+
}, 500);
6552
}
6653

6754
private toggleProcessButtons(isRunning: boolean) {

src/manager/TerminalManager.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ export class TerminalManager {
2121

2222
}
2323

24-
public get dispose() {
24+
public dispose(): void {
2525
if (this._terminal) {
26-
return this._terminal.dispose();
26+
this._terminal.dispose();
27+
this._terminal = undefined;
2728
}
28-
return undefined;
2929
}
30-
3130
}

0 commit comments

Comments
 (0)