active-win
Advanced tools
Comparing version 6.3.0 to 7.0.0
@@ -1,2 +0,13 @@ | ||
declare namespace activeWin { | ||
declare namespace activeWindow { | ||
interface Options { | ||
/** | ||
Enable the screen recording permission check. _(macOS)_ | ||
Setting this to `false` will prevent the screen recording permission prompt on macOS versions 10.15 and newer. The `title` property in the result will always be set to an empty string. | ||
@default true | ||
*/ | ||
readonly screenRecordingPermission: boolean; | ||
} | ||
interface BaseOwner { | ||
@@ -82,3 +93,3 @@ /** | ||
declare const activeWin: { | ||
declare const activeWindow: { | ||
/** | ||
@@ -91,6 +102,6 @@ Get metadata about the [active window](https://en.wikipedia.org/wiki/Active_window) (title, id, bounds, owner, etc). | ||
``` | ||
import activeWin = require('active-win'); | ||
import activeWindow = require('active-win'); | ||
(async () => { | ||
const result = await activeWin(); | ||
const result = await activeWindow(); | ||
@@ -112,3 +123,3 @@ if (!result) { | ||
*/ | ||
(): Promise<activeWin.Result | undefined>; | ||
(options?: activeWindow.Options): Promise<activeWindow.Result | undefined>; | ||
@@ -122,5 +133,5 @@ /** | ||
``` | ||
import activeWin = require('active-win'); | ||
import activeWindow = require('active-win'); | ||
const result = activeWin.sync(); | ||
const result = activeWindow.sync(); | ||
@@ -139,5 +150,5 @@ if (result) { | ||
*/ | ||
sync(): activeWin.Result | undefined; | ||
sync(options?: activeWindow.Options): activeWindow.Result | undefined; | ||
}; | ||
export = activeWin; | ||
export = activeWindow; |
16
index.js
'use strict'; | ||
module.exports = () => { | ||
module.exports = options => { | ||
if (process.platform === 'darwin') { | ||
return require('./lib/macos')(); | ||
return require('./lib/macos')(options); | ||
} | ||
if (process.platform === 'linux') { | ||
return require('./lib/linux')(); | ||
return require('./lib/linux')(options); | ||
} | ||
if (process.platform === 'win32') { | ||
return require('./lib/windows')(); | ||
return require('./lib/windows')(options); | ||
} | ||
@@ -19,13 +19,13 @@ | ||
module.exports.sync = () => { | ||
module.exports.sync = options => { | ||
if (process.platform === 'darwin') { | ||
return require('./lib/macos').sync(); | ||
return require('./lib/macos').sync(options); | ||
} | ||
if (process.platform === 'linux') { | ||
return require('./lib/linux').sync(); | ||
return require('./lib/linux').sync(options); | ||
} | ||
if (process.platform === 'win32') { | ||
return require('./lib/windows').sync(); | ||
return require('./lib/windows').sync(options); | ||
} | ||
@@ -32,0 +32,0 @@ |
@@ -38,5 +38,5 @@ 'use strict'; | ||
const windowId = (resultKeys.indexOf(windowIdProperty) > 0 && | ||
parseInt(result[windowIdProperty].split('#').pop(), 16)) || activeWindowId; | ||
Number.parseInt(result[windowIdProperty].split('#').pop(), 16)) || activeWindowId; | ||
const processId = parseInt(result['_NET_WM_PID(CARDINAL)'], 10); | ||
const processId = Number.parseInt(result['_NET_WM_PID(CARDINAL)'], 10); | ||
@@ -56,6 +56,6 @@ if (Number.isNaN(processId)) { | ||
bounds: { | ||
x: parseInt(bounds['Absolute upper-left X'], 10), | ||
y: parseInt(bounds['Absolute upper-left Y'], 10), | ||
width: parseInt(bounds.Width, 10), | ||
height: parseInt(bounds.Height, 10) | ||
x: Number.parseInt(bounds['Absolute upper-left X'], 10), | ||
y: Number.parseInt(bounds['Absolute upper-left Y'], 10), | ||
width: Number.parseInt(bounds.Width, 10), | ||
height: Number.parseInt(bounds.Height, 10) | ||
} | ||
@@ -65,7 +65,7 @@ }; | ||
const getActiveWindowId = activeWindowIdStdout => parseInt(activeWindowIdStdout.split('\t')[1], 16); | ||
const getActiveWindowId = activeWindowIdStdout => Number.parseInt(activeWindowIdStdout.split('\t')[1], 16); | ||
const getMemoryUsageByPid = async pid => { | ||
const statm = await readFile(`/proc/${pid}/statm`, 'utf8'); | ||
return parseInt(statm.split(' ')[1], 10) * 4096; | ||
return Number.parseInt(statm.split(' ')[1], 10) * 4096; | ||
}; | ||
@@ -75,3 +75,3 @@ | ||
const statm = require('fs').readFileSync(`/proc/${pid}/statm`, 'utf8'); | ||
return parseInt(statm.split(' ')[1], 10) * 4096; | ||
return Number.parseInt(statm.split(' ')[1], 10) * 4096; | ||
}; | ||
@@ -97,4 +97,4 @@ | ||
const [{stdout}, {stdout: boundsStdout}] = await Promise.all([ | ||
execFile(xpropBin, xpropDetailsArgs.concat([activeWindowId])), | ||
execFile(xwininfoBin, xpropDetailsArgs.concat([activeWindowId])) | ||
execFile(xpropBin, [...xpropDetailsArgs, activeWindowId]), | ||
execFile(xwininfoBin, [...xpropDetailsArgs, activeWindowId]) | ||
]); | ||
@@ -114,3 +114,3 @@ | ||
return data; | ||
} catch (_) { | ||
} catch { | ||
return undefined; | ||
@@ -129,4 +129,4 @@ } | ||
const stdout = childProcess.execFileSync(xpropBin, xpropDetailsArgs.concat(activeWindowId), {encoding: 'utf8'}); | ||
const boundsStdout = childProcess.execFileSync(xwininfoBin, xpropDetailsArgs.concat([activeWindowId]), {encoding: 'utf8'}); | ||
const stdout = childProcess.execFileSync(xpropBin, [...xpropDetailsArgs, activeWindowId], {encoding: 'utf8'}); | ||
const boundsStdout = childProcess.execFileSync(xwininfoBin, [...xpropDetailsArgs, activeWindowId], {encoding: 'utf8'}); | ||
@@ -141,5 +141,5 @@ const data = parseLinux({ | ||
return data; | ||
} catch (_) { | ||
} catch { | ||
return undefined; | ||
} | ||
}; |
@@ -22,7 +22,23 @@ 'use strict'; | ||
module.exports = async () => { | ||
const {stdout} = await execFile(bin); | ||
const getArguments = options => { | ||
if (!options) { | ||
return []; | ||
} | ||
const args = []; | ||
if (options.screenRecordingPermission === false) { | ||
args.push('--no-screen-recording-permission'); | ||
} | ||
return args; | ||
}; | ||
module.exports = async options => { | ||
const {stdout} = await execFile(bin, getArguments(options)); | ||
return parseMac(stdout); | ||
}; | ||
module.exports.sync = () => parseMac(childProcess.execFileSync(bin, {encoding: 'utf8'})); | ||
module.exports.sync = options => { | ||
const stdout = childProcess.execFileSync(bin, getArguments(options), {encoding: 'utf8'}); | ||
return parseMac(stdout); | ||
}; |
{ | ||
"name": "active-win", | ||
"version": "6.3.0", | ||
"version": "7.0.0", | ||
"description": "Get metadata about the active window (title, id, bounds, owner, URL, etc). Works on macOS, Linux, Windows.", | ||
@@ -14,3 +14,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=10" | ||
}, | ||
@@ -20,3 +20,3 @@ "scripts": { | ||
"build": "swift build --configuration=release && mv .build/release/active-win main", | ||
"prepublishOnly": "npm run build" | ||
"prepare": "npm run build" | ||
}, | ||
@@ -60,11 +60,14 @@ "files": [ | ||
"ava": "^2.4.0", | ||
"tsd": "^0.10.0", | ||
"xo": "^0.25.3" | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.2" | ||
}, | ||
"optionalDependencies": { | ||
"ffi-napi": "^2.4.5", | ||
"ref-napi": "^3.0.0", | ||
"ref-struct-napi": "^1.1.0", | ||
"ref-wchar-napi": "^1.0.2" | ||
"ffi-napi": "^4.0.3", | ||
"ref-napi": "^3.0.2", | ||
"ref-struct-napi": "^1.1.1", | ||
"ref-wchar-napi": "^1.0.3" | ||
}, | ||
"ava": { | ||
"verbose": true | ||
} | ||
} |
@@ -18,6 +18,6 @@ # active-win | ||
```js | ||
const activeWin = require('active-win'); | ||
const activeWindow = require('active-win'); | ||
(async () => { | ||
console.log(await activeWin()); | ||
console.log(await activeWindow(options)); | ||
/* | ||
@@ -49,12 +49,21 @@ { | ||
### activeWin() | ||
### activeWindow(options?) | ||
Returns a `Promise<Object>` with the result, or `Promise<undefined>` if there is no active window or if the information is not available. | ||
#### options | ||
### activeWin.sync() | ||
Type: `object` | ||
Returns an `Object` with the result, or `undefined` if there is no active window. | ||
##### screenRecordingPermission **(macOS only)** | ||
Type: `boolean`\ | ||
Default: `true` | ||
Enable the screen recording permission check. Setting this to `false` will prevent the screen recording permission prompt on macOS versions 10.15 and newer. The `title` property in the result will always be set to an empty string. | ||
### activeWindow.sync(options?) | ||
## Result | ||
Returns a `Promise<object>` with the result, or `Promise<undefined>` if there is no active window or if the information is not available. | ||
- `platform` *(string)* - `'macos'` | `'linux'` | `'windows'` | ||
@@ -61,0 +70,0 @@ - `title` *(string)* - Window title |
Sorry, the diff of this file is not supported yet
154020
486
98