Skip to content

Commit

Permalink
Require Node.js 18 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 30, 2024
1 parent 1de0ea8 commit d1a316d
Show file tree
Hide file tree
Showing 13 changed files with 344 additions and 307 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ jobs:
matrix:
node-version:
- 18
- 16
- 14
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ jobs:
- x64
node:
- 18
- 14
- 16
include:
- os: windows-latest
node: 18
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.9
import PackageDescription

let package = Package(
Expand Down
280 changes: 137 additions & 143 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,168 +1,162 @@
declare namespace activeWindow {
interface 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.
@default true
*/
readonly accessibilityPermission: boolean;

/**
Enable the screen recording permission check. _(macOS)_
export type Options = {
/**
Enable the accessibility 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 accessibility permission prompt on macOS versions 10.15 and newer. The `url` property won't be retrieved.
@default true
*/
readonly screenRecordingPermission: boolean;
}
@default true
*/
readonly accessibilityPermission: boolean;

interface BaseOwner {
/**
Name of the app.
*/
name: string;

/**
Process identifier
*/
processId: number;

/**
Path to the app.
*/
path: string;
}
/**
Enable the screen recording permission check. _(macOS)_
interface BaseResult {
/**
Window title.
*/
title: string;

/**
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;

/**
Window position and size.
*/
bounds: {
x: number;
y: number;
width: number;
height: number;
};

/**
App that owns the window.
*/
owner: BaseOwner;

/**
Memory usage by the window.
*/
memoryUsage: number;
}
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.
interface MacOSOwner extends BaseOwner {
/**
Bundle identifier.
*/
bundleId: string;
}
@default true
*/
readonly screenRecordingPermission: boolean;
};

interface MacOSResult extends BaseResult {
platform: 'macos';
export type BaseOwner = {
/**
Name of the app.
*/
name: string;

owner: MacOSOwner;
/**
Process identifier
*/
processId: number;

/**
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;
}
/**
Path to the app.
*/
path: string;
};

interface LinuxResult extends BaseResult {
platform: 'linux';
}
export type BaseResult = {
/**
Window title.
*/
title: string;

interface WindowsResult extends BaseResult {
platform: 'windows';
}
/**
Window identifier.
type Result = MacOSResult | LinuxResult | WindowsResult;
}
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;

declare const activeWindow: {
/**
Get metadata about the [active window](https://en.wikipedia.org/wiki/Active_window) (title, id, bounds, owner, etc).
@example
```
import activeWindow = require('active-win');
(async () => {
const result = await activeWindow();
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}.`);
}
})();
```
Window position and size.
*/
(options?: activeWindow.Options): Promise<activeWindow.Result | undefined>;
bounds: {
x: number;
y: number;
width: number;
height: number;
};

/**
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');
const result = activeWindow.sync();
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}.`);
}
}
```
App that owns the window.
*/
sync(options?: activeWindow.Options): activeWindow.Result | undefined;
owner: BaseOwner;

/**
Get metadata about all open windows.
Windows are returned in order from front to back.
Memory usage by the window.
*/
getOpenWindows(options?: activeWindow.Options): Promise<activeWindow.Result[]>;
memoryUsage: number;
};

// eslint-disable-next-line @typescript-eslint/naming-convention
export type MacOSOwner = {
/**
Get metadata about all open windows synchronously.
Bundle identifier.
*/
bundleId: string;
} & BaseOwner;

// eslint-disable-next-line @typescript-eslint/naming-convention
export type MacOSResult = {
platform: 'macos';

Windows are returned in order from front to back.
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.
*/
getOpenWindowsSync(options?: activeWindow.Options): activeWindow.Result[];
};
url?: string;
} & BaseResult;

export type LinuxResult = {
platform: 'linux';
} & BaseResult;

export type WindowsResult = {
platform: 'windows';
} & BaseResult;

export type Result = MacOSResult | LinuxResult | WindowsResult;

/**
Get metadata about the [active window](https://en.wikipedia.org/wiki/Active_window) (title, id, bounds, owner, etc).
@example
```
import {activeWindow} from 'active-win';
const result = await activeWindow();
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}.`);
}
```
*/
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).
@example
```
import {activeWindowSync} from 'active-win';
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}.`);
}
}
```
*/
export function activeWindowSync(options?: Options): Result | undefined;

/**
Get metadata about all open windows.
Windows are returned in order from front to back.
*/
export function openWindows(options?: Options): Promise<Result[]>;

/**
Get metadata about all open windows synchronously.
export = activeWindow;
Windows are returned in order from front to back.
*/
export function openWindowsSync(options?: Options): Result[];
Loading

0 comments on commit d1a316d

Please sign in to comment.