Handle Android back navigation in app
This commit is contained in:
@@ -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.
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user