@miniben90/x-win 1.5.1 → 1.7.0

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/README.md CHANGED
@@ -1,10 +1,12 @@
1
+ # @miniben90/x-win
2
+
1
3
  [![CI](https://github.com/miniben-90/x-win/actions/workflows/CI.yml/badge.svg)](https://github.com/miniben-90/x-win/actions/workflows/CI.yml)
2
4
  [![Node version](https://img.shields.io/node/v/@miniben90/x-win.svg)](https://www.npmjs.com/package/@miniben90/x-win)
3
5
  ![npm type definitions](https://img.shields.io/npm/types/@miniben90/x-win)
6
+ ![NPM License](https://img.shields.io/npm/l/@miniben90/x-win)
7
+ ![NPM Version](https://img.shields.io/npm/v/%40miniben90%2Fx-win)
4
8
 
5
- # @miniben90/x-win
6
-
7
- This project uses Rust and napi-rs to make it easy to obtain the active window or an array of open windows. It works on Microsoft Windows (10, 11), [Linux (with X server)](#linux), and [macOS](#darwin).
9
+ This project uses Rust and napi-rs to make it easy to obtain the active window or an array of open windows. It works on Microsoft Windows (10, 11), [Linux (with X server)](#linux), and [macOS 10.6+](#darwin).
8
10
 
9
11
  ## How to install
10
12
 
@@ -16,7 +18,7 @@ npm i @miniben90/x-win
16
18
  yarn add @miniben90/x-win
17
19
  ```
18
20
 
19
- ## How to use
21
+ ## How to use x-win
20
22
 
21
23
  ### Get information about the currently active window
22
24
 
@@ -56,6 +58,18 @@ console.log(currentWindow);
56
58
  }
57
59
  ```
58
60
 
61
+ You can also use asynchronous methods instead. To do so, you just have to use `activeWindowAsync`, for example:
62
+
63
+ ```typescript
64
+ import { activeWindowAsync, type WindowInfo } from '@miniben90/x-win';
65
+
66
+ activeWindow()
67
+ .then((currentWindow: WindowInfo) => {
68
+ console.log(currentWindow);
69
+ });
70
+
71
+ ```
72
+
59
73
  ### Get a list of open windows with information
60
74
 
61
75
  `exemple.ts`:
@@ -94,6 +108,18 @@ console.log(windows);
94
108
  }]
95
109
  ```
96
110
 
111
+ You can also use asynchronous methods instead. To do so, you just have to use `openWindowsAsync`, for example:
112
+
113
+ ```typescript
114
+ import { openWindowsAsync, type WindowInfo } from '@miniben90/x-win';
115
+
116
+ openWindowsAsync()
117
+ .then((windows: WindowInfo[]) => {
118
+ console.log(windows);
119
+ });
120
+
121
+ ```
122
+
97
123
  ### Subscribe to get the current active window
98
124
 
99
125
  Thread will be start to check every `100ms` for a new active window (checking window title, window id and process id).
@@ -135,7 +161,7 @@ sudo apt install libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0
135
161
  > ⚠️**Warning**
136
162
  > Recovery url is not available on linux
137
163
 
138
- # Darwin
164
+ # Darwin (version 10.6+)
139
165
 
140
166
  ## Screen recording permission introduced in macOS 10.15 Catalina
141
167
 
package/index.d.ts CHANGED
@@ -40,7 +40,7 @@ export interface WindowInfo {
40
40
  url: string
41
41
  }
42
42
  /**
43
- * Retrieve information about currently active window.
43
+ * Retrieve information the about currently active window.
44
44
  * Returns an object of `WindowInfo`.
45
45
  *
46
46
  * # Example
@@ -55,7 +55,24 @@ export interface WindowInfo {
55
55
  */
56
56
  export function activeWindow(): WindowInfo
57
57
  /**
58
- * Retrieve information about currently open windows.
58
+ * Retrieve information about the currently active window as a promise.
59
+ * Returns an object of `WindowInfo`.
60
+ *
61
+ * # Example
62
+ * ```javascript
63
+ * activeWindow()
64
+ * .then(currentWindow => {
65
+ * console.log(currentWindow);
66
+ * });
67
+ * ```
68
+ *
69
+ * # Information about Electron
70
+ *
71
+ * It is recommended to use this function within a worker to mitigate potential recovery issues on MacOS.
72
+ */
73
+ export function activeWindowAsync(): Promise<WindowInfo>
74
+ /**
75
+ * Retrieve information about the currently open windows.
59
76
  * Returns an array of `WindowInfo`, each containing details about a specific open window.
60
77
  *
61
78
  * # Example
@@ -71,6 +88,25 @@ export function activeWindow(): WindowInfo
71
88
  * It is recommended to use this function within a worker to mitigate potential recovery issues on MacOS.
72
89
  */
73
90
  export function openWindows(): Array<WindowInfo>
91
+ /**
92
+ * Retrieve information about the currently open windows as a promise.
93
+ * Returns an array of `WindowInfo`, each containing details about a specific open window.
94
+ *
95
+ * # Example
96
+ * ```javascript
97
+ * openWindows()
98
+ * .then(windows => {
99
+ * for (let i = 0; i < windows.length; i++) {
100
+ * console.log(i, windows[i]);
101
+ * }
102
+ * });
103
+ * ```
104
+ *
105
+ * # Information about Electron
106
+ *
107
+ * It is recommended to use this function within a worker to mitigate potential recovery issues on MacOS.
108
+ */
109
+ export function openWindowsAsync(): Promise<Array<WindowInfo>>
74
110
  /**
75
111
  * Subscribe an observer thread to monitor changes in the active window.
76
112
  *
package/index.js CHANGED
@@ -281,10 +281,12 @@ if (!nativeBinding) {
281
281
  throw new Error(`Failed to load native binding`)
282
282
  }
283
283
 
284
- const { activeWindow, openWindows, subscribeActiveWindow, unsubscribeActiveWindow, unsubscribeAllActiveWindow } = nativeBinding
284
+ const { activeWindow, activeWindowAsync, openWindows, openWindowsAsync, subscribeActiveWindow, unsubscribeActiveWindow, unsubscribeAllActiveWindow } = nativeBinding
285
285
 
286
286
  module.exports.activeWindow = activeWindow
287
+ module.exports.activeWindowAsync = activeWindowAsync
287
288
  module.exports.openWindows = openWindows
289
+ module.exports.openWindowsAsync = openWindowsAsync
288
290
  module.exports.subscribeActiveWindow = subscribeActiveWindow
289
291
  module.exports.unsubscribeActiveWindow = unsubscribeActiveWindow
290
292
  module.exports.unsubscribeAllActiveWindow = unsubscribeAllActiveWindow
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@miniben90/x-win",
3
3
  "description": "This package allows you to retrieve precise information about active and open windows on Windows, MacOS, and Linux. You can obtain the position, size, title, and other memory of windows.",
4
- "version": "1.5.1",
4
+ "version": "1.7.0",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "files": [
@@ -61,12 +61,12 @@
61
61
  },
62
62
  "packageManager": "yarn@4.0.2",
63
63
  "optionalDependencies": {
64
- "@miniben90/x-win-win32-x64-msvc": "1.5.1",
65
- "@miniben90/x-win-darwin-x64": "1.5.1",
66
- "@miniben90/x-win-linux-x64-gnu": "1.5.1",
67
- "@miniben90/x-win-darwin-arm64": "1.5.1",
68
- "@miniben90/x-win-win32-arm64-msvc": "1.5.1",
69
- "@miniben90/x-win-win32-ia32-msvc": "1.5.1",
70
- "@miniben90/x-win-darwin-universal": "1.5.1"
64
+ "@miniben90/x-win-win32-x64-msvc": "1.7.0",
65
+ "@miniben90/x-win-darwin-x64": "1.7.0",
66
+ "@miniben90/x-win-linux-x64-gnu": "1.7.0",
67
+ "@miniben90/x-win-darwin-arm64": "1.7.0",
68
+ "@miniben90/x-win-win32-arm64-msvc": "1.7.0",
69
+ "@miniben90/x-win-win32-ia32-msvc": "1.7.0",
70
+ "@miniben90/x-win-darwin-universal": "1.7.0"
71
71
  }
72
72
  }