fix(display): ensure display is connected and retry if not

This commit is contained in:
2026-07-06 16:43:49 +02:00
parent 7d85fc6c0b
commit 11a090441e
+29 -7
View File
@@ -28,7 +28,7 @@ function getMonitorGeometry(monitorName) {
const stdout = execSync('xrandr').toString(); const stdout = execSync('xrandr').toString();
const lines = stdout.split('\n'); const lines = stdout.split('\n');
for (const line of lines) { for (const line of lines) {
if (line.includes(monitorName) && line.includes('connected')) { if (line.startsWith(monitorName + ' ') && line.includes(' connected')) {
// Match geometry string like 1920x1080+1920+0 // Match geometry string like 1920x1080+1920+0
const match = line.match(/(\d+)x(\d+)\+(\d+)\+(\d+)/); const match = line.match(/(\d+)x(\d+)\+(\d+)\+(\d+)/);
if (match) { if (match) {
@@ -42,14 +42,33 @@ function getMonitorGeometry(monitorName) {
} }
} }
} catch (e) { } catch (e) {
console.error('Failed to parse xrandr:', e); console.error('Failed to execute xrandr:', e.message);
} }
// Fallback geometry if xrandr fails return null;
return { width: 1920, height: 1080, x: 0, y: 0 };
} }
function buildFlags() { function ensureMonitorConnected() {
const geometry = getMonitorGeometry(MONITOR); return new Promise(resolve => {
const check = () => {
// Run xrandr --auto to ensure any newly connected displays are configured
try {
execSync('xrandr --auto');
} catch(e) {}
const geom = getMonitorGeometry(MONITOR);
if (geom) {
console.log(`Monitor ${MONITOR} is connected and ready.`);
resolve(geom);
} else {
console.log(`Waiting for monitor ${MONITOR} to be connected...`);
setTimeout(check, 5000);
}
};
check();
});
}
function buildFlags(geometry) {
console.log(`Monitor ${MONITOR} resolved to position ${geometry.x},${geometry.y} with size ${geometry.width}x${geometry.height}`); console.log(`Monitor ${MONITOR} resolved to position ${geometry.x},${geometry.y} with size ${geometry.width}x${geometry.height}`);
const flags = [ const flags = [
@@ -79,13 +98,16 @@ function buildFlags() {
} }
async function startChromium() { async function startChromium() {
console.log(`Checking connection status for ${MONITOR}...`);
const geometry = await ensureMonitorConnected();
if (browserProcess) { if (browserProcess) {
console.log('Stopping existing Chromium...'); console.log('Stopping existing Chromium...');
browserProcess.kill('SIGTERM'); browserProcess.kill('SIGTERM');
await new Promise(resolve => setTimeout(resolve, 2000)); await new Promise(resolve => setTimeout(resolve, 2000));
} }
const flags = buildFlags(); const flags = buildFlags(geometry);
console.log('Starting Chromium with flags:', flags.join(' ')); console.log('Starting Chromium with flags:', flags.join(' '));