From c0d998017d027a82ccf5c5f0602cb57ab18bf40c Mon Sep 17 00:00:00 2001 From: Yaya-Cout Date: Fri, 17 Feb 2023 19:32:50 +0100 Subject: [PATCH] [apps/main] Add open app option --- apps/apps_container.cpp | 11 +++++++++-- apps/apps_container.h | 6 ++++++ apps/main.cpp | 19 ++++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 7e63f7503..ef2753f20 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -37,7 +37,8 @@ AppsContainer::AppsContainer() : m_homeSnapshot(), m_onBoardingSnapshot(), m_hardwareTestSnapshot(), - m_usbConnectedSnapshot() + m_usbConnectedSnapshot(), + m_startAppSnapshot() { m_emptyBatteryWindow.setFrame(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height), false); // #if __EMSCRIPTEN__ @@ -346,7 +347,13 @@ void AppsContainer::run() { /* Normal execution. The exception checkpoint must be created before * switching to the first app, because the first app might create nodes on * the pool. */ - bool switched = switchTo(initialAppSnapshot()); + bool switched; + if (m_startAppSnapshot != nullptr) { + switched = switchTo(m_startAppSnapshot); + } else { + switched = switchTo(initialAppSnapshot()); + } + assert(switched); (void) switched; // Silence compilation warning about unused variable. } else { diff --git a/apps/apps_container.h b/apps/apps_container.h index 0d49cdedb..485c5ce3b 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -59,6 +59,9 @@ public: // Ion::StorageDelegate void storageDidChangeForRecord(const Ion::Storage::Record record) override; void storageIsFull() override; + #ifdef EPSILON_GETOPT + void setStartApp(App::Snapshot * snapshot) { m_startAppSnapshot = snapshot; } + #endif protected: Home::App::Snapshot * homeAppSnapshot() { return &m_homeSnapshot; } private: @@ -89,6 +92,9 @@ private: HardwareTest::App::Snapshot m_hardwareTestSnapshot; USB::App::Snapshot m_usbConnectedSnapshot; XNTLoop m_XNTLoop; + #ifdef EPSILON_GETOPT + App::Snapshot * m_startAppSnapshot; + #endif }; #endif diff --git a/apps/main.cpp b/apps/main.cpp index b73b73e77..ec1db8b80 100644 --- a/apps/main.cpp +++ b/apps/main.cpp @@ -1,6 +1,7 @@ #include "apps_container.h" #include "global_preferences.h" #include +#include #define DUMMY_MAIN 0 #if DUMMY_MAIN @@ -50,13 +51,29 @@ void ion_main(int argc, const char * const argv[]) { } continue; } + + /* Option should be given at run-time: + * $ ./epsilon.elf --open-app code + */ + const char * appNames[] = {"home", EPSILON_APPS_NAMES}; + if (strcmp(argv[i], "--open-app") == 0 && argc > i+1) { + const char * requestedAppName = argv[i+1]; + for (int j = 0; j < AppsContainer::sharedAppsContainer()->numberOfApps(); j++) { + App::Snapshot * snapshot = AppsContainer::sharedAppsContainer()->appSnapshotAtIndex(j); + if (strcmp(requestedAppName, appNames[j]) == 0) { + AppsContainer::sharedAppsContainer()->setStartApp(snapshot); + break; + } + } + continue; + } + /* Option should be given at run-time: * $ ./epsilon.elf --[app_name]-[option] [arguments] * For example: * $ make -j8 PLATFORM=emscripten EPSILON_APPS=code * $ ./epsilon.elf --code-script hello_world.py:print("hello") --code-lock-on-console */ - const char * appNames[] = {"home", EPSILON_APPS_NAMES}; for (int j = 0; j < AppsContainer::sharedAppsContainer()->numberOfApps(); j++) { App::Snapshot * snapshot = AppsContainer::sharedAppsContainer()->appSnapshotAtIndex(j); // Compare name in order to find if the firsts chars which are different are NULL and '-'