@magaya/cloud-client-window-helper 0.0.2 → 1.0.316315

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/.whitesource ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "scanSettings": {
3
+ "configMode": "AUTO",
4
+ "configExternalURL": "",
5
+ "projectToken": "",
6
+ "baseBranches": []
7
+ },
8
+ "checkRunSettings": {
9
+ "vulnerableCheckRunConclusionLevel": "failure",
10
+ "displayMode": "diff",
11
+ "useMendCheckNames": true
12
+ },
13
+ "issueSettings": {
14
+ "minSeverityLevel": "LOW",
15
+ "issueType": "DEPENDENCY"
16
+ },
17
+ "remediateSettings": {
18
+ "workflowRules": {
19
+ "enabled": true
20
+ }
21
+ },
22
+ "imageSettings":{
23
+ "imageTracing":{
24
+ "enableImageTracingPR": false,
25
+ "addRepositoryCoordinate": false,
26
+ "addDockerfilePath": false,
27
+ "addMendIdentifier": false
28
+ }
29
+ }
30
+ }
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
- {
2
- "name": "@magaya/cloud-client-window-helper",
3
- "version": "0.0.2",
4
- "description": "Magaya Cloud Client Window Helper",
5
- "main": "index.js",
6
- "gypfile": true,
7
- "scripts": {
8
- "build": "node-gyp rebuild",
9
- "clean": "node-gyp clean",
10
- "test": "echo \"Error: no test specified\" && exit 1"
11
- },
12
- "keywords": [
13
- "magaya",
14
- "cloud",
15
- "helper"
16
- ],
17
- "author": "Magaya Corporation",
18
- "license": "MIT",
19
- "devDependencies": {
20
- "node-gyp": "^6.0.0"
21
- },
22
- "dependencies": {
23
- "node-addon-api": "^1.7.1"
24
- }
25
- }
1
+ {
2
+ "name": "@magaya/cloud-client-window-helper",
3
+ "version": "1.0.316315",
4
+ "description": "Magaya Cloud Client Window Helper",
5
+ "main": "index.js",
6
+ "gypfile": true,
7
+ "scripts": {
8
+ "build": "node-gyp rebuild",
9
+ "clean": "node-gyp clean",
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": [
13
+ "magaya",
14
+ "cloud",
15
+ "helper"
16
+ ],
17
+ "author": "Magaya Corporation",
18
+ "license": "MIT",
19
+ "devDependencies": {
20
+ "node-gyp": "^12.0.0"
21
+ },
22
+ "dependencies": {
23
+ "node-addon-api": "^1.7.1"
24
+ }
25
+ }
package/src/main.cc CHANGED
@@ -40,6 +40,12 @@ napi_value init(napi_env env, napi_value exports) {
40
40
  status = napi_set_named_property(env, exports, "minimizeWindow", fn);
41
41
  if (status != napi_ok) return nullptr;
42
42
 
43
+ status = napi_create_function(env, nullptr, 0, countWindowsByProcess, nullptr, &fn);
44
+ if (status != napi_ok) return nullptr;
45
+
46
+ status = napi_set_named_property(env, exports, "countWindowsByProcess", fn);
47
+ if (status != napi_ok) return nullptr;
48
+
43
49
  return exports;
44
50
  }
45
51
 
package/src/main.h CHANGED
@@ -6,6 +6,11 @@ struct windowInfo {
6
6
  std::string windowText;
7
7
  };
8
8
 
9
+ struct windowFilter {
10
+ int pid;
11
+ std::string exeName;
12
+ };
13
+
9
14
  napi_value getActiveWindow(napi_env env, napi_callback_info args);
10
15
 
11
16
  napi_value getChildWindows(napi_env env, napi_callback_info args);
@@ -16,4 +21,6 @@ napi_value isWindowVisible(napi_env env, napi_callback_info args);
16
21
 
17
22
  napi_value isWindowMinimized(napi_env env, napi_callback_info args);
18
23
 
19
- napi_value minimizeWindow(napi_env env, napi_callback_info args);
24
+ napi_value minimizeWindow(napi_env env, napi_callback_info args);
25
+
26
+ napi_value countWindowsByProcess(napi_env env, napi_callback_info args);
package/src/main_mac.cc CHANGED
@@ -56,5 +56,15 @@ napi_value minimizeWindow(napi_env env, napi_callback_info args) {
56
56
  size_t argsLength = 1;
57
57
  napi_value argInfo[1];
58
58
 
59
+ return nullptr;
60
+ }
61
+
62
+ napi_value countWindowsByProcess(napi_env env, napi_callback_info args) {
63
+ napi_value value;
64
+ napi_status status;
65
+
66
+ size_t argsLength = 1;
67
+ napi_value argInfo[1];
68
+
59
69
  return nullptr;
60
70
  }
package/src/main_win.cc CHANGED
@@ -2,6 +2,7 @@
2
2
  #include <windows.h>
3
3
 
4
4
  std::vector<windowInfo> winvector;
5
+ int countWindows;
5
6
 
6
7
  BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) {
7
8
  TCHAR strName[MAX_PATH];
@@ -26,6 +27,42 @@ BOOL CALLBACK EnumWindowsVisibleProc(HWND hwnd, LPARAM lparam) {
26
27
  return TRUE;
27
28
  }
28
29
 
30
+ BOOL CALLBACK EnumWindowsByProcessProc(HWND hwnd, LPARAM lparam) {
31
+ windowFilter* winfilter = reinterpret_cast<windowFilter*>(lparam);
32
+
33
+ DWORD pid;
34
+ GetWindowThreadProcessId(hwnd, &pid);
35
+
36
+ DWORD dwSize = MAX_PATH;
37
+ CHAR exeName[MAX_PATH];
38
+
39
+ if (!winfilter->exeName.empty()) {
40
+ HANDLE handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, pid);
41
+ if (!handle || !QueryFullProcessImageName(handle, 0, exeName, &dwSize)) {
42
+ exeName[0] = '\0';
43
+ }
44
+ }
45
+
46
+ bool passfilter = true;
47
+
48
+ if (passfilter && winfilter->pid != 0 && pid != winfilter->pid) {
49
+ passfilter = false;
50
+ }
51
+
52
+ if (passfilter && !winfilter->exeName.empty()) {
53
+ PCHAR pch = strstr(exeName, winfilter->exeName.c_str());
54
+ if (!pch) {
55
+ passfilter = false;
56
+ }
57
+ }
58
+
59
+ if (passfilter) {
60
+ countWindows++;
61
+ }
62
+
63
+ return TRUE;
64
+ }
65
+
29
66
  napi_value getActiveWindow(napi_env env, napi_callback_info args) {
30
67
  napi_value obj;
31
68
  napi_value value;
@@ -209,4 +246,59 @@ napi_value minimizeWindow(napi_env env, napi_callback_info args) {
209
246
  ShowWindow(HWND(handle), SW_MINIMIZE);
210
247
 
211
248
  return nullptr;
249
+ }
250
+
251
+ napi_value countWindowsByProcess(napi_env env, napi_callback_info args) {
252
+ napi_value obj;
253
+ napi_value value;
254
+ napi_status status;
255
+
256
+ bool hasproperty;
257
+
258
+ size_t argsLength = 1;
259
+ napi_value argInfo[1];
260
+
261
+ status = napi_get_cb_info(env, args, &argsLength, argInfo, NULL, NULL);
262
+ if (status != napi_ok) return nullptr;
263
+
264
+ status = napi_coerce_to_object(env, argInfo[0], &obj);
265
+ if (status != napi_ok) return nullptr;
266
+
267
+ windowFilter winfilter {0, ""};
268
+
269
+ status = napi_get_named_property(env, obj, "pid", &value);
270
+ if (status != napi_ok) return nullptr;
271
+
272
+ status = napi_has_named_property(env, obj, "pid", &hasproperty);
273
+ if (status != napi_ok) return nullptr;
274
+
275
+ if (hasproperty) {
276
+ status = napi_get_value_int32(env, value, &winfilter.pid);
277
+ if (status != napi_ok) return nullptr;
278
+ }
279
+
280
+ status = napi_has_named_property(env, obj, "exename", &hasproperty);
281
+ if (status != napi_ok) return nullptr;
282
+
283
+ if (hasproperty) {
284
+ status = napi_get_named_property(env, obj, "exename", &value);
285
+ if (status != napi_ok) return nullptr;
286
+
287
+ size_t result;
288
+ CHAR exeName[MAX_PATH];
289
+
290
+ status = napi_get_value_string_utf8(env, value, exeName, MAX_PATH, &result);
291
+ if (status != napi_ok) return nullptr;
292
+
293
+ winfilter.exeName = exeName;
294
+ }
295
+
296
+ countWindows = 0;
297
+
298
+ EnumWindows(EnumWindowsByProcessProc, reinterpret_cast<LPARAM>(&winfilter));
299
+
300
+ status = napi_create_int32(env, countWindows, &value);
301
+ if (status != napi_ok) return nullptr;
302
+
303
+ return value;
212
304
  }