Add a function that minimizes the Android app (#692)

Add a function that minimizes the Android app
This commit is contained in:
albexk 2024-03-31 14:14:12 +03:00 committed by GitHub
parent db8d966fac
commit c6e6f2ae84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 25 additions and 0 deletions

View file

@ -476,4 +476,12 @@ class AmneziaActivity : QtActivity() {
window.setFlags(flag, LayoutParams.FLAG_SECURE)
}
}
@Suppress("unused")
fun minimizeApp() {
Log.v(TAG, "Minimize application")
mainScope.launch {
moveTaskToBack(false)
}
}
}

View file

@ -209,6 +209,11 @@ void AndroidController::setScreenshotsEnabled(bool enabled)
callActivityMethod("setScreenshotsEnabled", "(Z)V", enabled);
}
void AndroidController::minimizeApp()
{
callActivityMethod("minimizeApp", "()V");
}
// Moving log processing to the Android side
jclass AndroidController::log;
jmethodID AndroidController::logDebug;

View file

@ -40,6 +40,7 @@ public:
void exportLogsFile(const QString &fileName);
void clearLogs();
void setScreenshotsEnabled(bool enabled);
void minimizeApp();
static bool initLogging();
static void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message);

View file

@ -7,6 +7,7 @@
#endif
#ifdef Q_OS_ANDROID
#include "platforms/android/android_controller.h"
#include "platforms/android/android_utils.h"
#include <QJniObject>
#endif
@ -74,6 +75,13 @@ void PageController::closeWindow()
#endif
}
void PageController::hideWindow()
{
#ifdef Q_OS_ANDROID
AndroidController::instance()->minimizeApp();
#endif
}
void PageController::keyPressEvent(Qt::Key key)
{
switch (key) {

View file

@ -76,6 +76,7 @@ public slots:
QString getPagePath(PageLoader::PageEnum page);
void closeWindow();
void hideWindow();
void keyPressEvent(Qt::Key key);
unsigned int getInitialPageNavigationBarColor();

View file

@ -24,6 +24,7 @@ PageType {
function onClosePage() {
if (stackView.depth <= 1) {
PageController.hideWindow()
return
}
stackView.pop()

View file

@ -40,6 +40,7 @@ PageType {
function onClosePage() {
if (tabBarStackView.depth <= 1) {
PageController.hideWindow()
return
}
tabBarStackView.pop()