Allow hardcoding a captcha response in the config files

This commit is contained in:
Jordan Rose
2025-09-19 12:30:24 -07:00
committed by GitHub
parent 55e8e4376b
commit 140241b83f
2 changed files with 16 additions and 5 deletions
+5 -1
View File
@@ -174,7 +174,11 @@ const preventDisplaySleepService = new PreventDisplaySleepService(
powerSaveBlocker
);
const challengeHandler = new ChallengeMainHandler();
const challengeHandler = new ChallengeMainHandler(
config.has('hardcodedCaptchaForLocalTestingOnly')
? config.get<string>('hardcodedCaptchaForLocalTestingOnly')
: undefined
);
const nativeThemeNotifier = new NativeThemeNotifier();
nativeThemeNotifier.initialize();
+11 -4
View File
@@ -10,13 +10,18 @@ import type {
IPCResponse,
ChallengeResponse,
} from '../challenge.js';
import { getEnvironment, Environment } from '../environment.js';
const log = createLogger('challengeMain');
export class ChallengeMainHandler {
#handlers: Array<(response: ChallengeResponse) => void> = [];
#hardcodedResult?: ChallengeResponse;
constructor() {
constructor(hardcodedResult?: string) {
if (hardcodedResult && getEnvironment() === Environment.Development) {
this.#hardcodedResult = { captcha: hardcodedResult };
}
this.#initialize();
}
@@ -41,9 +46,11 @@ export class ChallengeMainHandler {
const start = Date.now();
const data = await new Promise<ChallengeResponse>(resolve => {
this.#handlers.push(resolve);
});
const data =
this.#hardcodedResult ||
(await new Promise<ChallengeResponse>(resolve => {
this.#handlers.push(resolve);
}));
const duration = Date.now() - start;
log.info(`${logId}: got response after ${duration}ms`);