kill-tabs 4.1.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -2
- package/package.json +1 -1
- package/windows.js +26 -4
package/index.js
CHANGED
|
@@ -4,8 +4,7 @@ import psList from 'ps-list';
|
|
|
4
4
|
import windows from './windows.js';
|
|
5
5
|
|
|
6
6
|
export default async function killTabs(options = {}) {
|
|
7
|
-
const
|
|
8
|
-
const list = await processList();
|
|
7
|
+
const list = process.platform === 'win32' ? await windows(options) : await psList();
|
|
9
8
|
|
|
10
9
|
const processes = {
|
|
11
10
|
chrome: process.platform === 'darwin' ? 'Chrome Helper' : 'chrome',
|
package/package.json
CHANGED
package/windows.js
CHANGED
|
@@ -4,11 +4,33 @@ import execall from 'execall';
|
|
|
4
4
|
|
|
5
5
|
const TEN_MEBIBYTE = 1024 * 1024 * 10;
|
|
6
6
|
|
|
7
|
-
export default async function killTabs() {
|
|
8
|
-
const
|
|
9
|
-
const stdout = await promisify(childProcess.exec)(command, {maxBuffer: TEN_MEBIBYTE});
|
|
7
|
+
export default async function killTabs(options) {
|
|
8
|
+
const browsers = [];
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
if (options.chromium) {
|
|
11
|
+
browsers.push('Caption=\'chromium.exe\'');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (options.chrome) {
|
|
15
|
+
browsers.push('Caption=\'chrome.exe\'');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (options.brave) {
|
|
19
|
+
browsers.push('Caption=\'brave.exe\'');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (options.edge) {
|
|
23
|
+
browsers.push('Caption=\'msedge.exe\'');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const arguments_ = ['process', 'where', browsers.join(' or '), 'get', 'CommandLine,ProcessId', '/format:list'];
|
|
27
|
+
const response = await promisify(childProcess.execFile)('wmic', arguments_, {maxBuffer: TEN_MEBIBYTE});
|
|
28
|
+
|
|
29
|
+
if (response.stderr && !response.stderr.includes('No Instance(s) Available.')) {
|
|
30
|
+
throw new Error('Failed to kill tabs.', {cause: new Error(response.stderr)});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return execall(/CommandLine=(.+)\s+ProcessId=(\d+)/g, response.stdout).map(element => ({
|
|
12
34
|
cmd: element.subMatches[0],
|
|
13
35
|
pid: Number.parseInt(element.subMatches[1], 10),
|
|
14
36
|
}));
|