From 2c55c0e4527c6d86b97e84ef25e62e787d96de9a Mon Sep 17 00:00:00 2001 From: vgmoose Date: Sun, 20 Aug 2023 20:09:13 -0400 Subject: [PATCH] add callback launching support for switch/wiiu --- .github/workflows/main.yml | 2 +- .gitmodules | 3 +++ Makefile | 9 +++++---- README.md | 4 +++- edit/main.cpp | 6 ++++++ gui/MainDisplay.cpp | 31 ++++++++++++++++++++++++++++++- libs/chesto | 2 +- libs/librpxloader | 1 + 8 files changed, 50 insertions(+), 8 deletions(-) create mode 160000 libs/librpxloader diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7082730..05c6c53 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: - platform: switch ext: nro container: - image: ghcr.io/fortheusers/sealeo:latest + image: ghcr.io/fortheusers/sealeo:sha-1474053 steps: - uses: actions/checkout@main with: diff --git a/.gitmodules b/.gitmodules index 3f44921..9ad73f0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "libs/json"] path = libs/json url = https://github.com/nlohmann/json.git +[submodule "libs/librpxloader"] + path = libs/librpxloader + url = https://github.com/wiiu-env/librpxloader.git diff --git a/Makefile b/Makefile index 8cf61cd..360445f 100644 --- a/Makefile +++ b/Makefile @@ -7,12 +7,13 @@ APP_VERSION := 2.1 SOURCES += . gui edit CFLAGS += -DUSE_KEYBOARD -SOURCES += $(CHESTO_DIR)/libs/SDL_FontCache -VPATH += $(CHESTO_DIR)/libs/SDL_FontCache +SOURCES += $(CHESTO_DIR)/libs/SDL_FontCache +VPATH += $(CHESTO_DIR)/libs/SDL_FontCache ifeq (wiiu,$(MAKECMDGOALS)) -SOURCES += $(CHESTO_DIR)/libs/wiiu_kbd -VPATH += $(CHESTO_DIR)/libs/wiiu_kbd +SOURCES += $(CHESTO_DIR)/libs/wiiu_kbd libs/librpxloader/source +VPATH += $(CHESTO_DIR)/libs/wiiu_kbd +INCLUDES += ../libs/librpxloader/include endif include libs/chesto/Makefile \ No newline at end of file diff --git a/README.md b/README.md index 0432dfd..0efc975 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,9 @@ A basic SDL2 text editor designed for easy use on a video game console using a controller or touch screen. The primary goal of this project is to allow you to not have to turn to another device to edit text files. -## Passing files to vgedit +File browser Editor View + +### Passing files to vgedit vgedit can be passed a file name to open by specifying it as the first argument on the command line. On PC this looks like `vgedit.exe test.txt`, and on Switch/Wii U, if supported, the calling homebrew can pass the argument before launching vgedit. Another way to pass a target file is to write an `args.json` file in the same directory as vgedit. For example, to open `test.txt`: diff --git a/edit/main.cpp b/edit/main.cpp index fd65b3f..248e76b 100644 --- a/edit/main.cpp +++ b/edit/main.cpp @@ -25,9 +25,15 @@ int main(int argc, char* argv[]) std::string startPath = START_PATH; + // USAGE: vgedit [file to edit path] [callback path] if (argc > 1) { // get the file path from the command line startPath = argv[1]; + + // if there's a callback path, store it for later + if (argc > 2) { + display->callbackPath = argv[2]; + } } // check if the args.json file exists diff --git a/gui/MainDisplay.cpp b/gui/MainDisplay.cpp index c67548e..275da5f 100644 --- a/gui/MainDisplay.cpp +++ b/gui/MainDisplay.cpp @@ -2,6 +2,14 @@ #include "EditorView.hpp" #include "FileBrowser.hpp" +#if defined(__WIIU__) +#include "../libs/librpxloader/include/rpxloader/rpxloader.h" +#endif + +#if defined(SWITCH) +#include +#endif + MainDisplay::MainDisplay() { RootDisplay::super(); @@ -43,8 +51,29 @@ void MainDisplay::closeEditor() // (single file mode) if (callbackPath != "") { - // TODO: on switch/wiiu set the next nro/wuhb to launch std::cout << "Launching " << callbackPath << std::endl; + bool success = false; + + #ifdef __WIIU__ + RPXLoaderStatus ret = RPXLoader_InitLibrary(); + if (ret == RPX_LOADER_RESULT_SUCCESS) { + auto res = RPXLoader_LaunchHomebrew(callbackPath.c_str()); + success = res == RPX_LOADER_RESULT_SUCCESS; + } + #endif + + #ifdef SWITCH + // use envSetNextLoad to set the path to the app to launch + if (envHasNextLoad()) { + auto res = envSetNextLoad(callbackPath.c_str(), editorView->editor->filename); // give it the filename of the file we edited + success = R_SUCCEEDED(res); + } + #endif + + if (!success) { + std::cout << "Failed to launch " << callbackPath << std::endl; + exit(1); + } } exit(0); diff --git a/libs/chesto b/libs/chesto index e812797..f6710e8 160000 --- a/libs/chesto +++ b/libs/chesto @@ -1 +1 @@ -Subproject commit e812797a5c8627e4fc3e68b8760ae7b736facbc5 +Subproject commit f6710e8fcd1497d6b2f5d07030881cea24c5ea9e diff --git a/libs/librpxloader b/libs/librpxloader new file mode 160000 index 0000000..cad78bc --- /dev/null +++ b/libs/librpxloader @@ -0,0 +1 @@ +Subproject commit cad78bc9329d538f132198c9077ae7a5001a8b09