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 3.0.1 to 4.0.0

16

index.js

@@ -6,5 +6,9 @@ 'use strict';

return require('./lib/macos')();
} else if (process.platform === 'linux') {
}
if (process.platform === 'linux') {
return require('./lib/linux')();
} else if (process.platform === 'win32') {
}
if (process.platform === 'win32') {
return require('./lib/windows')();

@@ -19,5 +23,9 @@ }

return require('./lib/macos').sync();
} else if (process.platform === 'linux') {
}
if (process.platform === 'linux') {
return require('./lib/linux').sync();
} else if (process.platform === 'win32') {
}
if (process.platform === 'win32') {
return require('./lib/windows').sync();

@@ -24,0 +32,0 @@ }

'use strict';
const util = require('util');
const childProcess = require('child_process');
const pify = require('pify');
const execFile = util.promisify(childProcess.execFile);
const xpropBin = 'xprop';

@@ -10,4 +11,3 @@ const xpropActiveArgs = ['-root', '\t$0', '_NET_ACTIVE_WINDOW'];

const parseLinux = linuxData => {
const stdout = linuxData.stdout;
const activeWindowId = linuxData.activeWindowId;
const {stdout, activeWindowId} = linuxData;

@@ -17,7 +17,7 @@ const result = {};

if (row.includes('=')) {
const parts = row.split('=');
result[parts[0].trim()] = parts[1].trim();
const [key, value] = row.split('=');
result[key.trim()] = value.trim();
} else if (row.includes(':')) {
const parts = row.split(':');
result[parts[0].trim()] = parts[1].trim();
const [key, value] = row.split(':');
result[key.trim()] = value.trim();
}

@@ -43,14 +43,11 @@ }

module.exports = () => {
return pify(childProcess.execFile)(xpropBin, xpropActiveArgs).then(
activeWindowIdStdout => {
const activeWindowId = getActiveWindowId(activeWindowIdStdout);
return pify(childProcess.execFile)(xpropBin, xpropDetailsArgs.concat(activeWindowId)).then(stdout => {
return {
activeWindowId,
stdout
};
});
}
).then(parseLinux);
module.exports = async () => {
const {stdout: activeWindowIdStdout} = await execFile(xpropBin, xpropActiveArgs);
const activeWindowId = getActiveWindowId(activeWindowIdStdout);
const {stdout} = await execFile(xpropBin, xpropDetailsArgs.concat(activeWindowId));
return parseLinux({
activeWindowId,
stdout
});
};

@@ -62,2 +59,3 @@

const stdout = childProcess.execFileSync(xpropBin, xpropDetailsArgs.concat(activeWindowId), {encoding: 'utf8'});
return parseLinux({

@@ -64,0 +62,0 @@ activeWindowId,

'use strict';
const path = require('path');
const util = require('util');
const childProcess = require('child_process');
const pify = require('pify');
const execFile = util.promisify(childProcess.execFile);
const bin = path.join(__dirname, '../main');

@@ -11,4 +12,4 @@

return JSON.parse(stdout);
} catch (err) {
console.error(err);
} catch (error) {
console.error(error);
throw new Error('Error parsing window data');

@@ -18,3 +19,7 @@ }

module.exports = () => pify(childProcess.execFile)(bin).then(parseMac);
module.exports = async () => {
const {stdout} = await execFile(bin);
return parseMac(stdout);
};
module.exports.sync = () => parseMac(childProcess.execFileSync(bin, {encoding: 'utf8'}));
/* eslint-disable import/no-unresolved */
'use strict';
const path = require('path');
const ffi = require('ffi');
const ffi = require('ffi-napi');
const wchar = require('ref-wchar');
const ref = require('ref');
const struct = require('ref-struct');
// Create the struct required to save the window bounds
const Rect = struct({
left: 'long',
top: 'long',
right: 'long',
bottom: 'long'
});
const RectPointer = ref.refType(Rect);
// Required by QueryFullProcessImageName

@@ -21,3 +31,6 @@ // https://msdn.microsoft.com/en-us/library/windows/desktop/ms684880(v=vs.85).aspx

// https://msdn.microsoft.com/en-us/library/windows/desktop/ms633522(v=vs.85).aspx
GetWindowThreadProcessId: ['uint32', ['pointer', 'uint32 *']]
GetWindowThreadProcessId: ['uint32', ['pointer', 'uint32 *']],
// Get window bounds function
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowrect
GetWindowRect: ['bool', ['pointer', RectPointer]]
});

@@ -82,2 +95,6 @@

kernel32.CloseHandle(processHandle);
// Create a new instance of Rect, the struct required by the `GetWindowRect` method
const bounds = new Rect();
// Get the window bounds and save it into the `bounds` variable
user32.GetWindowRect(activeWindowHandle, bounds.ref());

@@ -91,2 +108,8 @@ return {

path: processPath
},
bounds: {
x: bounds.left,
y: bounds.top,
width: bounds.right - bounds.left,
height: bounds.bottom - bounds.top
}

@@ -93,0 +116,0 @@ };

{
"name": "active-win",
"version": "3.0.1",
"version": "4.0.0",
"description": "Get metadata about the active window (title, id, bounds, owner, etc). Works on macOS, Linux, Windows.",

@@ -13,3 +13,3 @@ "license": "MIT",

"engines": {
"node": ">=4"
"node": ">=8"
},

@@ -49,14 +49,12 @@ "scripts": {

],
"dependencies": {
"pify": "^3.0.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
"ava": "^0.25.0",
"xo": "^0.23.0"
},
"optionalDependencies": {
"ffi": "^2.2.0",
"ffi-napi": "^2.4.3",
"ref": "^1.3.4",
"ref-wchar": "^1.0.2"
"ref-wchar": "^1.0.2",
"ref-struct": "^1.1.0"
}
}
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