-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-monitor-detection.js
More file actions
182 lines (159 loc) · 5.46 KB
/
Copy pathtest-monitor-detection.js
File metadata and controls
182 lines (159 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Test script for monitor detection and screenshot functionality
// Run this with: node test-monitor-detection.js
const path = require("path");
// Mock Electron APIs for testing
const mockElectron = {
screen: {
getAllDisplays: () => {
console.log("🔍 Testing screen.getAllDisplays()");
return [
{
id: 1,
bounds: { x: 0, y: 0, width: 1920, height: 1080 },
size: { width: 1920, height: 1080 },
workArea: { x: 0, y: 0, width: 1920, height: 1040 },
scaleFactor: 1,
rotation: 0,
colorDepth: 24,
colorSpace: "srgb",
internal: false,
},
{
id: 2,
bounds: { x: 1920, y: 0, width: 2560, height: 1440 },
size: { width: 2560, height: 1440 },
workArea: { x: 1920, y: 0, width: 2560, height: 1400 },
scaleFactor: 1.25,
rotation: 0,
colorDepth: 30,
colorSpace: "display-p3",
internal: false,
},
];
},
getPrimaryDisplay: () => {
console.log("🔍 Testing screen.getPrimaryDisplay()");
return {
id: 1,
bounds: { x: 0, y: 0, width: 1920, height: 1080 },
size: { width: 1920, height: 1080 },
workArea: { x: 0, y: 0, width: 1920, height: 1040 },
scaleFactor: 1,
rotation: 0,
colorDepth: 24,
colorSpace: "srgb",
internal: false,
};
},
},
desktopCapturer: {
getSources: async (options) => {
console.log(
"🔍 Testing desktopCapturer.getSources() with options:",
options,
);
// Mock thumbnail
const mockThumbnail = {
getSize: () => ({
width: options.thumbnailSize.width,
height: options.thumbnailSize.height,
}),
isEmpty: () => false,
toDataURL: () =>
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==",
};
return [
{
id: "screen:1:0",
name: "Screen 1",
display_id: "1",
thumbnail: mockThumbnail,
},
{
id: "screen:2:0",
name: "Screen 2",
display_id: "2",
thumbnail: mockThumbnail,
},
{
id: "screen:0:0",
name: "Entire screen",
display_id: "0",
thumbnail: mockThumbnail,
},
];
},
},
};
// Override require for electron module
const Module = require("module");
const originalRequire = Module.prototype.require;
Module.prototype.require = function (id) {
if (id === "electron") {
return mockElectron;
}
return originalRequire.apply(this, arguments);
};
async function testMonitorDetection() {
console.log("=== TESTING MONITOR DETECTION ===\n");
try {
// Test MonitorDetector
console.log("1. Testing MonitorDetector...");
const MonitorDetector = require("./monitor1-fix.js");
const detector = new MonitorDetector();
const initialized = await detector.initialize();
console.log("✅ MonitorDetector initialized:", initialized);
const recommendation = detector.getRecommendation();
console.log("📊 Recommendation:", {
source: recommendation.recommendedSource?.name,
reasoning: recommendation.reasoning,
alternativeCount: recommendation.alternativeSources.length,
});
const testResults = await detector.testAllSources();
console.log("🧪 Test results:", testResults.length, "sources tested");
console.log("\n");
// Test HDRCompatibilityManager
console.log("2. Testing HDRCompatibilityManager...");
const HDRCompatibilityManager = require("./hdr-patch.js");
const hdrManager = new HDRCompatibilityManager();
const hdrInitialized = hdrManager.initialize();
console.log("✅ HDRCompatibilityManager initialized:", hdrInitialized);
const hdrStatus = hdrManager.getStatus();
console.log("📊 HDR Status:", hdrStatus);
const thumbnailSize = hdrManager.getOptimalThumbnailSize(
mockElectron.screen.getPrimaryDisplay(),
);
console.log("📐 Optimal thumbnail size:", thumbnailSize);
console.log("\n");
// Test ScreenshotManager
console.log("3. Testing ScreenshotManager...");
const ScreenshotManager = require("./screenshot-fix.js");
const screenshotManager = new ScreenshotManager();
const screenshotInitialized = await screenshotManager.initialize();
console.log("✅ ScreenshotManager initialized:", screenshotInitialized);
const diagnostics = screenshotManager.getDiagnostics();
console.log("📊 Screenshot diagnostics:", {
initialized: diagnostics.initialized,
hdrMode: diagnostics.hdrStatus.compatibilityMode,
displayCount: diagnostics.monitorInfo.displayCount,
sourceCount: diagnostics.monitorInfo.sourceCount,
lastSuccessfulSource: diagnostics.lastSuccessfulSource?.name || "none",
});
// Test screenshot capture
console.log("📸 Testing screenshot capture...");
const dataUrl = await screenshotManager.captureScreenshot();
console.log("✅ Screenshot captured, length:", dataUrl.length);
console.log("\n=== ALL TESTS COMPLETED SUCCESSFULLY ===");
} catch (error) {
console.error("❌ Test failed:", error);
console.error("Stack:", error.stack);
}
}
// Run tests
testMonitorDetection()
.then(() => {
console.log("\n🎉 Monitor detection testing completed!");
})
.catch((error) => {
console.error("\n💥 Testing failed:", error);
});