(Android) Added experimental support for running ES-DE as the home app

This commit is contained in:
Leon Styhre 2024-05-20 19:49:28 +02:00
parent 5bad361121
commit 05e641c04e
3 changed files with 44 additions and 14 deletions

View file

@ -40,6 +40,7 @@
#if defined(__ANDROID__)
#include "InputOverlay.h"
#include "utils/PlatformUtilAndroid.h"
#endif
#include <SDL2/SDL_events.h>
@ -76,7 +77,10 @@ GuiMenu::GuiMenu()
if (!Settings::getInstance()->getBool("ForceKiosk") &&
Settings::getInstance()->getString("UIMode") != "kiosk") {
#if defined(__APPLE__) || defined(__ANDROID__)
#if defined(__APPLE__)
addEntry("QUIT ES-DE", mMenuColorPrimary, false, [this] { openQuitMenu(); });
#elif defined(__ANDROID__)
if (!AndroidVariables::sIsHomeApp)
addEntry("QUIT ES-DE", mMenuColorPrimary, false, [this] { openQuitMenu(); });
#else
if (Settings::getInstance()->getBool("ShowQuitMenu"))
@ -1791,16 +1795,31 @@ void GuiMenu::openOtherOptions()
#endif
#if defined(__ANDROID__)
if (!AndroidVariables::sIsHomeApp) {
// Whether swiping or pressing back should exit the application.
auto backEventAppExit = std::make_shared<SwitchComponent>();
backEventAppExit->setState(Settings::getInstance()->getBool("BackEventAppExit"));
s->addWithLabel("BACK BUTTON/BACK SWIPE EXITS APP", backEventAppExit);
s->addSaveFunc([backEventAppExit, s] {
if (backEventAppExit->getState() != Settings::getInstance()->getBool("BackEventAppExit")) {
if (backEventAppExit->getState() !=
Settings::getInstance()->getBool("BackEventAppExit")) {
Settings::getInstance()->setBool("BackEventAppExit", backEventAppExit->getState());
s->setNeedsSaving();
}
});
}
else {
// If we're running as the Android home app then we don't allow the application to quit,
// so simply add a disabled dummy switch in this case.
auto backEventAppExit = std::make_shared<SwitchComponent>();
s->addWithLabel("BACK BUTTON/BACK SWIPE EXITS APP", backEventAppExit);
backEventAppExit->setEnabled(false);
backEventAppExit->setState(false);
backEventAppExit->setOpacity(DISABLED_OPACITY);
backEventAppExit->getParent()
->getChild(backEventAppExit->getChildIndex() - 1)
->setOpacity(DISABLED_OPACITY);
}
#endif
if (Settings::getInstance()->getBool("DebugFlag")) {

View file

@ -701,6 +701,14 @@ int main(int argc, char* argv[])
LOG(LogInfo) << applicationName << " " << PROGRAM_VERSION_STRING << "-"
<< ANDROID_VERSION_CODE << " (r" << PROGRAM_RELEASE_NUMBER << "), built "
<< PROGRAM_BUILT_STRING;
if (AndroidVariables::sIsHomeApp) {
LOG(LogInfo) << "Running as the Android home app";
}
else {
LOG(LogInfo) << "Running as a regular Android app";
}
#else
LOG(LogInfo) << applicationName << " " << PROGRAM_VERSION_STRING << " (r"
<< PROGRAM_RELEASE_NUMBER << "), built " << PROGRAM_BUILT_STRING;

View file

@ -26,6 +26,7 @@
#if defined(__ANDROID__)
#define TOUCH_GUID_STRING "-3"
#include "utils/PlatformUtilAndroid.h"
#endif
namespace
@ -477,9 +478,11 @@ bool InputManager::parseEvent(const SDL_Event& event)
return false;
#if defined(__ANDROID__)
// Quit application if the back button is pressed or if the back gesture is used.
// Quit application if the back button is pressed or if the back gesture is used,
// unless we're set as the Android home app.
if (event.key.keysym.sym == SDLK_AC_BACK &&
Settings::getInstance()->getBool("BackEventAppExit")) {
Settings::getInstance()->getBool("BackEventAppExit") &&
!AndroidVariables::sIsHomeApp) {
SDL_Event quit {};
quit.type = SDL_QUIT;
SDL_PushEvent(&quit);
@ -493,7 +496,7 @@ bool InputManager::parseEvent(const SDL_Event& event)
#if defined(__APPLE__)
if (quitShortcut != "CmdQ") {
#elif defined(__ANDROID__)
if (true) {
if (!AndroidVariables::sIsHomeApp) {
#else
if (quitShortcut != "AltF4") {
#endif