Skip to content

Commit 348b8ed

Browse files
committed
refactor: Swap ps-tree for tree-kill because of WMIC removal
1 parent 37cc66d commit 348b8ed

File tree

5 files changed

+27
-30
lines changed

5 files changed

+27
-30
lines changed

package-lock.json

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"minimist": "^1.2.7",
5151
"node-7z": "3.0.0",
5252
"open": "^10.1.0",
53-
"ps-tree": "1.2.0",
5453
"react": "17.0.2",
5554
"react-color": "2.18.0",
5655
"react-contenteditable": "^3.3.7",
@@ -67,6 +66,7 @@
6766
"remark-gfm": "2.0.0",
6867
"tail": "2.0.3",
6968
"terminate": "2.6.1",
69+
"tree-kill": "^1.2.2",
7070
"typesafe-actions": "4.4.2",
7171
"uuid": "3.3.2",
7272
"uuid-validate": "0.0.3",

src/back/ManagedChildProcess.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { IBackProcessInfo, INamedBackProcessInfo, ProcessState } from '@shared/i
33
import * as Coerce from '@shared/utils/Coerce';
44
import { ChildProcess, spawn } from 'child_process';
55
import { EventEmitter } from 'events';
6-
import { kill as processKill } from 'process';
7-
import * as psTree from 'ps-tree';
86
import * as readline from 'readline';
9-
import { Disposable } from './util/lifecycle';
7+
import * as kill from 'tree-kill';
108
import { onServiceChange } from './util/events';
9+
import { Disposable } from './util/lifecycle';
1110

1211
const { str } = Coerce;
1312

@@ -183,27 +182,18 @@ export class ManagedChildProcess extends EventEmitter {
183182
}
184183

185184
private treeKill = async (PID: number): Promise<void> => {
186-
// This is a re-implementation of *just* the parts of tmbr that we need.
187-
// Did this because tmbr wasn't working, not sure why.
188-
// psTree takes a callback, so we wrap it in a promise.
189185
await new Promise<void>((resolve, reject) => {
190-
psTree(PID, async (error, children) => {
186+
kill(PID, (error) => {
191187
if (error) {
192188
reject(error);
193-
return;
189+
} else {
190+
resolve();
194191
}
195-
// Kill each child process.
196-
await Promise.all(children.map(async (child) => {
197-
processKill(Number(child.PID));
198-
}));
199-
resolve();
200192
});
201193
})
202194
.catch((error: any) => {
203195
log.error('Launcher', `Failed to kill process ${this.name} (${this.info.filename}) - ${error}`);
204196
});
205-
// Kill the parent process.
206-
processKill(PID);
207197
};
208198
/**
209199
* Set the state of the process.

src/back/util/misc.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ import { exitApp } from '@back/responses';
66
import { BackState, ShowMessageBoxFunc, ShowOpenDialogFunc, ShowSaveDialogFunc, StatusState } from '@back/types';
77
import { deepCopy, recursiveReplace, stringifyArray } from '@shared/Util';
88
import { BackOut, ComponentState } from '@shared/back/types';
9+
import { PlatformAppPath, PlatformAppPathSuggestions } from '@shared/curate/types';
910
import { getCurationFolder } from '@shared/curate/util';
1011
import { BrowserApplicationOpts } from '@shared/extensions/interfaces';
1112
import { IBackProcessInfo, INamedBackProcessInfo, IService, ProcessState } from '@shared/interfaces';
1213
import { LangContainer, LangFile, autoCode, getDefaultLocalization } from '@shared/lang';
1314
import { Legacy_IAdditionalApplicationInfo, Legacy_IGameInfo } from '@shared/legacy/interfaces';
15+
import { newGame } from '@shared/utils/misc';
1416
import * as child_process from 'child_process';
17+
import { AdditionalApp, Game, Tag } from 'flashpoint-launcher';
1518
import * as fs from 'fs-extra';
1619
import * as os from 'os';
1720
import * as path from 'path';
18-
import * as psTree from 'ps-tree';
21+
import * as kill from 'tree-kill';
1922
import { promisify } from 'util';
2023
import { uuid } from './uuid';
21-
import { AdditionalApp, Game, Tag } from 'flashpoint-launcher';
22-
import { newGame } from '@shared/utils/misc';
23-
import { PlatformAppPath, PlatformAppPathSuggestions } from '@shared/curate/types';
2424

2525
const unlink = promisify(fs.unlink);
2626

@@ -190,15 +190,12 @@ export async function exit(state: BackState, beforeProcessExit?: () => void | Pr
190190
.catch(e => { console.error(e); });
191191

192192
await new Promise<void>((resolve, reject) => {
193-
psTree(process.pid, async (error, children) => {
193+
kill(process.pid, (error) => {
194194
if (error) {
195195
reject(error);
196+
} else {
197+
resolve();
196198
}
197-
// Kill each child process.
198-
for (const child of children) {
199-
process.kill(Number(child.PID));
200-
}
201-
resolve();
202199
});
203200
});
204201
// Kill the parent process.

src/renderer/components/app.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,9 +1393,9 @@ export class App extends React.Component<AppProps> {
13931393
devConsole: this.props.main.devConsole,
13941394
creditsData: this.props.main.creditsData,
13951395
creditsDoneLoading: this.props.main.creditsDoneLoading,
1396-
selectedGameId: this.props.main.selectedGameId,
1397-
gameRunning: this.checkGameRunningMemo(this.props.main.selectedGameId, this.props.main.services),
1398-
selectedPlaylistId: this.props.main.selectedPlaylistId,
1396+
selectedGameId: currentView.selectedGame?.id,
1397+
gameRunning: this.checkGameRunningMemo(currentView.selectedGame?.id, this.props.main.services),
1398+
selectedPlaylistId: currentView.selectedPlaylist?.id,
13991399
onDeletePlaylist: this.onPlaylistDelete,
14001400
onUpdatePlaylist: this.onUpdatePlaylist,
14011401
wasNewGameClicked: this.props.main.wasNewGameClicked,
@@ -1720,6 +1720,7 @@ export class App extends React.Component<AppProps> {
17201720
};
17211721

17221722
private checkGameRunningMemo = memoizeOne((gameId: string | undefined, services: IService[]) => {
1723+
console.log('checking if running:' + gameId);
17231724
return gameId ? !!services.find(s => s.id === `game.${gameId}`) : false;
17241725
});
17251726

0 commit comments

Comments
 (0)