75 lines
2.1 KiB
JavaScript
75 lines
2.1 KiB
JavaScript
const { app, BrowserWindow, screen, ipcMain } = require('electron');
|
|
const path = require('path');
|
|
|
|
let mainWindow;
|
|
let screenWindow;
|
|
|
|
function createWindows() {
|
|
const displays = screen.getAllDisplays();
|
|
console.log('🖥️ All Displays Detected:', displays);
|
|
|
|
// Show bounds to confirm
|
|
displays.forEach((display, index) => {
|
|
console.log(`Display ${index}:`, display.bounds);
|
|
});
|
|
|
|
// Use index directly
|
|
const primaryDisplay = displays[0]; // 1600x900
|
|
const secondaryDisplay = displays[1] || displays[0]; // 1024x768
|
|
|
|
// 🪟 Main Window on Primary Display
|
|
mainWindow = new BrowserWindow({
|
|
x: primaryDisplay.bounds.x,
|
|
y: primaryDisplay.bounds.y,
|
|
width: primaryDisplay.bounds.width,
|
|
height: primaryDisplay.bounds.height,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, 'preload.js'),
|
|
contextIsolation: true
|
|
}
|
|
});
|
|
|
|
mainWindow.loadURL('http://192.168.1.110:4200/login');
|
|
|
|
// 🪟 Second Window on Secondary Display
|
|
screenWindow = new BrowserWindow({
|
|
x: secondaryDisplay.bounds.x,
|
|
y: secondaryDisplay.bounds.y,
|
|
width: secondaryDisplay.bounds.width,
|
|
height: secondaryDisplay.bounds.height,
|
|
frame: false,
|
|
show: false,
|
|
backgroundColor: '#000', // helpful for visual debugging
|
|
webPreferences: {
|
|
preload: path.join(__dirname, 'preload.js'),
|
|
contextIsolation: true
|
|
}
|
|
});
|
|
|
|
screenWindow.loadURL('http://192.168.1.110:4200/screen');
|
|
|
|
screenWindow.webContents.on('did-fail-load', (event, errorCode, errorDesc) => {
|
|
console.error('❌ Failed to load screen window:', errorCode, errorDesc);
|
|
});
|
|
|
|
screenWindow.once('ready-to-show', () => {
|
|
console.log('✅ screenWindow ready');
|
|
});
|
|
|
|
ipcMain.on('open-second-screen', () => {
|
|
console.log('💡 Showing second screen');
|
|
if (screenWindow) screenWindow.show();
|
|
});
|
|
|
|
ipcMain.on('close-second-screen', () => {
|
|
console.log('🔒 Hiding second screen');
|
|
if (screenWindow) screenWindow.hide();
|
|
});
|
|
}
|
|
|
|
app.whenReady().then(createWindows);
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') app.quit();
|
|
});
|