diff --git a/app/main.ts b/app/main.ts index 8c6ce889c5..2a654bb75b 100644 --- a/app/main.ts +++ b/app/main.ts @@ -174,7 +174,11 @@ const preventDisplaySleepService = new PreventDisplaySleepService( powerSaveBlocker ); -const challengeHandler = new ChallengeMainHandler(); +const challengeHandler = new ChallengeMainHandler( + config.has('hardcodedCaptchaForLocalTestingOnly') + ? config.get('hardcodedCaptchaForLocalTestingOnly') + : undefined +); const nativeThemeNotifier = new NativeThemeNotifier(); nativeThemeNotifier.initialize(); diff --git a/ts/main/challengeMain.ts b/ts/main/challengeMain.ts index 93a9fc7b32..2469d3a33e 100644 --- a/ts/main/challengeMain.ts +++ b/ts/main/challengeMain.ts @@ -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(resolve => { - this.#handlers.push(resolve); - }); + const data = + this.#hardcodedResult || + (await new Promise(resolve => { + this.#handlers.push(resolve); + })); const duration = Date.now() - start; log.info(`${logId}: got response after ${duration}ms`);