@miniben90/x-win 0.2.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/LICENSE +21 -0
- package/README.md +20 -0
- package/index.d.ts +42 -0
- package/index.js +252 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 BENKHADRA Hocine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# x-win
|
|
2
|
+
|
|
3
|
+
> This project work with Rust and napi-rs to make easy to have active window or an array of open windows.
|
|
4
|
+
> It work with Microsoft Windows (10, 11), Linux (With Xserver) and Macos(*).
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
Easy to install:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
# With npm
|
|
12
|
+
npm i x-win
|
|
13
|
+
|
|
14
|
+
# With yarn
|
|
15
|
+
yarn add x-win
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### (*)About Macos
|
|
19
|
+
|
|
20
|
+
> Macos require to grant access for recording screen. If your project don't have it the title will have `<unknown>` as value.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Struct to store usage data of the window
|
|
8
|
+
*/
|
|
9
|
+
export interface UsageInfo {
|
|
10
|
+
memory: number
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Struct to store process information of the window
|
|
14
|
+
*/
|
|
15
|
+
export interface ProcessInfo {
|
|
16
|
+
processId: number
|
|
17
|
+
path: string
|
|
18
|
+
name: string
|
|
19
|
+
execName: string
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Struct to store position and size of the window
|
|
23
|
+
*/
|
|
24
|
+
export interface WindowPosition {
|
|
25
|
+
x: number
|
|
26
|
+
y: number
|
|
27
|
+
width: number
|
|
28
|
+
height: number
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Struct to store all informations of the window
|
|
32
|
+
*/
|
|
33
|
+
export interface WindowInfo {
|
|
34
|
+
id: number
|
|
35
|
+
os: string
|
|
36
|
+
title: string
|
|
37
|
+
position: WindowPosition
|
|
38
|
+
info: ProcessInfo
|
|
39
|
+
usage: UsageInfo
|
|
40
|
+
}
|
|
41
|
+
export function activeWindow(): WindowInfo
|
|
42
|
+
export function openWindows(): Array<WindowInfo>
|
package/index.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
const { existsSync, readFileSync } = require('fs')
|
|
2
|
+
const { join } = require('path')
|
|
3
|
+
|
|
4
|
+
const { platform, arch } = process
|
|
5
|
+
|
|
6
|
+
let nativeBinding = null
|
|
7
|
+
let localFileExisted = false
|
|
8
|
+
let loadError = null
|
|
9
|
+
|
|
10
|
+
function isMusl() {
|
|
11
|
+
// For Node 10
|
|
12
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
13
|
+
try {
|
|
14
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim();
|
|
15
|
+
return readFileSync(lddPath, 'utf8').includes('musl')
|
|
16
|
+
} catch (e) {
|
|
17
|
+
return true
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
const { glibcVersionRuntime } = process.report.getReport().header
|
|
21
|
+
return !glibcVersionRuntime
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
switch (platform) {
|
|
26
|
+
case 'android':
|
|
27
|
+
switch (arch) {
|
|
28
|
+
case 'arm64':
|
|
29
|
+
localFileExisted = existsSync(join(__dirname, 'x-win.android-arm64.node'))
|
|
30
|
+
try {
|
|
31
|
+
if (localFileExisted) {
|
|
32
|
+
nativeBinding = require('./x-win.android-arm64.node')
|
|
33
|
+
} else {
|
|
34
|
+
nativeBinding = require('@miniben90/x-win-android-arm64')
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
loadError = e
|
|
38
|
+
}
|
|
39
|
+
break
|
|
40
|
+
case 'arm':
|
|
41
|
+
localFileExisted = existsSync(join(__dirname, 'x-win.android-arm-eabi.node'))
|
|
42
|
+
try {
|
|
43
|
+
if (localFileExisted) {
|
|
44
|
+
nativeBinding = require('./x-win.android-arm-eabi.node')
|
|
45
|
+
} else {
|
|
46
|
+
nativeBinding = require('@miniben90/x-win-android-arm-eabi')
|
|
47
|
+
}
|
|
48
|
+
} catch (e) {
|
|
49
|
+
loadError = e
|
|
50
|
+
}
|
|
51
|
+
break
|
|
52
|
+
default:
|
|
53
|
+
throw new Error(`Unsupported architecture on Android ${arch}`)
|
|
54
|
+
}
|
|
55
|
+
break
|
|
56
|
+
case 'win32':
|
|
57
|
+
switch (arch) {
|
|
58
|
+
case 'x64':
|
|
59
|
+
localFileExisted = existsSync(
|
|
60
|
+
join(__dirname, 'x-win.win32-x64-msvc.node')
|
|
61
|
+
)
|
|
62
|
+
try {
|
|
63
|
+
if (localFileExisted) {
|
|
64
|
+
nativeBinding = require('./x-win.win32-x64-msvc.node')
|
|
65
|
+
} else {
|
|
66
|
+
nativeBinding = require('@miniben90/x-win-win32-x64-msvc')
|
|
67
|
+
}
|
|
68
|
+
} catch (e) {
|
|
69
|
+
loadError = e
|
|
70
|
+
}
|
|
71
|
+
break
|
|
72
|
+
case 'ia32':
|
|
73
|
+
localFileExisted = existsSync(
|
|
74
|
+
join(__dirname, 'x-win.win32-ia32-msvc.node')
|
|
75
|
+
)
|
|
76
|
+
try {
|
|
77
|
+
if (localFileExisted) {
|
|
78
|
+
nativeBinding = require('./x-win.win32-ia32-msvc.node')
|
|
79
|
+
} else {
|
|
80
|
+
nativeBinding = require('@miniben90/x-win-win32-ia32-msvc')
|
|
81
|
+
}
|
|
82
|
+
} catch (e) {
|
|
83
|
+
loadError = e
|
|
84
|
+
}
|
|
85
|
+
break
|
|
86
|
+
case 'arm64':
|
|
87
|
+
localFileExisted = existsSync(
|
|
88
|
+
join(__dirname, 'x-win.win32-arm64-msvc.node')
|
|
89
|
+
)
|
|
90
|
+
try {
|
|
91
|
+
if (localFileExisted) {
|
|
92
|
+
nativeBinding = require('./x-win.win32-arm64-msvc.node')
|
|
93
|
+
} else {
|
|
94
|
+
nativeBinding = require('@miniben90/x-win-win32-arm64-msvc')
|
|
95
|
+
}
|
|
96
|
+
} catch (e) {
|
|
97
|
+
loadError = e
|
|
98
|
+
}
|
|
99
|
+
break
|
|
100
|
+
default:
|
|
101
|
+
throw new Error(`Unsupported architecture on Windows: ${arch}`)
|
|
102
|
+
}
|
|
103
|
+
break
|
|
104
|
+
case 'darwin':
|
|
105
|
+
localFileExisted = existsSync(join(__dirname, 'x-win.darwin-universal.node'))
|
|
106
|
+
try {
|
|
107
|
+
if (localFileExisted) {
|
|
108
|
+
nativeBinding = require('./x-win.darwin-universal.node')
|
|
109
|
+
} else {
|
|
110
|
+
nativeBinding = require('@miniben90/x-win-darwin-universal')
|
|
111
|
+
}
|
|
112
|
+
break
|
|
113
|
+
} catch {}
|
|
114
|
+
switch (arch) {
|
|
115
|
+
case 'x64':
|
|
116
|
+
localFileExisted = existsSync(join(__dirname, 'x-win.darwin-x64.node'))
|
|
117
|
+
try {
|
|
118
|
+
if (localFileExisted) {
|
|
119
|
+
nativeBinding = require('./x-win.darwin-x64.node')
|
|
120
|
+
} else {
|
|
121
|
+
nativeBinding = require('@miniben90/x-win-darwin-x64')
|
|
122
|
+
}
|
|
123
|
+
} catch (e) {
|
|
124
|
+
loadError = e
|
|
125
|
+
}
|
|
126
|
+
break
|
|
127
|
+
case 'arm64':
|
|
128
|
+
localFileExisted = existsSync(
|
|
129
|
+
join(__dirname, 'x-win.darwin-arm64.node')
|
|
130
|
+
)
|
|
131
|
+
try {
|
|
132
|
+
if (localFileExisted) {
|
|
133
|
+
nativeBinding = require('./x-win.darwin-arm64.node')
|
|
134
|
+
} else {
|
|
135
|
+
nativeBinding = require('@miniben90/x-win-darwin-arm64')
|
|
136
|
+
}
|
|
137
|
+
} catch (e) {
|
|
138
|
+
loadError = e
|
|
139
|
+
}
|
|
140
|
+
break
|
|
141
|
+
default:
|
|
142
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
|
143
|
+
}
|
|
144
|
+
break
|
|
145
|
+
case 'freebsd':
|
|
146
|
+
if (arch !== 'x64') {
|
|
147
|
+
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
|
148
|
+
}
|
|
149
|
+
localFileExisted = existsSync(join(__dirname, 'x-win.freebsd-x64.node'))
|
|
150
|
+
try {
|
|
151
|
+
if (localFileExisted) {
|
|
152
|
+
nativeBinding = require('./x-win.freebsd-x64.node')
|
|
153
|
+
} else {
|
|
154
|
+
nativeBinding = require('@miniben90/x-win-freebsd-x64')
|
|
155
|
+
}
|
|
156
|
+
} catch (e) {
|
|
157
|
+
loadError = e
|
|
158
|
+
}
|
|
159
|
+
break
|
|
160
|
+
case 'linux':
|
|
161
|
+
switch (arch) {
|
|
162
|
+
case 'x64':
|
|
163
|
+
if (isMusl()) {
|
|
164
|
+
localFileExisted = existsSync(
|
|
165
|
+
join(__dirname, 'x-win.linux-x64-musl.node')
|
|
166
|
+
)
|
|
167
|
+
try {
|
|
168
|
+
if (localFileExisted) {
|
|
169
|
+
nativeBinding = require('./x-win.linux-x64-musl.node')
|
|
170
|
+
} else {
|
|
171
|
+
nativeBinding = require('@miniben90/x-win-linux-x64-musl')
|
|
172
|
+
}
|
|
173
|
+
} catch (e) {
|
|
174
|
+
loadError = e
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
localFileExisted = existsSync(
|
|
178
|
+
join(__dirname, 'x-win.linux-x64-gnu.node')
|
|
179
|
+
)
|
|
180
|
+
try {
|
|
181
|
+
if (localFileExisted) {
|
|
182
|
+
nativeBinding = require('./x-win.linux-x64-gnu.node')
|
|
183
|
+
} else {
|
|
184
|
+
nativeBinding = require('@miniben90/x-win-linux-x64-gnu')
|
|
185
|
+
}
|
|
186
|
+
} catch (e) {
|
|
187
|
+
loadError = e
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
break
|
|
191
|
+
case 'arm64':
|
|
192
|
+
if (isMusl()) {
|
|
193
|
+
localFileExisted = existsSync(
|
|
194
|
+
join(__dirname, 'x-win.linux-arm64-musl.node')
|
|
195
|
+
)
|
|
196
|
+
try {
|
|
197
|
+
if (localFileExisted) {
|
|
198
|
+
nativeBinding = require('./x-win.linux-arm64-musl.node')
|
|
199
|
+
} else {
|
|
200
|
+
nativeBinding = require('@miniben90/x-win-linux-arm64-musl')
|
|
201
|
+
}
|
|
202
|
+
} catch (e) {
|
|
203
|
+
loadError = e
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
localFileExisted = existsSync(
|
|
207
|
+
join(__dirname, 'x-win.linux-arm64-gnu.node')
|
|
208
|
+
)
|
|
209
|
+
try {
|
|
210
|
+
if (localFileExisted) {
|
|
211
|
+
nativeBinding = require('./x-win.linux-arm64-gnu.node')
|
|
212
|
+
} else {
|
|
213
|
+
nativeBinding = require('@miniben90/x-win-linux-arm64-gnu')
|
|
214
|
+
}
|
|
215
|
+
} catch (e) {
|
|
216
|
+
loadError = e
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
break
|
|
220
|
+
case 'arm':
|
|
221
|
+
localFileExisted = existsSync(
|
|
222
|
+
join(__dirname, 'x-win.linux-arm-gnueabihf.node')
|
|
223
|
+
)
|
|
224
|
+
try {
|
|
225
|
+
if (localFileExisted) {
|
|
226
|
+
nativeBinding = require('./x-win.linux-arm-gnueabihf.node')
|
|
227
|
+
} else {
|
|
228
|
+
nativeBinding = require('@miniben90/x-win-linux-arm-gnueabihf')
|
|
229
|
+
}
|
|
230
|
+
} catch (e) {
|
|
231
|
+
loadError = e
|
|
232
|
+
}
|
|
233
|
+
break
|
|
234
|
+
default:
|
|
235
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
|
236
|
+
}
|
|
237
|
+
break
|
|
238
|
+
default:
|
|
239
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!nativeBinding) {
|
|
243
|
+
if (loadError) {
|
|
244
|
+
throw loadError
|
|
245
|
+
}
|
|
246
|
+
throw new Error(`Failed to load native binding`)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const { activeWindow, openWindows } = nativeBinding
|
|
250
|
+
|
|
251
|
+
module.exports.activeWindow = activeWindow
|
|
252
|
+
module.exports.openWindows = openWindows
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@miniben90/x-win",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"types": "index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.d.ts",
|
|
8
|
+
"index.js",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
12
|
+
"napi": {
|
|
13
|
+
"name": "x-win",
|
|
14
|
+
"triples": {
|
|
15
|
+
"additional": [
|
|
16
|
+
"aarch64-pc-windows-msvc",
|
|
17
|
+
"i686-pc-windows-msvc",
|
|
18
|
+
"aarch64-apple-darwin",
|
|
19
|
+
"universal-apple-darwin"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "BENKHADRA Hocine",
|
|
25
|
+
"email": "contact@benkhadra.com",
|
|
26
|
+
"url": "https://benkhadra.com/"
|
|
27
|
+
},
|
|
28
|
+
"repository": "https://github.com/miniben-90/x-win.git",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@napi-rs/cli": "^2.14.0",
|
|
32
|
+
"ava": "^4.3.3"
|
|
33
|
+
},
|
|
34
|
+
"ava": {
|
|
35
|
+
"timeout": "3m"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">= 10"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"artifacts": "napi artifacts",
|
|
42
|
+
"build": "napi build --platform --release",
|
|
43
|
+
"build:debug": "napi build --platform",
|
|
44
|
+
"prepublishOnly": "napi prepublish -t npm",
|
|
45
|
+
"test": "ava",
|
|
46
|
+
"universal": "napi universal",
|
|
47
|
+
"version": "napi version"
|
|
48
|
+
},
|
|
49
|
+
"packageManager": "yarn@3.3.1",
|
|
50
|
+
"description": "Get position, size, title and a few other properties of the active or open window(s) on Windows, MacOS and Linux.",
|
|
51
|
+
"optionalDependencies": {
|
|
52
|
+
"@miniben90/x-win-win32-x64-msvc": "0.2.0",
|
|
53
|
+
"@miniben90/x-win-darwin-x64": "0.2.0",
|
|
54
|
+
"@miniben90/x-win-linux-x64-gnu": "0.2.0",
|
|
55
|
+
"@miniben90/x-win-win32-arm64-msvc": "0.2.0",
|
|
56
|
+
"@miniben90/x-win-win32-ia32-msvc": "0.2.0",
|
|
57
|
+
"@miniben90/x-win-darwin-arm64": "0.2.0",
|
|
58
|
+
"@miniben90/x-win-darwin-universal": "0.2.0"
|
|
59
|
+
}
|
|
60
|
+
}
|