29 lines
787 B
TypeScript
29 lines
787 B
TypeScript
export interface NativeLoginHandoff {
|
|
request(): void;
|
|
}
|
|
|
|
export interface ProcessNativeLoginHandoffOptions {
|
|
exitCode?: number;
|
|
delayMs?: number;
|
|
exit?: (code: number) => void;
|
|
}
|
|
|
|
export class ProcessNativeLoginHandoff implements NativeLoginHandoff {
|
|
private requested = false;
|
|
private readonly exitCode: number;
|
|
private readonly delayMs: number;
|
|
private readonly exit: (code: number) => void;
|
|
|
|
constructor(options: ProcessNativeLoginHandoffOptions = {}) {
|
|
this.exitCode = options.exitCode ?? 75;
|
|
this.delayMs = options.delayMs ?? 250;
|
|
this.exit = options.exit ?? ((code) => process.exit(code));
|
|
}
|
|
|
|
request(): void {
|
|
if (this.requested) return;
|
|
this.requested = true;
|
|
setTimeout(() => this.exit(this.exitCode), this.delayMs).unref();
|
|
}
|
|
}
|