mirror of https://github.com/mastodon/mastodon
Disable push notification when not logged in (#19272)
parent
37eaa7fc01
commit
216dbaedaf
@ -1,7 +1,32 @@
|
|||||||
export default function ready(loaded) {
|
// @ts-check
|
||||||
if (['interactive', 'complete'].includes(document.readyState)) {
|
|
||||||
loaded();
|
/**
|
||||||
} else {
|
* @param {(() => void) | (() => Promise<void>)} callback
|
||||||
document.addEventListener('DOMContentLoaded', loaded);
|
* @returns {Promise<void>}
|
||||||
}
|
*/
|
||||||
|
export default function ready(callback) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
function loaded() {
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
result = callback();
|
||||||
|
} catch (err) {
|
||||||
|
reject(err);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof result?.then === 'function') {
|
||||||
|
result.then(resolve).catch(reject);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (['interactive', 'complete'].includes(document.readyState)) {
|
||||||
|
loaded();
|
||||||
|
} else {
|
||||||
|
document.addEventListener('DOMContentLoaded', loaded);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue