forked from github/awesome-cordova-plugins
86b637e85a
closes: #2452
26 lines
928 B
TypeScript
26 lines
928 B
TypeScript
export function checkReady() {
|
|
const DEVICE_READY_TIMEOUT = 5000;
|
|
|
|
// To help developers using cordova, we listen for the device ready event and
|
|
// log an error if it didn't fire in a reasonable amount of time. Generally,
|
|
// when this happens, developers should remove and reinstall plugins, since
|
|
// an inconsistent plugin is often the culprit.
|
|
const before = Date.now();
|
|
|
|
let didFireReady = false;
|
|
document.addEventListener('deviceready', () => {
|
|
console.log(
|
|
`Ionic Native: deviceready event fired after ${Date.now() - before} ms`
|
|
);
|
|
didFireReady = true;
|
|
});
|
|
|
|
setTimeout(() => {
|
|
if (!didFireReady && window.cordova) {
|
|
console.warn(
|
|
`Ionic Native: deviceready did not fire within ${DEVICE_READY_TIMEOUT}ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.`
|
|
);
|
|
}
|
|
}, DEVICE_READY_TIMEOUT);
|
|
}
|