Skip to content

Commit

Permalink
Add a function that minimizes the Android app (#692)
Browse files Browse the repository at this point in the history
Add a function that minimizes the Android app
  • Loading branch information
albexk authored Mar 31, 2024
1 parent db8d966 commit c6e6f2a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client/android/src/org/amnezia/vpn/AmneziaActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
5 changes: 5 additions & 0 deletions client/platforms/android/android_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions client/platforms/android/android_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AndroidController : public QObject
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);
Expand Down
8 changes: 8 additions & 0 deletions client/ui/controllers/pageController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#endif

#ifdef Q_OS_ANDROID
#include "platforms/android/android_controller.h"
#include "platforms/android/android_utils.h"
#include <QJniObject>
#endif
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions client/ui/controllers/pageController.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public slots:
QString getPagePath(PageLoader::PageEnum page);

void closeWindow();
void hideWindow();
void keyPressEvent(Qt::Key key);

unsigned int getInitialPageNavigationBarColor();
Expand Down
1 change: 1 addition & 0 deletions client/ui/qml/Pages2/PageSetupWizardStart.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ PageType {

function onClosePage() {
if (stackView.depth <= 1) {
PageController.hideWindow()
return
}
stackView.pop()
Expand Down
1 change: 1 addition & 0 deletions client/ui/qml/Pages2/PageStart.qml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ PageType {

function onClosePage() {
if (tabBarStackView.depth <= 1) {
PageController.hideWindow()
return
}
tabBarStackView.pop()
Expand Down

0 comments on commit c6e6f2a

Please sign in to comment.