Tabs is better for this yay Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
const { execSync } = require('child_process');
|
|
|
|
// Real monitor resolution instead of a hardcoded viewport — this suite runs
|
|
// on whatever box the self-hosted runner/dev machine happens to be (varies:
|
|
// 1366x768, 1920x1080, ...). Memoized per process.
|
|
let _cachedViewport = null;
|
|
|
|
function detectViewport() {
|
|
if (_cachedViewport) return _cachedViewport;
|
|
const FALLBACK = { width: 1366, height: 768 };
|
|
let detected = null;
|
|
try {
|
|
if (process.platform === 'linux') {
|
|
const out = execSync('xrandr --current 2>/dev/null', { encoding: 'utf8' });
|
|
const m = out.match(/(\d+)x(\d+)\s+[\d.]+\*/);
|
|
if (m) detected = { width: Number(m[1]), height: Number(m[2]) };
|
|
} else if (process.platform === 'win32') {
|
|
const out = execSync(
|
|
'powershell -NoProfile -Command "Add-Type -AssemblyName System.Windows.Forms; ' +
|
|
'$b = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds; Write-Output \\"$($b.Width)x$($b.Height)\\""',
|
|
{ encoding: 'utf8', windowsHide: true },
|
|
).trim();
|
|
const m = out.match(/(\d+)x(\d+)/);
|
|
if (m) detected = { width: Number(m[1]), height: Number(m[2]) };
|
|
} else if (process.platform === 'darwin') {
|
|
const out = execSync('system_profiler SPDisplaysDataType 2>/dev/null', { encoding: 'utf8' });
|
|
const m = out.match(/Resolution:\s*(\d+)\s*x\s*(\d+)/);
|
|
if (m) detected = { width: Number(m[1]), height: Number(m[2]) };
|
|
}
|
|
} catch {
|
|
// No xrandr on a headless CI box, PowerShell blocked, etc. — fall back.
|
|
}
|
|
_cachedViewport = detected ?? FALLBACK;
|
|
return _cachedViewport;
|
|
}
|
|
|
|
module.exports = { detectViewport };
|