mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* fix(cli): a Chrome download that stops sending is abandoned, retried, and releases the lock * fix(cli): a stalled Chrome download is aborted at the socket so the process can exit * fix(cli): the Chrome download runs in its own process and is killed when it stalls * test(cli): ignore the expected socket reset in the download stall test on Windows
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
const PROGRESS_PREFIX = "HYPERFRAMES_BROWSER_INSTALL_PROGRESS:";
|
|
const LOG_PREFIX = "HYPERFRAMES_BROWSER_INSTALL_LOG:";
|
|
|
|
export type InstallEvent =
|
|
| { kind: "progress"; downloaded: number; total: number }
|
|
| { kind: "log"; text: string };
|
|
|
|
export function installProgressLine(downloaded: number, total: number): string {
|
|
return `${PROGRESS_PREFIX}${JSON.stringify([downloaded, total])}\n`;
|
|
}
|
|
|
|
export function installLogLine(text: string): string {
|
|
return `${LOG_PREFIX}${JSON.stringify(text)}\n`;
|
|
}
|
|
|
|
export function parseInstallLine(line: string): InstallEvent | null {
|
|
try {
|
|
if (line.startsWith(PROGRESS_PREFIX)) {
|
|
const [downloaded, total] = JSON.parse(line.slice(PROGRESS_PREFIX.length)) as [
|
|
number,
|
|
number,
|
|
];
|
|
return { kind: "progress", downloaded, total };
|
|
}
|
|
if (line.startsWith(LOG_PREFIX)) {
|
|
return { kind: "log", text: JSON.parse(line.slice(LOG_PREFIX.length)) as string };
|
|
}
|
|
} catch {
|
|
// a torn line is dropped: the next progress line carries the same information
|
|
}
|
|
return null;
|
|
}
|