@miniben90/x-win 1.5.0 → 1.6.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
@@ -16,7 +16,7 @@ npm i @miniben90/x-win
16
16
  yarn add @miniben90/x-win
17
17
  ```
18
18
 
19
- ## How to use
19
+ ## How to use x-win
20
20
 
21
21
  ### Get information about the currently active window
22
22
 
@@ -56,6 +56,18 @@ console.log(currentWindow);
56
56
  }
57
57
  ```
58
58
 
59
+ You can also use asynchronous methods instead. To do so, you just have to use `activeWindowAsync`, for example:
60
+
61
+ ```typescript
62
+ import { activeWindowAsync, type WindowInfo } from '@miniben90/x-win';
63
+
64
+ activeWindow()
65
+ .then((currentWindow: WindowInfo) => {
66
+ console.log(currentWindow);
67
+ });
68
+
69
+ ```
70
+
59
71
  ### Get a list of open windows with information
60
72
 
61
73
  `exemple.ts`:
@@ -94,6 +106,18 @@ console.log(windows);
94
106
  }]
95
107
  ```
96
108
 
109
+ You can also use asynchronous methods instead. To do so, you just have to use `openWindowsAsync`, for example:
110
+
111
+ ```typescript
112
+ import { openWindowsAsync, type WindowInfo } from '@miniben90/x-win';
113
+
114
+ openWindowsAsync()
115
+ .then((windows: WindowInfo[]) => {
116
+ console.log(windows);
117
+ });
118
+
119
+ ```
120
+
97
121
  ### Subscribe to get the current active window
98
122
 
99
123
  Thread will be start to check every `100ms` for a new active window (checking window title, window id and process id).
package/index.d.ts CHANGED
@@ -39,8 +39,130 @@ export interface WindowInfo {
39
39
  usage: UsageInfo
40
40
  url: string
41
41
  }
42
+ /**
43
+ * Retrieve information the about currently active window.
44
+ * Returns an object of `WindowInfo`.
45
+ *
46
+ * # Example
47
+ * ```javascript
48
+ * const currentWindow = activeWindow();
49
+ * console.log(currentWindow);
50
+ * ```
51
+ *
52
+ * # Information about Electron
53
+ *
54
+ * It is recommended to use this function within a worker to mitigate potential recovery issues on MacOS.
55
+ */
42
56
  export function activeWindow(): WindowInfo
57
+ /**
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.
76
+ * Returns an array of `WindowInfo`, each containing details about a specific open window.
77
+ *
78
+ * # Example
79
+ * ```javascript
80
+ * const windows = openWindows();
81
+ * for (let i = 0; i < windows.length; i++) {
82
+ * console.log(i, windows[i]);
83
+ * }
84
+ * ```
85
+ *
86
+ * # Information about Electron
87
+ *
88
+ * It is recommended to use this function within a worker to mitigate potential recovery issues on MacOS.
89
+ */
43
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>>
110
+ /**
111
+ * Subscribe an observer thread to monitor changes in the active window.
112
+ *
113
+ * # Example
114
+ * ```javascript
115
+ * const a = subscribeActiveWindow((info) => {
116
+ * t.log(a, info);
117
+ * });
118
+ * const b = subscribeActiveWindow((info) => {
119
+ * t.log(b, info);
120
+ * });
121
+ * const c = subscribeActiveWindow((info) => {
122
+ * t.log(c, info);
123
+ * });
124
+ *
125
+ * unsubscribeAllActiveWindow();
126
+ * ```
127
+ */
44
128
  export function subscribeActiveWindow(callback: (info: WindowInfo) => void): number
129
+ /**
130
+ * Terminate and unsubscribe a specific observer using their ID.
131
+ *
132
+ * # Example
133
+ * ```javascript
134
+ * const a = subscribeActiveWindow((info) => {
135
+ * t.log(a, info);
136
+ * });
137
+ * const b = subscribeActiveWindow((info) => {
138
+ * t.log(b, info);
139
+ * });
140
+ * const c = subscribeActiveWindow((info) => {
141
+ * t.log(c, info);
142
+ * });
143
+ *
144
+ * unsubscribeActiveWindow(a);
145
+ * unsubscribeActiveWindow(b);
146
+ * unsubscribeActiveWindow(c);
147
+ * ```
148
+ */
45
149
  export function unsubscribeActiveWindow(threadId: number): void
150
+ /**
151
+ * Terminate and unsubscribe all observer threads monitoring changes in the active window.
152
+ *
153
+ * # Example
154
+ * ```javascript
155
+ * const a = subscribeActiveWindow((info) => {
156
+ * t.log(a, info);
157
+ * });
158
+ * const b = subscribeActiveWindow((info) => {
159
+ * t.log(b, info);
160
+ * });
161
+ * const c = subscribeActiveWindow((info) => {
162
+ * t.log(c, info);
163
+ * });
164
+ *
165
+ * unsubscribeAllActiveWindow();
166
+ * ```
167
+ */
46
168
  export function unsubscribeAllActiveWindow(): void
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.0",
4
+ "version": "1.6.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.0",
65
- "@miniben90/x-win-darwin-x64": "1.5.0",
66
- "@miniben90/x-win-linux-x64-gnu": "1.5.0",
67
- "@miniben90/x-win-darwin-arm64": "1.5.0",
68
- "@miniben90/x-win-win32-arm64-msvc": "1.5.0",
69
- "@miniben90/x-win-win32-ia32-msvc": "1.5.0",
70
- "@miniben90/x-win-darwin-universal": "1.5.0"
64
+ "@miniben90/x-win-win32-x64-msvc": "1.6.0",
65
+ "@miniben90/x-win-darwin-x64": "1.6.0",
66
+ "@miniben90/x-win-linux-x64-gnu": "1.6.0",
67
+ "@miniben90/x-win-darwin-arm64": "1.6.0",
68
+ "@miniben90/x-win-win32-arm64-msvc": "1.6.0",
69
+ "@miniben90/x-win-win32-ia32-msvc": "1.6.0",
70
+ "@miniben90/x-win-darwin-universal": "1.6.0"
71
71
  }
72
72
  }