node-mac-recorder
Version:
Native macOS screen recording package for Node.js applications
71 lines (56 loc) ⢠2.44 kB
JavaScript
const WindowSelector = require('./window-selector');
async function autoBringToFrontDemo() {
console.log('š¤ Auto Bring-To-Front Demo');
console.log('============================\n');
const selector = new WindowSelector();
try {
console.log('š Enabling auto bring-to-front feature...');
selector.setBringToFrontEnabled(true);
console.log('ā
Auto mode enabled!');
console.log('š±ļø Now move your cursor over different windows');
console.log('š Each window should automatically come to front\n');
let windowCount = 0;
let lastWindowId = null;
selector.on('windowEntered', (window) => {
if (window.id !== lastWindowId) {
windowCount++;
console.log(`[${windowCount}] šÆ AUTO-FRONT: ${window.appName} - "${window.title}"`);
console.log(` š Position: (${window.x}, ${window.y})`);
console.log(` š Size: ${window.width} Ć ${window.height}`);
console.log(` š Window should come to front automatically!\n`);
lastWindowId = window.id;
}
});
selector.on('windowLeft', (window) => {
console.log(`šŖ Left: ${window.appName} - "${window.title}"\n`);
});
await selector.startSelection();
console.log('Demo started! Move cursor over different app windows to see them come to front.');
console.log('Press Ctrl+C to stop\n');
// Auto-stop after 60 seconds
setTimeout(async () => {
console.log('\nā° Demo completed!');
console.log(`š Total windows auto-focused: ${windowCount}`);
selector.setBringToFrontEnabled(false);
await selector.cleanup();
process.exit(0);
}, 60000);
// Manual stop
process.on('SIGINT', async () => {
console.log('\n\nš Stopping demo...');
console.log(`š Total windows auto-focused: ${windowCount}`);
selector.setBringToFrontEnabled(false);
await selector.cleanup();
process.exit(0);
});
// Prevent exit
setInterval(() => {}, 1000);
} catch (error) {
console.error('ā Error:', error.message);
await selector.cleanup();
}
}
if (require.main === module) {
autoBringToFrontDemo();
}