kill-tabs 4.0.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/cli.js CHANGED
@@ -10,6 +10,7 @@ const cli = meow(`
10
10
  --no-chromium Don't kill tabs in Chromium
11
11
  --no-chrome Don't kill tabs in Chrome
12
12
  --no-brave Don't kill tabs in Brave
13
+ --no-edge Don't kill tabs in Edge
13
14
  `, {
14
15
  importMeta: import.meta,
15
16
  flags: {
@@ -25,6 +26,10 @@ const cli = meow(`
25
26
  type: 'boolean',
26
27
  default: true,
27
28
  },
29
+ edge: {
30
+ type: 'boolean',
31
+ default: true,
32
+ },
28
33
  },
29
34
  });
30
35
 
package/index.js CHANGED
@@ -4,13 +4,13 @@ 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',
12
11
  chromium: process.platform === 'darwin' ? 'Chromium Helper' : 'chromium',
13
- brave: process.platform === 'darwin' ? 'Brave Helper' : 'brave',
12
+ brave: process.platform === 'darwin' ? 'Brave Browser Helper' : 'brave',
13
+ edge: process.platform === 'darwin' ? 'Microsoft Edge Helper' : 'edge',
14
14
  };
15
15
 
16
16
  if (options.chromium === false) {
@@ -25,6 +25,10 @@ export default async function killTabs(options = {}) {
25
25
  delete processes.brave;
26
26
  }
27
27
 
28
+ if (options.edge === false) {
29
+ delete processes.edge;
30
+ }
31
+
28
32
  const pids = list
29
33
  .filter(process_ =>
30
34
  Object.keys(processes).some(name => process_.cmd.includes(processes[name]))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kill-tabs",
3
- "version": "4.0.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",
@@ -29,6 +29,7 @@
29
29
  "cli",
30
30
  "chrome",
31
31
  "brave",
32
+ "edge",
32
33
  "browser",
33
34
  "tabs",
34
35
  "kill",
package/readme.md CHANGED
@@ -26,6 +26,7 @@ $ kill-tabs --help
26
26
  --no-chromium Don't kill tabs in Chromium
27
27
  --no-chrome Don't kill tabs in Chrome
28
28
  --no-brave Don't kill tabs in Brave
29
+ --no-edge Don't kill tabs in Edge
29
30
  ```
30
31
 
31
32
  ## API
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
  }));