36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
/* Keep Android back navigation inside MetalCircle until the calendar home. */
|
|
(() => {
|
|
const capacitor = window.Capacitor;
|
|
if (!capacitor || capacitor.getPlatform() !== 'android' || typeof capacitor.addListener !== 'function') return;
|
|
|
|
try {
|
|
capacitor.addListener('App', 'backButton', ({canGoBack}) => {
|
|
const openDialog = document.querySelector('dialog[open]');
|
|
if (openDialog) {
|
|
openDialog.close();
|
|
return;
|
|
}
|
|
|
|
const openDetails = document.querySelector('details[open]');
|
|
if (openDetails) {
|
|
openDetails.open = false;
|
|
return;
|
|
}
|
|
|
|
if (location.pathname === '/') {
|
|
capacitor.nativePromise('App', 'exitApp', {}).catch(() => {});
|
|
return;
|
|
}
|
|
|
|
if (canGoBack) {
|
|
history.back();
|
|
return;
|
|
}
|
|
|
|
location.replace('/');
|
|
});
|
|
} catch (_) {
|
|
// The website remains usable when the native App plugin is unavailable.
|
|
}
|
|
})();
|