-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathenhanced-window-selector.js
More file actions
202 lines (164 loc) Β· 7.84 KB
/
enhanced-window-selector.js
File metadata and controls
202 lines (164 loc) Β· 7.84 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env node
const WindowSelector = require('./window-selector');
async function enhancedWindowSelector() {
console.log('π― Enhanced Window Selector');
console.log('===========================\n');
const selector = new WindowSelector();
try {
// Δ°zinleri kontrol et
const permissions = await selector.checkPermissions();
console.log('π Permissions:');
console.log(` Screen Recording: ${permissions.screenRecording ? 'β
' : 'β'}`);
console.log(` Accessibility: ${permissions.accessibility ? 'β
' : 'β'}`);
console.log(` Microphone: ${permissions.microphone ? 'β
' : 'β'}\n`);
let currentWindow = null;
let windowHistory = [];
// Event listeners with detailed output
selector.on('windowEntered', (window) => {
currentWindow = window;
windowHistory.push({
action: 'entered',
timestamp: new Date().toLocaleTimeString(),
window: window
});
// Clear console (optional - comment out if you want to keep history)
// console.clear();
console.log('\n' + '='.repeat(80));
console.log('π WINDOW ENTERED');
console.log('='.repeat(80));
displayWindowInfo(window);
console.log('\nπ‘ Controls:');
console.log(' β’ Press ENTER to select this window');
console.log(' β’ Move cursor to another window to switch');
console.log(' β’ Press Ctrl+C to exit');
});
selector.on('windowLeft', (window) => {
windowHistory.push({
action: 'left',
timestamp: new Date().toLocaleTimeString(),
window: window
});
console.log('\nπͺ LEFT WINDOW: ' + getWindowLabel(window));
currentWindow = null;
});
selector.on('windowSelected', (selectedWindow) => {
console.log('\n' + 'π'.repeat(20));
console.log('π― WINDOW SELECTED!');
console.log('π'.repeat(20));
displayWindowInfo(selectedWindow, true);
// Show usage statistics
console.log('\nπ Session Statistics:');
console.log(` Total windows explored: ${new Set(windowHistory.map(h => h.window.id)).size}`);
console.log(` Total interactions: ${windowHistory.length}`);
process.exit(0);
});
// Manual selection with ENTER key
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('line', () => {
if (currentWindow) {
selector.emit('windowSelected', currentWindow);
} else {
console.log('\nβ οΈ No window under cursor. Move cursor over a window first.');
}
});
// Start selection
console.log('π Starting enhanced window selection...\n');
console.log('π Instructions:');
console.log(' 1. Move your cursor over different windows');
console.log(' 2. Watch the detailed window information appear');
console.log(' 3. Press ENTER when you want to select the current window');
console.log(' 4. The overlay should highlight windows (may not be visible due to macOS security)\n');
await selector.startSelection();
// Detailed status monitoring
let statusCount = 0;
const statusInterval = setInterval(() => {
const status = selector.getStatus();
statusCount++;
// Show periodic status
if (statusCount % 40 === 0) { // Every 20 seconds
console.log(`\nβ±οΈ Status Update (${statusCount/2}s):`);
console.log(` Windows available: ${status.nativeStatus?.windowCount || 0}`);
console.log(` Selection active: ${status.isSelecting ? 'β
' : 'β'}`);
console.log(` Overlay present: ${status.nativeStatus?.hasOverlay ? 'β
' : 'β'}`);
if (currentWindow) {
console.log(` Current focus: ${getWindowLabel(currentWindow)}`);
}
console.log(' (Move cursor over windows to see details)\n');
}
}, 500);
// Graceful shutdown
process.on('SIGINT', async () => {
clearInterval(statusInterval);
rl.close();
console.log('\n\nπ Shutting down...');
if (windowHistory.length > 0) {
console.log('\nπ Session Summary:');
const uniqueApps = [...new Set(windowHistory.map(h => h.window.appName))];
console.log(` Apps explored: ${uniqueApps.join(', ')}`);
console.log(` Total windows: ${new Set(windowHistory.map(h => h.window.id)).size}`);
}
await selector.cleanup();
console.log('β
Cleanup completed');
process.exit(0);
});
} catch (error) {
console.error('\nβ Error:', error.message);
process.exit(1);
}
}
function displayWindowInfo(window, isSelected = false) {
const prefix = isSelected ? 'π―' : 'π±';
console.log(`\n${prefix} Application: ${window.appName}`);
console.log(`π Title: "${window.title}"`);
console.log(`π Window ID: ${window.id}`);
console.log(`\nπ Position & Size:`);
console.log(` Global Position: (${window.x}, ${window.y})`);
console.log(` Dimensions: ${window.width} Γ ${window.height} pixels`);
console.log(` Total Area: ${(window.width * window.height).toLocaleString()} pixels`);
console.log(` Aspect Ratio: ${(window.width / window.height).toFixed(2)}`);
if (window.screenId !== undefined) {
console.log(`\nπ₯οΈ Screen Information:`);
console.log(` Screen ID: ${window.screenId}`);
if (window.screenX !== undefined && window.screenY !== undefined) {
console.log(` Screen Origin: (${window.screenX}, ${window.screenY})`);
console.log(` Screen Size: ${window.screenWidth} Γ ${window.screenHeight}`);
// Calculate relative position
const relativeX = window.x - window.screenX;
const relativeY = window.y - window.screenY;
console.log(` Relative Position: (${relativeX}, ${relativeY})`);
// Screen coverage
const screenArea = window.screenWidth * window.screenHeight;
const windowArea = window.width * window.height;
const coverage = ((windowArea / screenArea) * 100).toFixed(1);
console.log(` Screen Coverage: ${coverage}%`);
}
}
// Position analysis
console.log(`\nπ Analysis:`);
if (window.width > 1000 && window.height > 600) {
console.log(' πΊ Large window - Good for detailed content');
} else if (window.width > 500 && window.height > 300) {
console.log(' π Medium window - Standard size');
} else {
console.log(' π Small window - Compact application');
}
const aspectRatio = window.width / window.height;
if (Math.abs(aspectRatio - 16/9) < 0.1) {
console.log(' π¬ 16:9 aspect ratio - Video optimized');
} else if (aspectRatio > 2) {
console.log(' π± Wide window - Good for dashboards');
} else if (aspectRatio < 1) {
console.log(' π Tall window - Document/chat style');
}
console.log(`\nβ° Detected at: ${new Date().toLocaleTimeString()}`);
}
function getWindowLabel(window) {
return `${window.appName} - "${window.title}"`;
}
if (require.main === module) {
enhancedWindowSelector();
}