29 lines
1.8 KiB
JavaScript
29 lines
1.8 KiB
JavaScript
import { access } from 'node:fs/promises';
|
|
import { constants } from 'node:fs';
|
|
import { spawn } from 'node:child_process';
|
|
|
|
const run = (file, args) => new Promise((resolve, reject) => {
|
|
const child = spawn(file, args, { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
let stdout = ''; let stderr = '';
|
|
child.stdout?.on('data', (chunk) => { stdout += chunk; });
|
|
child.stderr?.on('data', (chunk) => { stderr += chunk; });
|
|
child.once('error', reject);
|
|
child.once('close', (code) => code === 0 ? resolve({ stdout, stderr }) : reject(new Error(stderr || `${file} exited ${code}`)));
|
|
});
|
|
const checks = [
|
|
['session', false, async () => process.env.XDG_SESSION_TYPE || 'unknown'],
|
|
['portal', false, async () => { await access('/usr/share/dbus-1/services/org.freedesktop.portal.Desktop.service', constants.F_OK); return 'installed'; }],
|
|
['pipewire', false, async () => { await run('which', ['pw-cat']); return 'installed'; }],
|
|
['at-spi', false, async () => { await run('python3', ['-c', 'import gi; gi.require_version("Atspi", "2.0"); from gi.repository import Atspi']); return 'PyGObject Atspi available'; }],
|
|
['libei', false, async () => { const result = await run('ldconfig', ['-p']); if (!/libei|libeis/.test(result.stdout)) throw new Error('libei/libeis not found'); return 'libei/libeis installed'; }],
|
|
['ydotool', true, async () => { await run('which', ['ydotool']); return 'optional fallback present'; }],
|
|
];
|
|
|
|
let failed = 0;
|
|
for (const [name, optional, check] of checks) {
|
|
try { console.log(`ok ${name}: ${await check()}${optional ? ' (optional)' : ''}`); }
|
|
catch { if (!optional) failed += 1; console.log(`---- ${name}: unavailable${optional ? ' (optional)' : ''}`); }
|
|
}
|
|
console.log(failed ? `cu-doctor: ${failed} required checks unavailable` : 'cu-doctor: required checks passed');
|
|
process.exitCode = failed ? 1 : 0;
|