diff --git a/packages/app/package.json b/packages/app/package.json index caaab578..14423f06 100755 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -24,6 +24,7 @@ "dependencies": { "@ant-design/icons": "4.7.0", "@capacitor/android": "^4.5.0", + "@capacitor/app": "^4.1.1", "@capacitor/cli": "^4.5.0", "@capacitor/core": "^4.5.0", "@capacitor/haptics": "1.1.4", diff --git a/packages/app/src/App.jsx b/packages/app/src/App.jsx index 6e91630c..0e1000c5 100755 --- a/packages/app/src/App.jsx +++ b/packages/app/src/App.jsx @@ -54,6 +54,7 @@ import { Helmet } from "react-helmet" import * as antd from "antd" import { Toast } from "antd-mobile" import { StatusBar, Style } from "@capacitor/status-bar" +import { App as CapacitorApp } from "@capacitor/app" import { Translation } from "react-i18next" import { Session, User } from "models" @@ -105,6 +106,17 @@ class App extends React.Component { // append var to #root document.getElementById("root").classList.add("electron") } + + if (this.publicMethods.isAppCapacitor()) { + // prevent back button to close app + CapacitorApp.addListener('backButton', ({ canGoBack }) => { + if (!canGoBack) { + CapacitorApp.exitApp(); + } else { + window.history.back(); + } + }); + } } static publicEvents = { @@ -316,7 +328,7 @@ class App extends React.Component { escClosable: true, }) } - + return window.app.ModalController.open((props) => ) }, openSettings: (goTo) => {