@miniben90/x-win 1.4.0 → 1.5.1
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 +31 -1
- package/index.d.ts +89 -0
- package/index.js +4 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -94,6 +94,36 @@ console.log(windows);
|
|
|
94
94
|
}]
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
+
### Subscribe to get the current active window
|
|
98
|
+
|
|
99
|
+
Thread will be start to check every `100ms` for a new active window (checking window title, window id and process id).
|
|
100
|
+
|
|
101
|
+
* `subscribeActiveWindow`: Create a subscription with a callback function
|
|
102
|
+
* `unsubscribeActiveWindow`: Remove a specific subscription
|
|
103
|
+
* `unsubscribeAllActiveWindow`: Remove all threads
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { subscribeActiveWindow, unsubscribeActiveWindow, unsubscribeAllActiveWindow } from '@miniben90/x-win';
|
|
108
|
+
|
|
109
|
+
const a = subscribeActiveWindow(activeWindow => {
|
|
110
|
+
console.log('test a', activeWindow);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const b = subscribeActiveWindow(activeWindow => {
|
|
114
|
+
console.log('test b', activeWindow);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
const c = subscribeActiveWindow(activeWindow => {
|
|
119
|
+
console.log('test c', activeWindow);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
setTimeout(() => unsubscribeActiveWindow(c), 5000);
|
|
123
|
+
|
|
124
|
+
setTimeout(() => unsubscribeAllActiveWindow(), 10000);
|
|
125
|
+
```
|
|
126
|
+
|
|
97
127
|
# Linux
|
|
98
128
|
|
|
99
129
|
Dependencies are required to be installed for development purposes.
|
|
@@ -103,7 +133,7 @@ sudo apt install libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0
|
|
|
103
133
|
```
|
|
104
134
|
|
|
105
135
|
> ⚠️**Warning**
|
|
106
|
-
> Recovery url is not available
|
|
136
|
+
> Recovery url is not available on linux
|
|
107
137
|
|
|
108
138
|
# Darwin
|
|
109
139
|
|
package/index.d.ts
CHANGED
|
@@ -39,5 +39,94 @@ export interface WindowInfo {
|
|
|
39
39
|
usage: UsageInfo
|
|
40
40
|
url: string
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Retrieve information 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 currently open windows.
|
|
59
|
+
* Returns an array of `WindowInfo`, each containing details about a specific open window.
|
|
60
|
+
*
|
|
61
|
+
* # Example
|
|
62
|
+
* ```javascript
|
|
63
|
+
* const windows = openWindows();
|
|
64
|
+
* for (let i = 0; i < windows.length; i++) {
|
|
65
|
+
* console.log(i, windows[i]);
|
|
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
|
+
*/
|
|
43
73
|
export function openWindows(): Array<WindowInfo>
|
|
74
|
+
/**
|
|
75
|
+
* Subscribe an observer thread to monitor changes in the active window.
|
|
76
|
+
*
|
|
77
|
+
* # Example
|
|
78
|
+
* ```javascript
|
|
79
|
+
* const a = subscribeActiveWindow((info) => {
|
|
80
|
+
* t.log(a, info);
|
|
81
|
+
* });
|
|
82
|
+
* const b = subscribeActiveWindow((info) => {
|
|
83
|
+
* t.log(b, info);
|
|
84
|
+
* });
|
|
85
|
+
* const c = subscribeActiveWindow((info) => {
|
|
86
|
+
* t.log(c, info);
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* unsubscribeAllActiveWindow();
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export function subscribeActiveWindow(callback: (info: WindowInfo) => void): number
|
|
93
|
+
/**
|
|
94
|
+
* Terminate and unsubscribe a specific observer using their ID.
|
|
95
|
+
*
|
|
96
|
+
* # Example
|
|
97
|
+
* ```javascript
|
|
98
|
+
* const a = subscribeActiveWindow((info) => {
|
|
99
|
+
* t.log(a, info);
|
|
100
|
+
* });
|
|
101
|
+
* const b = subscribeActiveWindow((info) => {
|
|
102
|
+
* t.log(b, info);
|
|
103
|
+
* });
|
|
104
|
+
* const c = subscribeActiveWindow((info) => {
|
|
105
|
+
* t.log(c, info);
|
|
106
|
+
* });
|
|
107
|
+
*
|
|
108
|
+
* unsubscribeActiveWindow(a);
|
|
109
|
+
* unsubscribeActiveWindow(b);
|
|
110
|
+
* unsubscribeActiveWindow(c);
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export function unsubscribeActiveWindow(threadId: number): void
|
|
114
|
+
/**
|
|
115
|
+
* Terminate and unsubscribe all observer threads monitoring changes in the active window.
|
|
116
|
+
*
|
|
117
|
+
* # Example
|
|
118
|
+
* ```javascript
|
|
119
|
+
* const a = subscribeActiveWindow((info) => {
|
|
120
|
+
* t.log(a, info);
|
|
121
|
+
* });
|
|
122
|
+
* const b = subscribeActiveWindow((info) => {
|
|
123
|
+
* t.log(b, info);
|
|
124
|
+
* });
|
|
125
|
+
* const c = subscribeActiveWindow((info) => {
|
|
126
|
+
* t.log(c, info);
|
|
127
|
+
* });
|
|
128
|
+
*
|
|
129
|
+
* unsubscribeAllActiveWindow();
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export function unsubscribeAllActiveWindow(): void
|
package/index.js
CHANGED
|
@@ -281,7 +281,10 @@ if (!nativeBinding) {
|
|
|
281
281
|
throw new Error(`Failed to load native binding`)
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
const { activeWindow, openWindows } = nativeBinding
|
|
284
|
+
const { activeWindow, openWindows, subscribeActiveWindow, unsubscribeActiveWindow, unsubscribeAllActiveWindow } = nativeBinding
|
|
285
285
|
|
|
286
286
|
module.exports.activeWindow = activeWindow
|
|
287
287
|
module.exports.openWindows = openWindows
|
|
288
|
+
module.exports.subscribeActiveWindow = subscribeActiveWindow
|
|
289
|
+
module.exports.unsubscribeActiveWindow = unsubscribeActiveWindow
|
|
290
|
+
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.
|
|
4
|
+
"version": "1.5.1",
|
|
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.
|
|
65
|
-
"@miniben90/x-win-darwin-x64": "1.
|
|
66
|
-
"@miniben90/x-win-linux-x64-gnu": "1.
|
|
67
|
-
"@miniben90/x-win-darwin-arm64": "1.
|
|
68
|
-
"@miniben90/x-win-win32-arm64-msvc": "1.
|
|
69
|
-
"@miniben90/x-win-win32-ia32-msvc": "1.
|
|
70
|
-
"@miniben90/x-win-darwin-universal": "1.
|
|
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"
|
|
71
71
|
}
|
|
72
72
|
}
|