Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

active-win

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

active-win - npm Package Compare versions

Comparing version 8.2.1 to 9.0.0

260

index.d.ts

@@ -1,168 +0,162 @@

declare namespace activeWindow {
interface Options {
/**
Enable the accessibility permission check. _(macOS)_
export type Options = {
/**
Enable the accessibility permission check. _(macOS)_
Setting this to `false` will prevent the accessibility permission prompt on macOS versions 10.15 and newer. The `url` property won't be retrieved.
Setting this to `false` will prevent the accessibility permission prompt on macOS versions 10.15 and newer. The `url` property won't be retrieved.
@default true
*/
readonly accessibilityPermission: boolean;
@default true
*/
readonly accessibilityPermission: boolean;
/**
Enable the screen recording permission check. _(macOS)_
/**
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.
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;
}
@default true
*/
readonly screenRecordingPermission: boolean;
};
interface BaseOwner {
/**
Name of the app.
*/
name: string;
export type BaseOwner = {
/**
Name of the app.
*/
name: string;
/**
Process identifier
*/
processId: number;
/**
Process identifier
*/
processId: number;
/**
Path to the app.
*/
path: string;
}
/**
Path to the app.
*/
path: string;
};
interface BaseResult {
/**
Window title.
*/
title: string;
export type BaseResult = {
/**
Window title.
*/
title: string;
/**
Window identifier.
/**
Window identifier.
On Windows, there isn't a clear notion of a "Window ID". Instead it returns the memory address of the window "handle" in the `id` property. That "handle" is unique per window, so it can be used to identify them. [Read more…](https://msdn.microsoft.com/en-us/library/windows/desktop/ms632597(v=vs.85).aspx#window_handle).
*/
id: number;
On Windows, there isn't a clear notion of a "Window ID". Instead it returns the memory address of the window "handle" in the `id` property. That "handle" is unique per window, so it can be used to identify them. [Read more…](https://msdn.microsoft.com/en-us/library/windows/desktop/ms632597(v=vs.85).aspx#window_handle).
*/
id: number;
/**
Window position and size.
*/
bounds: {
x: number;
y: number;
width: number;
height: number;
};
/**
Window position and size.
*/
bounds: {
x: number;
y: number;
width: number;
height: number;
};
/**
App that owns the window.
*/
owner: BaseOwner;
/**
App that owns the window.
*/
owner: BaseOwner;
/**
Memory usage by the window.
*/
memoryUsage: number;
}
/**
Memory usage by the window.
*/
memoryUsage: number;
};
interface MacOSOwner extends BaseOwner {
/**
Bundle identifier.
*/
bundleId: string;
}
// eslint-disable-next-line @typescript-eslint/naming-convention
export type MacOSOwner = {
/**
Bundle identifier.
*/
bundleId: string;
} & BaseOwner;
interface MacOSResult extends BaseResult {
platform: 'macos';
// eslint-disable-next-line @typescript-eslint/naming-convention
export type MacOSResult = {
platform: 'macos';
owner: MacOSOwner;
owner: MacOSOwner;
/**
URL of the active browser tab if the active window is Safari (includes Technology Preview), Chrome (includes Beta, Dev, and Canary), Edge (includes Beta, Dev, and Canary), Brave (includes Beta and Nightly), Mighty, Ghost Browser, WaveBox, Sidekick, Opera (includes Beta and Developer), or Vivaldi.
*/
url?: string;
}
/**
URL of the active browser tab if the active window is Safari (includes Technology Preview), Chrome (includes Beta, Dev, and Canary), Edge (includes Beta, Dev, and Canary), Brave (includes Beta and Nightly), Mighty, Ghost Browser, WaveBox, Sidekick, Opera (includes Beta and Developer), or Vivaldi.
*/
url?: string;
} & BaseResult;
interface LinuxResult extends BaseResult {
platform: 'linux';
}
export type LinuxResult = {
platform: 'linux';
} & BaseResult;
interface WindowsResult extends BaseResult {
platform: 'windows';
}
export type WindowsResult = {
platform: 'windows';
} & BaseResult;
type Result = MacOSResult | LinuxResult | WindowsResult;
}
export type Result = MacOSResult | LinuxResult | WindowsResult;
declare const activeWindow: {
/**
Get metadata about the [active window](https://en.wikipedia.org/wiki/Active_window) (title, id, bounds, owner, etc).
/**
Get metadata about the [active window](https://en.wikipedia.org/wiki/Active_window) (title, id, bounds, owner, etc).
@example
```
import activeWindow = require('active-win');
@example
```
import {activeWindow} from 'active-win';
(async () => {
const result = await activeWindow();
const result = await activeWindow();
if (!result) {
return;
}
if (!result) {
return;
}
if (result.platform === 'macos') {
// Among other fields, result.owner.bundleId is available on macOS.
console.log(`Process title is ${result.title} with bundle id ${result.owner.bundleId}.`);
} else if (result.platform === 'windows') {
console.log(`Process title is ${result.title} with path ${result.owner.path}.`);
} else {
console.log(`Process title is ${result.title} with path ${result.owner.path}.`);
}
})();
```
*/
(options?: activeWindow.Options): Promise<activeWindow.Result | undefined>;
if (result.platform === 'macos') {
// Among other fields, `result.owner.bundleId` is available on macOS.
console.log(`Process title is ${result.title} with bundle id ${result.owner.bundleId}.`);
} else if (result.platform === 'windows') {
console.log(`Process title is ${result.title} with path ${result.owner.path}.`);
} else {
console.log(`Process title is ${result.title} with path ${result.owner.path}.`);
}
```
*/
export function activeWindow(options?: Options): Promise<Result | undefined>;
/**
Get metadata about the [active window](https://en.wikipedia.org/wiki/Active_window) synchronously (title, id, bounds, owner, etc).
/**
Get metadata about the [active window](https://en.wikipedia.org/wiki/Active_window) synchronously (title, id, bounds, owner, etc).
@example
```
import activeWindow = require('active-win');
@example
```
import {activeWindowSync} from 'active-win';
const result = activeWindow.sync();
const result = activeWindowSync();
if (result) {
if (result.platform === 'macos') {
// Among other fields, result.owner.bundleId is available on macOS.
console.log(`Process title is ${result.title} with bundle id ${result.owner.bundleId}.`);
} else if (result.platform === 'windows') {
console.log(`Process title is ${result.title} with path ${result.owner.path}.`);
} else {
console.log(`Process title is ${result.title} with path ${result.owner.path}.`);
}
if (result) {
if (result.platform === 'macos') {
// Among other fields, `result.owner.bundleId` is available on macOS.
console.log(`Process title is ${result.title} with bundle id ${result.owner.bundleId}.`);
} else if (result.platform === 'windows') {
console.log(`Process title is ${result.title} with path ${result.owner.path}.`);
} else {
console.log(`Process title is ${result.title} with path ${result.owner.path}.`);
}
```
*/
sync(options?: activeWindow.Options): activeWindow.Result | undefined;
}
```
*/
export function activeWindowSync(options?: Options): Result | undefined;
/**
Get metadata about all open windows.
/**
Get metadata about all open windows.
Windows are returned in order from front to back.
*/
getOpenWindows(options?: activeWindow.Options): Promise<activeWindow.Result[]>;
Windows are returned in order from front to back.
*/
export function openWindows(options?: Options): Promise<Result[]>;
/**
Get metadata about all open windows synchronously.
/**
Get metadata about all open windows synchronously.
Windows are returned in order from front to back.
*/
getOpenWindowsSync(options?: activeWindow.Options): activeWindow.Result[];
};
export = activeWindow;
Windows are returned in order from front to back.
*/
export function openWindowsSync(options?: Options): Result[];

@@ -1,65 +0,85 @@

'use strict';
import process from 'node:process';
import {
activeWindowSync as activeWindowSyncMacOS,
openWindowsSync as openWindowsSyncMacOS,
} from './lib/macos.js';
import {
activeWindowSync as activeWindowSyncLinux,
openWindowsSync as openWindowsSyncLinux,
} from './lib/linux.js';
import {
activeWindowSync as activeWindowSyncWindows,
openWindowsSync as openWindowsSyncWindows,
} from './lib/windows.js';
module.exports = options => {
export async function activeWindow(options) {
if (process.platform === 'darwin') {
return require('./lib/macos.js')(options);
const {activeWindow} = await import('./lib/macos.js');
return activeWindow(options);
}
if (process.platform === 'linux') {
return require('./lib/linux.js')(options);
const {activeWindow} = await import('./lib/linux.js');
return activeWindow(options);
}
if (process.platform === 'win32') {
return require('./lib/windows.js')(options);
const {activeWindow} = await import('./lib/windows.js');
return activeWindow(options);
}
return Promise.reject(new Error('macOS, Linux, and Windows only'));
};
throw new Error('macOS, Linux, and Windows only');
}
module.exports.sync = options => {
export function activeWindowSync(options) {
if (process.platform === 'darwin') {
return require('./lib/macos.js').sync(options);
return activeWindowSyncMacOS(options);
}
if (process.platform === 'linux') {
return require('./lib/linux.js').sync(options);
return activeWindowSyncLinux(options);
}
if (process.platform === 'win32') {
return require('./lib/windows.js').sync(options);
return activeWindowSyncWindows(options);
}
throw new Error('macOS, Linux, and Windows only');
};
}
module.exports.getOpenWindows = options => {
export async function openWindows(options) {
if (process.platform === 'darwin') {
return require('./lib/macos.js').getOpenWindows(options);
const {openWindows} = await import('./lib/macos.js');
return openWindows(options);
}
if (process.platform === 'linux') {
return require('./lib/linux.js').getOpenWindows(options);
const {openWindows} = await import('./lib/linux.js');
return openWindows(options);
}
if (process.platform === 'win32') {
return require('./lib/windows.js').getOpenWindows(options);
const {openWindows} = await import('./lib/windows.js');
return openWindows(options);
}
return Promise.reject(new Error('macOS, Linux, and Windows only'));
};
throw new Error('macOS, Linux, and Windows only');
}
module.exports.getOpenWindowsSync = options => {
export function openWindowsSync(options) {
if (process.platform === 'darwin') {
return require('./lib/macos.js').getOpenWindowsSync(options);
return openWindowsSyncMacOS(options);
}
if (process.platform === 'linux') {
return require('./lib/linux.js').getOpenWindowsSync(options);
return openWindowsSyncLinux(options);
}
if (process.platform === 'win32') {
return require('./lib/windows.js').getOpenWindowsSync(options);
return openWindowsSyncWindows(options);
}
throw new Error('macOS, Linux, and Windows only');
};
}
// Note to self: The `main` field in package.json is requried for pre-gyp.

@@ -1,5 +0,5 @@

'use strict';
const {promisify} = require('util');
const fs = require('fs');
const childProcess = require('child_process');
import process from 'node:process';
import {promisify} from 'node:util';
import fs from 'node:fs';
import childProcess from 'node:child_process';

@@ -10,7 +10,7 @@ const execFile = promisify(childProcess.execFile);

const xpropBin = 'xprop';
const xwininfoBin = 'xwininfo';
const xpropActiveArgs = ['-root', '\t$0', '_NET_ACTIVE_WINDOW'];
const xpropOpenArgs = ['-root', '_NET_CLIENT_LIST_STACKING'];
const xpropDetailsArgs = ['-id'];
const xpropBinary = 'xprop';
const xwininfoBinary = 'xwininfo';
const xpropActiveArguments = ['-root', '\t$0', '_NET_ACTIVE_WINDOW'];
const xpropOpenArguments = ['-root', '_NET_CLIENT_LIST_STACKING'];
const xpropDetailsArguments = ['-id'];

@@ -39,4 +39,4 @@ const processOutput = output => {

const resultKeys = Object.keys(result);
const windowId = (resultKeys.indexOf(windowIdProperty) > 0 &&
Number.parseInt(result[windowIdProperty].split('#').pop(), 16)) || activeWindowId;
const windowId = (resultKeys.indexOf(windowIdProperty) > 0
&& Number.parseInt(result[windowIdProperty].split('#').pop(), 16)) || activeWindowId;

@@ -55,3 +55,3 @@ const processId = Number.parseInt(result['_NET_WM_PID(CARDINAL)'], 10);

name: JSON.parse(result['WM_CLASS(STRING)'].split(',').pop()),
processId
processId,
},

@@ -62,4 +62,4 @@ bounds: {

width: Number.parseInt(bounds.Width, 10),
height: Number.parseInt(bounds.Height, 10)
}
height: Number.parseInt(bounds.Height, 10),
},
};

@@ -76,9 +76,7 @@ };

const getMemoryUsageByPidSync = pid => {
const statm = require('fs').readFileSync(`/proc/${pid}/statm`, 'utf8');
const statm = fs.readFileSync(`/proc/${pid}/statm`, 'utf8');
return Number.parseInt(statm.split(' ')[1], 10) * 4096;
};
const getPathByPid = pid => {
return readlink(`/proc/${pid}/exe`);
};
const getPathByPid = pid => readlink(`/proc/${pid}/exe`);

@@ -93,4 +91,4 @@ const getPathByPidSync = pid => {

const [{stdout}, {stdout: boundsStdout}] = await Promise.all([
execFile(xpropBin, [...xpropDetailsArgs, windowId], {env: {...process.env, LC_ALL: 'C.utf8'}}),
execFile(xwininfoBin, [...xpropDetailsArgs, windowId])
execFile(xpropBinary, [...xpropDetailsArguments, windowId], {env: {...process.env, LC_ALL: 'C.utf8'}}),
execFile(xwininfoBinary, [...xpropDetailsArguments, windowId]),
]);

@@ -101,7 +99,7 @@

boundsStdout,
stdout
stdout,
});
const [memoryUsage, path] = await Promise.all([
getMemoryUsageByPid(data.owner.processId),
getPathByPid(data.owner.processId).catch(() => {})
getPathByPid(data.owner.processId).catch(() => {}),
]);

@@ -114,4 +112,4 @@ data.memoryUsage = memoryUsage;

function getWindowInformationSync(windowId) {
const stdout = childProcess.execFileSync(xpropBin, [...xpropDetailsArgs, windowId], {encoding: 'utf8', env: {...process.env, LC_ALL: 'C.utf8'}});
const boundsStdout = childProcess.execFileSync(xwininfoBin, [...xpropDetailsArgs, windowId], {encoding: 'utf8'});
const stdout = childProcess.execFileSync(xpropBinary, [...xpropDetailsArguments, windowId], {encoding: 'utf8', env: {...process.env, LC_ALL: 'C.utf8'}});
const boundsStdout = childProcess.execFileSync(xwininfoBinary, [...xpropDetailsArguments, windowId], {encoding: 'utf8'});

@@ -121,3 +119,3 @@ const data = parseLinux({

boundsStdout,
stdout
stdout,
});

@@ -129,5 +127,5 @@ data.memoryUsage = getMemoryUsageByPidSync(data.owner.processId);

module.exports = async () => {
export async function activeWindow() {
try {
const {stdout: activeWindowIdStdout} = await execFile(xpropBin, xpropActiveArgs);
const {stdout: activeWindowIdStdout} = await execFile(xpropBinary, xpropActiveArguments);
const activeWindowId = getActiveWindowId(activeWindowIdStdout);

@@ -143,7 +141,7 @@

}
};
}
module.exports.sync = () => {
export function activeWindowSync() {
try {
const activeWindowIdStdout = childProcess.execFileSync(xpropBin, xpropActiveArgs, {encoding: 'utf8'});
const activeWindowIdStdout = childProcess.execFileSync(xpropBinary, xpropActiveArguments, {encoding: 'utf8'});
const activeWindowId = getActiveWindowId(activeWindowIdStdout);

@@ -159,7 +157,8 @@

}
};
}
module.exports.getOpenWindows = async () => {
export async function openWindows() {
try {
const {stdout: openWindowIdStdout} = await execFile(xpropBin, xpropOpenArgs);
const {stdout: openWindowIdStdout} = await execFile(xpropBinary, xpropOpenArguments);
// Get open windows Ids

@@ -182,7 +181,7 @@ const windowsIds = openWindowIdStdout.split('#')[1].trim().replace('\n', '').split(',');

}
};
}
module.exports.getOpenWindowsSync = () => {
export function openWindowsSync() {
try {
const openWindowIdStdout = childProcess.execFileSync(xpropBin, xpropOpenArgs, {encoding: 'utf8'});
const openWindowIdStdout = childProcess.execFileSync(xpropBinary, xpropOpenArguments, {encoding: 'utf8'});
const windowsIds = openWindowIdStdout.split('#')[1].trim().replace('\n', '').split(',');

@@ -206,2 +205,2 @@

}
};
}

@@ -1,8 +0,10 @@

'use strict';
const path = require('path');
const {promisify} = require('util');
const childProcess = require('child_process');
import path from 'node:path';
import {promisify} from 'node:util';
import childProcess from 'node:child_process';
import {fileURLToPath} from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const execFile = promisify(childProcess.execFile);
const bin = path.join(__dirname, '../main');
const binary = path.join(__dirname, '../main');

@@ -23,32 +25,32 @@ const parseMac = stdout => {

const args = [];
const arguments_ = [];
if (options.accessibilityPermission === false) {
args.push('--no-accessibility-permission');
arguments_.push('--no-accessibility-permission');
}
if (options.screenRecordingPermission === false) {
args.push('--no-screen-recording-permission');
arguments_.push('--no-screen-recording-permission');
}
return args;
return arguments_;
};
module.exports = async options => {
const {stdout} = await execFile(bin, getArguments(options));
export async function activeWindow(options) {
const {stdout} = await execFile(binary, getArguments(options));
return parseMac(stdout);
};
}
module.exports.sync = options => {
const stdout = childProcess.execFileSync(bin, getArguments(options), {encoding: 'utf8'});
export function activeWindowSync(options) {
const stdout = childProcess.execFileSync(binary, getArguments(options), {encoding: 'utf8'});
return parseMac(stdout);
};
}
module.exports.getOpenWindows = async options => {
const {stdout} = await execFile(bin, [...getArguments(options), '--open-windows-list']);
export async function openWindows(options) {
const {stdout} = await execFile(binary, [...getArguments(options), '--open-windows-list']);
return parseMac(stdout);
};
}
module.exports.getOpenWindowsSync = options => {
const stdout = childProcess.execFileSync(bin, [...getArguments(options), '--open-windows-list'], {encoding: 'utf8'});
export function openWindowsSync(options) {
const stdout = childProcess.execFileSync(binary, [...getArguments(options), '--open-windows-list'], {encoding: 'utf8'});
return parseMac(stdout);
};
}

@@ -1,9 +0,32 @@

const addon = require('./windows-binding.js');
import path from 'node:path';
import fs from 'node:fs';
import {fileURLToPath} from 'node:url';
import {createRequire} from 'node:module';
import preGyp from '@mapbox/node-pre-gyp';
module.exports = async () => addon.getActiveWindow();
const __dirname = path.dirname(fileURLToPath(import.meta.url));
module.exports.getOpenWindows = async () => addon.getOpenWindows();
const require = createRequire(import.meta.url);
module.exports.sync = addon.getActiveWindow;
const bindingPath = preGyp.find(path.resolve(path.join(__dirname, '../package.json')));
module.exports.getOpenWindowsSync = addon.getOpenWindows;
const addon = (fs.existsSync(bindingPath)) ? require(bindingPath) : {
getActiveWindow() {},
getOpenWindows() {},
};
export async function activeWindow() {
return addon.getActiveWindow();
}
export function activeWindowSync() {
return addon.getActiveWindow();
}
export function openWindows() {
return addon.getOpenWindows();
}
export function openWindowsSync() {
return addon.getOpenWindows();
}
{
"name": "active-win",
"version": "8.2.1",
"description": "Get metadata about the active window (title, id, bounds, owner, URL, etc)",
"version": "9.0.0",
"description": "Get metadata about the active window and open windows (title, id, bounds, owner, URL, etc)",
"license": "MIT",

@@ -16,8 +16,12 @@ "repository": {

},
"type": "module",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"main": "./index.js",
"sideEffects": false,
"engines": {
"node": ">=14"
"node": ">=18.18"
},
"main": "./index",
"types": "./index.d.ts",
"binary": {

@@ -30,4 +34,3 @@ "module_name": "node-active-win",

"napi_versions": [
3,
6
9
]

@@ -59,6 +62,7 @@ },

"window",
"win",
"windows",
"active",
"focused",
"current",
"open",
"title",

@@ -83,14 +87,14 @@ "name",

"devDependencies": {
"ava": "^2.4.0",
"tsd": "^0.14.0",
"xo": "^0.38.2",
"ava": "^6.1.2",
"tsd": "^0.31.0",
"xo": "^0.58.0",
"node-pre-gyp-github": "^1.4.4"
},
"optionalDependencies": {
"@mapbox/node-pre-gyp": "^1.0.10",
"node-addon-api": "^5.0.0",
"node-gyp": "^9.3.0"
"@mapbox/node-pre-gyp": "^1.0.11",
"node-addon-api": "^8.0.0",
"node-gyp": "^10.1.0"
},
"peerDependencies": {
"node-gyp": "^9.3.0"
"node-gyp": "^10.1.0"
},

@@ -101,6 +105,3 @@ "peerDependenciesMeta": {

}
},
"ava": {
"verbose": true
}
}
# active-win
Get metadata about the [active window](https://en.wikipedia.org/wiki/Active_window) (title, id, bounds, owner, URL, etc)
> Get metadata about the [active window](https://en.wikipedia.org/wiki/Active_window) and open windows (title, id, bounds, owner, URL, etc)

@@ -13,30 +13,30 @@ Works on macOS 10.14+, Linux ([note](#linux-support)), and Windows 7+.

**[This is an ESM package which requires you to use ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)**
## Usage
```js
const activeWindow = require('active-win');
import {activeWindow} from 'active-win';
(async () => {
console.log(await activeWindow(options));
/*
{
title: 'Unicorns - Google Search',
id: 5762,
bounds: {
x: 0,
y: 0,
height: 900,
width: 1440
},
owner: {
name: 'Google Chrome',
processId: 310,
bundleId: 'com.google.Chrome',
path: '/Applications/Google Chrome.app'
},
url: 'https://sindresorhus.com/unicorn',
memoryUsage: 11015432
}
*/
})();
console.log(await activeWindow(options));
/*
{
title: 'Unicorns - Google Search',
id: 5762,
bounds: {
x: 0,
y: 0,
height: 900,
width: 1440
},
owner: {
name: 'Google Chrome',
processId: 310,
bundleId: 'com.google.Chrome',
path: '/Applications/Google Chrome.app'
},
url: 'https://sindresorhus.com/unicorn',
memoryUsage: 11015432
}
*/
```

@@ -68,3 +68,3 @@

### activeWindow.sync(options?)
### activeWindowSync(options?)

@@ -94,3 +94,3 @@ Get metadata about the active window synchronously.

### activeWindow.getOpenWindows()
### openWindows()

@@ -101,5 +101,5 @@ Get metadata about all open windows.

Returns `Promise<activeWindow.Result[]>`.
Returns `Promise<Result[]>`.
### activeWindow.getOpenWindowsSync()
### openWindowsSync()

@@ -110,3 +110,3 @@ Get metadata about all open windows synchronously.

Returns `activeWindow.Result[]`.
Returns `Result[]`.

@@ -113,0 +113,0 @@ ## OS support

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc