Merge pull request #30 from crc-32/app_loading

WIP: App Loading
This commit is contained in:
vgmoose 2018-11-20 18:44:54 -05:00 committed by GitHub
commit 2df8d1b1d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 2 deletions

View File

@ -49,12 +49,25 @@ AppDetails::AppDetails(Package* package, AppList* appList)
Button* download = new Button(action, A_BUTTON, true, 30);
download->position(970, 550);
download->action = std::bind(&AppDetails::proceed, this);
this->elements.push_back(download);
Button* cancel = new Button("Cancel", B_BUTTON, true, 30, download->width);
cancel->position(970, 630);
cancel->action = std::bind(&AppDetails::back, this);
Button* start = new Button("Launch", START_BUTTON, true, 30, download->width);
#if defined(SWITCH)
if((package->status == UPDATE || package->status == INSTALLED || package->status == LOCAL) && envHasNextLoad() && package->binary != "none"){
download->position(970, 470);
start->position(970, 550);
cancel->position(970, 630);
start->action = std::bind(&AppDetails::launch, this);
this->elements.push_back(start);
}
#endif
this->elements.push_back(cancel);
this->elements.push_back(download);
// the scrollable portion of the app details page
@ -131,6 +144,17 @@ void AppDetails::proceed()
SDL_PushEvent(&sdlevent);
}
void AppDetails::launch()
{
#if defined(SWITCH)
SDL_Event sdlevent;
sdlevent.type = SDL_JOYBUTTONDOWN;
// 10 = KEY_PLUS for switch, see https://github.com/devkitPro/SDL/blob/switch-sdl2/src/joystick/switch/SDL_sysjoystick.c#L52
sdlevent.jbutton.button = 10;
SDL_PushEvent(&sdlevent);
#endif
}
void AppDetails::back()
{
SDL_Event sdlevent;
@ -159,6 +183,8 @@ void AppDetails::leaveFeedback()
bool AppDetails::process(InputEvents* event)
{
SDL_Color red = {0xFF, 0x00, 0x00, 0xff};
// don't process any keystrokes if an operation is in progress
if (this->operating)
return false;
@ -205,6 +231,34 @@ bool AppDetails::process(InputEvents* event)
this->appList->update();
return true;
}
#if defined(SWITCH)
if (event->pressed(START_BUTTON) && this->canLaunch == true)
{
char path[8+strlen(package->binary.c_str())];
sprintf(path, "sdmc:/%s", package->binary.c_str());
printf("Launch path: %s\n", path);
FILE *file;
bool successLaunch;
//Final check if path actually exists
if ((file = fopen(path, "r")))
{
fclose(file);
printf("Path OK, Launching...");
successLaunch = this->launchFile(path, path);
}else successLaunch = false;
if(!successLaunch){
printf("Failed to launch.");
TextElement* errorText = new TextElement("Couldn't launch app", 24, &red, false, 300);
errorText->position(970, 430);
this->elements.push_back(errorText);
this->canLaunch = false;
}
return true;
}
#endif
if (event->isTouchDown())
this->dragging = true;
@ -222,6 +276,17 @@ void AppDetails::preInstallHook()
#endif
}
bool AppDetails::launchFile(char* path, char* context){
#if defined(SWITCH)
//If setnexload works without problems, quit to make loader open next nro
if(R_SUCCEEDED(envSetNextLoad(path, context))){
quit();
return true;
}
return false;
#endif
}
void AppDetails::postInstallHook()
{
#if defined(SWITCH)

View File

@ -16,6 +16,7 @@ public:
AppDetails(Package* package, AppList* appList);
bool process(InputEvents* event);
void render(Element* parent);
bool launchFile(char* path, char* context);
bool operating = false;
Package* package;
@ -23,12 +24,15 @@ public:
AppList* appList;
ProgressBar* pbar = NULL;
int highlighted = -1;
bool canLaunch = true;
// the callback method to update the currently displayed pop up (and variables it needs)
static int updateCurrentlyDisplayedPopup(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
void proceed();
void back();
void launch();
void moreByAuthor();
void leaveFeedback();

View File

@ -28,6 +28,9 @@ Button::Button(const char* message, int button, bool dark, int size, int width)
case X_BUTTON:
unicode = "\ue0a3";
break;
case START_BUTTON:
unicode = "\ue0a4";
break;
default:
unicode = "";
}

@ -1 +1 @@
Subproject commit 2567c622051237dbb59ea14ec06acb733230fe5a
Subproject commit 986e0f63ee18f39e7d86c898384f416f73d26750

Binary file not shown.