Handle Android back navigation in app

This commit is contained in:
2026-09-15 14:03:43 +02:00
parent fe2b196510
commit 2a803036b5
7 changed files with 124 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
/* 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.
}
})();