This commit is contained in:
@@ -147,6 +147,37 @@ if (window.Capacitor?.isNativePlatform?.()) {
|
||||
webPlatform.systemBars = { setColors: (opts) => SystemBars.setColors(opts) };
|
||||
webPlatform.features.hasSystemBars = true;
|
||||
}
|
||||
|
||||
// Android hardware back button → dispatch to the app-level registry.
|
||||
// We expose a `detail.handled` flag so in-tree listeners (see
|
||||
// `useBackHandler`) can claim the event. When nothing claims it, we
|
||||
// fall back to `App.minimizeApp()` so the user lands on their home
|
||||
// screen instead of force-exiting the process.
|
||||
const AppPlugin = window.Capacitor.Plugins.App;
|
||||
if (AppPlugin && typeof AppPlugin.addListener === 'function') {
|
||||
AppPlugin.addListener('backButton', () => {
|
||||
const detail = { handled: false };
|
||||
try {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('brycord:android-back', { detail }),
|
||||
);
|
||||
} catch (e) {
|
||||
console.warn('[backButton] dispatch failed', e);
|
||||
}
|
||||
if (!detail.handled) {
|
||||
try {
|
||||
if (typeof AppPlugin.minimizeApp === 'function') {
|
||||
AppPlugin.minimizeApp();
|
||||
} else if (typeof AppPlugin.exitApp === 'function') {
|
||||
AppPlugin.exitApp();
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[backButton] fallback failed', e);
|
||||
}
|
||||
}
|
||||
});
|
||||
webPlatform.features.hasBackButton = true;
|
||||
}
|
||||
}
|
||||
|
||||
export default webPlatform;
|
||||
|
||||
Reference in New Issue
Block a user