Function: waitForElectronAPI()
waitForElectronAPI(
maxAttempts
:number
,baseDelay
:number
):Promise
<void
>
Defined in: src/stores/utils.ts:208
Utility function to wait for electronAPI to be available.
Parametersโ
maxAttemptsโ
number
= 50
Maximum number of polling attempts
baseDelayโ
number
= 100
Base delay in milliseconds for exponential backoff
Returnsโ
Promise
<void
>
Promise that resolves when electronAPI is available
Remarksโ
Polls for the API with exponential backoff to handle timing issues during application startup. This is necessary because the preload script may not have finished executing when React components first mount.
Exampleโ
try {
await waitForElectronAPI();
// Safe to use window.electronAPI
} catch (error) {
logger.error("ElectronAPI not available", error as https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error);
}
Default Valueโ
maxAttempts - 50;
Default Valueโ
baseDelay - 100;
Throwsโ
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Error when electronAPI is not available after maximum attempts