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.
Files changed (3) hide show
  1. package/index.js +1 -2
  2. package/package.json +1 -1
  3. 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 processList = process.platform === 'win32' ? windows : psList;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kill-tabs",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "description": "Kill all Chrome tabs to improve performance, decrease battery usage, and save memory",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/kill-tabs",
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 command = 'wmic process where Caption=\'chrome.exe\' get CommandLine,ProcessId /format:list';
9
- const stdout = await promisify(childProcess.exec)(command, {maxBuffer: TEN_MEBIBYTE});
7
+ export default async function killTabs(options) {
8
+ const browsers = [];
10
9
 
11
- return execall(/CommandLine=(.+)\s+ProcessId=(\d+)/g, stdout).map(element => ({
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
  }));