@aspiresys/visor 1.3.3 → 1.3.5

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/dist/display.js CHANGED
@@ -3,14 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getWindowsScaleFactor = getWindowsScaleFactor;
4
4
  const child_process_1 = require("child_process");
5
5
  function getWindowsScaleFactor() {
6
+ const widthCmd = `powershell -NoProfile -Command "(Get-CimInstance -ClassName Win32_VideoController).CurrentHorizontalResolution"`;
7
+ const logicalCmd = `powershell -NoProfile -Command "Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width"`;
6
8
  try {
7
- const output = (0, child_process_1.execSync)('reg query "HKCU\\Control Panel\\Desktop\\WindowMetrics" /v AppliedDPI', { encoding: "utf8" });
8
- const match = output.match(/AppliedDPI\s+REG_DWORD\s+0x([0-9a-f]+)/i);
9
- if (match) {
10
- const dpi = parseInt(match[1], 16);
11
- return dpi / 96;
9
+ const hardwareWidth = parseInt((0, child_process_1.execSync)(widthCmd).toString().trim(), 10);
10
+ const logicalWidth = parseInt((0, child_process_1.execSync)(logicalCmd).toString().trim(), 10);
11
+ if (!hardwareWidth || !logicalWidth)
12
+ return 1;
13
+ const calculatedScale = Math.round((hardwareWidth / logicalWidth) * 100);
14
+ return calculatedScale / 100;
15
+ }
16
+ catch (error) {
17
+ try {
18
+ const regCmd = `powershell -NoProfile -Command "(Get-ItemProperty 'HKCU:\\Control Panel\\Desktop\\PerMonitorSettings\\*').DpiScale | Select-Object -First 1"`;
19
+ const regVal = parseInt((0, child_process_1.execSync)(regCmd).toString().trim(), 10);
20
+ if (!isNaN(regVal)) {
21
+ const indexMap = { 0: 100, 1: 125, 2: 150, 3: 175, 4: 200 };
22
+ return (indexMap[regVal] || 100) / 100;
23
+ }
24
+ }
25
+ catch (e) {
26
+ return 1;
12
27
  }
28
+ return 1;
13
29
  }
14
- catch (e) { }
15
- return 1;
16
30
  }
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ const path_1 = require("./path");
14
14
  const display_1 = require("./display");
15
15
  const logger_1 = require("./logger");
16
16
  const console_1 = require("console");
17
+ const templateMetadata_1 = require("./templateMetadata");
17
18
  class Visor {
18
19
  constructor() {
19
20
  this.mouse = nut_js_1.mouse;
@@ -316,8 +317,9 @@ class Visor {
316
317
  const screen = await (0, screen_1.captureScreen)();
317
318
  const template = await (0, matcher_1.loadTemplate)((0, path_1.resolveImagePath)(image));
318
319
  const scaleFactor = config_1.visorConfig.scaleFactor;
320
+ const metadata = (0, templateMetadata_1.loadTemplateMetadata)((0, path_1.resolveImagePath)(image));
319
321
  try {
320
- const result = (0, matcher_1.matchTemplate)(screen, template, confidence);
322
+ const result = (0, matcher_1.matchTemplate)(screen, template, confidence, metadata);
321
323
  if (result) {
322
324
  (0, logger_1.log)(`[FIND] Actual coords: (${Math.floor(result.x * scaleFactor)}, ${Math.floor(result.y * scaleFactor)})`);
323
325
  }
package/dist/matcher.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Region } from "./types";
2
2
  export declare function loadTemplate(path: string): Promise<any>;
3
3
  export declare function loadScreen(path: string): Promise<any>;
4
- export declare function matchTemplate(screen: any, template: any, confidence?: number): Region | null;
4
+ export declare function matchTemplate(screen: any, template: any, confidence?: number, metadata?: any): Region | null;
5
5
  export declare function findAllMatches(screen: any, template: any, confidence?: number): Region[];
6
6
  export declare function findAllInspectorMatches(screen: any, template: any, confidence?: number): Region[];
7
7
  export declare function matchInspectorTemplate(screen: any, template: any, confidence?: number, multiScale?: boolean): Region | null;
package/dist/matcher.js CHANGED
@@ -16,6 +16,7 @@ const cv = require("@techstark/opencv-js");
16
16
  const templateCache = new Map();
17
17
  const types_1 = require("./types");
18
18
  const logger_1 = require("./logger");
19
+ const config_1 = require("./config");
19
20
  async function loadTemplate(path) {
20
21
  if (templateCache.has(path)) {
21
22
  (0, logger_1.log)(`[CACHE] Template hit: ${path}`);
@@ -49,9 +50,23 @@ function resizeTemplate(template, scale) {
49
50
  cv.resize(template, resized, new cv.Size(newWidth, newHeight), 0, 0, scale < 1 ? cv.INTER_AREA : cv.INTER_CUBIC);
50
51
  return resized;
51
52
  }
52
- function matchTemplate(screen, template, confidence = 0.8) {
53
+ function matchTemplate(screen, template, confidence = 0.8, metadata) {
54
+ (0, logger_1.log)("Screen:", screen.cols, "x", screen.rows);
55
+ (0, logger_1.log)("Template:", template.cols, "x", template.rows);
56
+ const result = new cv.Mat();
53
57
  const start = Date.now();
54
- const scales = [1.0, 0.9, 1.1, 0.8, 1.2, 0.7, 1.3, 0.6, 1.4, 0.5, 1.5];
58
+ const scales = (() => {
59
+ if (metadata) {
60
+ const widthRatio = screen.cols / metadata.capturedResolution.width;
61
+ const heightRatio = screen.rows / metadata.capturedResolution.height;
62
+ const resolutionRatio = (widthRatio + heightRatio) / 2;
63
+ const dpiRatio = config_1.visorConfig.scaleFactor / metadata.capturedScaleFactor;
64
+ const predictedScale = resolutionRatio * dpiRatio;
65
+ (0, logger_1.log)(`[MATCH] Predicted scale: ${predictedScale.toFixed(3)}`);
66
+ return [predictedScale, predictedScale * 0.95, predictedScale * 1.05, predictedScale * 0.9, predictedScale * 1.1];
67
+ }
68
+ return [1.0, 1.25, 1.5, 1.75, 2.0, 0.75, 0.5];
69
+ })();
55
70
  let bestMatch = null;
56
71
  for (const scale of scales) {
57
72
  const resizedTemplate = resizeTemplate(template, scale);
@@ -141,7 +156,7 @@ function findAllInspectorMatches(screen, template, confidence = 0.8) {
141
156
  function matchInspectorTemplate(screen, template, confidence = 0.8, multiScale = false) {
142
157
  if (multiScale) {
143
158
  const start = Date.now();
144
- const scales = [1.0, 0.9, 1.1, 0.8, 1.2, 0.7, 1.3, 0.6, 1.4, 0.5, 1.5];
159
+ const scales = [1.0, 1.25, 1.5, 1.75, 2.0, 0.75, 0.5];
145
160
  let bestMatch = null;
146
161
  for (const scale of scales) {
147
162
  const resizedTemplate = resizeTemplate(template, scale);
@@ -0,0 +1 @@
1
+ export declare function loadTemplateMetadata(path: string): any;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadTemplateMetadata = loadTemplateMetadata;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ function loadTemplateMetadata(path) {
9
+ const metadataPath = path.replace(/\.png$/i, ".properties.json");
10
+ if (!fs_1.default.existsSync(metadataPath)) {
11
+ return null;
12
+ }
13
+ return JSON.parse(fs_1.default.readFileSync(metadataPath, "utf-8"));
14
+ }
package/inspector/main.js CHANGED
@@ -4,7 +4,8 @@ const {
4
4
  app,
5
5
  BrowserWindow,
6
6
  ipcMain,
7
- dialog
7
+ dialog,
8
+ screen
8
9
  } = require("electron");
9
10
 
10
11
  const fs = require("fs");
@@ -103,6 +104,23 @@ ipcMain.handle("save-template",
103
104
  selection.height
104
105
  )
105
106
  }).toFile(inspectorCopy);
107
+ const display = screen.getPrimaryDisplay();
108
+ const metadata = {
109
+ capturedResolution: {
110
+ width: Math.round(display.size.width * display.scaleFactor),
111
+ height: Math.round(display.size.height * display.scaleFactor)
112
+ },
113
+ templateSize: {
114
+ width: Math.round(selection.width),
115
+ height: Math.round(selection.height)
116
+ },
117
+ capturedScaleFactor: display.scaleFactor,
118
+ capturedAt: new Date().toISOString()
119
+ };
120
+ const outputMetadataPath = output.replace(/\.png$/i, ".properties.json");
121
+ fs.writeFileSync(outputMetadataPath, JSON.stringify(metadata, null, 2));
122
+ const metadataPath = inspectorCopy.replace(/\.png$/i, ".properties.json");
123
+ fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
106
124
  return output;
107
125
  }
108
126
  );
@@ -90,13 +90,14 @@ canvas.addEventListener("mousemove",
90
90
  canvas.addEventListener("mouseup",
91
91
  () => {
92
92
  selecting = false;
93
+ document.getElementById("mousex").innerHTML = Math.round(startX);
94
+ document.getElementById("mousey").innerHTML = Math.round(startY);
93
95
  document.getElementById("mousew").innerHTML = Math.round(Math.abs(endX - startX));
94
96
  document.getElementById("mouseh").innerHTML = Math.round(Math.abs(endY - startY));
95
97
  console.log(startX, startY, endX, endY);
96
98
  }
97
99
  );
98
100
 
99
-
100
101
  saveBtn.addEventListener("click",
101
102
  async () => {
102
103
  if (startX === undefined || startY === undefined || endX === undefined || endY === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aspiresys/visor",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -169,6 +169,8 @@ By default Visor evaluates templates across multiple scale levels and automatica
169
169
 
170
170
  Supported environments include:
171
171
 
172
+ * 050% scaling
173
+ * 075% scaling
172
174
  * 100% scaling
173
175
  * 125% scaling
174
176
  * 150% scaling