2024-09-01 14:58:03 +02:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
import assert from 'node:assert';
|
|
|
|
import { execa } from 'execa';
|
|
|
|
import got from 'got';
|
|
|
|
import os from 'node:os';
|
|
|
|
import timers from 'node:timers/promises';
|
|
|
|
|
|
|
|
|
|
|
|
const losslessCutExePath = process.argv[2];
|
|
|
|
assert(losslessCutExePath);
|
2024-09-02 23:55:31 +02:00
|
|
|
const screenshotDevice = process.argv[3];
|
|
|
|
const screenshotOutPath = process.argv[4];
|
2024-09-01 14:58:03 +02:00
|
|
|
assert(screenshotOutPath);
|
|
|
|
|
|
|
|
|
|
|
|
const port = 8081;
|
|
|
|
|
|
|
|
const ps = execa(losslessCutExePath, ['--http-api', String(port)]);
|
|
|
|
|
|
|
|
console.log('Started', losslessCutExePath);
|
|
|
|
|
|
|
|
// eslint-disable-next-line unicorn/prefer-top-level-await
|
|
|
|
ps.catch((err) => console.error(err));
|
|
|
|
|
|
|
|
const client = got.extend({ prefixUrl: `http://127.0.0.1:${port}`, timeout: { request: 5000 } });
|
|
|
|
|
|
|
|
async function captureScreenshot(outPath: string) {
|
|
|
|
// https://trac.ffmpeg.org/wiki/Capture/Desktop#Windows
|
|
|
|
|
2024-09-02 23:55:31 +02:00
|
|
|
const platform = os.platform();
|
|
|
|
|
|
|
|
if (platform === 'darwin') {
|
|
|
|
const { stderr } = await execa('ffmpeg', ['-f', 'avfoundation', '-list_devices', 'true', '-i', '', '-hide_banner'], { reject: false });
|
|
|
|
console.log(stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(screenshotDevice);
|
|
|
|
|
2024-09-01 14:58:03 +02:00
|
|
|
await execa('ffmpeg', [
|
2024-09-02 23:55:31 +02:00
|
|
|
...(platform === 'darwin' ? ['-r', '30', '-pix_fmt', 'uyvy422', '-f', 'avfoundation'] : []),
|
|
|
|
...(platform === 'win32' ? ['-f', 'gdigrab', '-framerate', '30'] : []),
|
|
|
|
...(platform === 'linux' ? ['-framerate', '25', '-f', 'x11grab'] : []),
|
|
|
|
'-i', screenshotDevice,
|
2024-09-01 14:58:03 +02:00
|
|
|
'-vframes', '1', outPath,
|
|
|
|
], { timeout: 30000 });
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const resp = await client('', {
|
|
|
|
retry: { backoffLimit: 5000, limit: 10 },
|
|
|
|
hooks: { beforeRequest: [() => { console.log('attempt'); }] },
|
|
|
|
}).text();
|
|
|
|
assert(resp.length > 0);
|
|
|
|
|
|
|
|
console.log('Waiting for UI to settle');
|
|
|
|
|
|
|
|
await timers.setTimeout(5000);
|
|
|
|
|
|
|
|
console.log('Capturing screenshot');
|
|
|
|
|
|
|
|
await captureScreenshot(screenshotOutPath);
|
|
|
|
|
|
|
|
console.log('Sending quit command');
|
|
|
|
|
|
|
|
await client.post('api/action/quit').text();
|
|
|
|
} finally {
|
|
|
|
// ps.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Waiting for app to quit');
|
|
|
|
|
2024-09-02 23:55:31 +02:00
|
|
|
const { stdout, stderr } = await ps;
|
2024-09-01 14:58:03 +02:00
|
|
|
|
|
|
|
console.log('App has quit');
|
2024-09-02 23:55:31 +02:00
|
|
|
|
|
|
|
console.log('stdout:', stdout);
|
|
|
|
console.log('stderr:', stderr);
|