Implement mobile connection resumes
This commit is contained in:
29
src/main.ts
29
src/main.ts
@ -7,5 +7,32 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||
for (const noscript of document.getElementsByTagName("noscript")) {
|
||||
noscript.remove();
|
||||
}
|
||||
new Locutus.App();
|
||||
|
||||
const locutus = new Locutus.App();
|
||||
if (isMobilePlatform()) {
|
||||
console.log("MOBILE");
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (document.visibilityState === 'hidden') {
|
||||
locutus.sleep();
|
||||
} else if (document.visibilityState === 'visible') {
|
||||
locutus.wakeup().then();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log("DESKTOP");
|
||||
window.addEventListener("beforeunload", (evt) => {
|
||||
locutus.close();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function isMobilePlatform(): boolean {
|
||||
if (window.matchMedia("(any-pointer:coarse)").matches) return true;
|
||||
const ua = navigator.userAgent;
|
||||
if (/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(ua)) {
|
||||
return true;
|
||||
} else if (/Mobile|Android|iP(hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(ua)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user