Skip to content

Commit

Permalink
Add exit confirmation.
Browse files Browse the repository at this point in the history
See #339.

Signed-off-by: Thomas Rohloff <[email protected]>
  • Loading branch information
V10lator committed Aug 4, 2024
1 parent 44edfbe commit 770e2d7
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 9 deletions.
1 change: 1 addition & 0 deletions data/locale/German.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"Are you really sure you want to brick your Wii U?": "Bist du sicher das du deine Konsole zerstören willst?",
"You're on your own doing this,\ndo you understand the consequences?": "Du bist selbst verantwortlich wenn du fortfährst,\nverstehst du die Konsequenzen?",

"Do you really want to exit?": "Willst du wirklich beenden?",
"Search": "Suche",
"unknown": "unbekannten",
"Yes": "Ja",
Expand Down
1 change: 1 addition & 0 deletions include/menu/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extern "C"
void showNoSpaceOverlay(NUSDEV dev);
void humanize(uint64_t size, char *out);
void getFreeSpaceString(NUSDEV dev, char *out);
bool showExitOverlay();

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions meta/baselocale.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
"Are you really sure you want to brick your Wii U?": "Are you really sure you want to brick your Wii U?",
"You're on your own doing this,\ndo you understand the consequences?": "You're on your own doing this,\ndo you understand the consequences?",

"Do you really want to exit?": "Do you really want to exit?",
"Search": "Search",
"unknown": "unknown",
"Yes": "Yes",
Expand Down
2 changes: 1 addition & 1 deletion src/ioQueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ bool checkForQueueErrors()
}

if(AppRunning(true))
homeButtonCallback(NULL);
homeButtonCallback((void *)true);
}

return true;
Expand Down
10 changes: 6 additions & 4 deletions src/menu/mainMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ void mainMenu()

if(vpad.trigger & VPAD_BUTTON_B)
{
drawByeFrame();
return;
if(showExitOverlay())
{
drawByeFrame();
return;
}
}

if(vpad.trigger & VPAD_BUTTON_A)
else if(vpad.trigger & VPAD_BUTTON_A)
{
switch(cursorPos)
{
Expand Down
40 changes: 40 additions & 0 deletions src/menu/menuUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,46 @@ void showNoSpaceOverlay(NUSDEV dev)
removeErrorOverlay(ovl);
}
}

bool showExitOverlay()
{
const char *extMsg = localise("Do you really want to exit?");
const char *yes = localise("Yes");
const char *no = localise("No");

size_t extMsgS = strlen(extMsg);
size_t yesS = strlen(yes);
size_t noS = strlen(no);

char ovlMsg[extMsgS + 2 /* "\n\n" */ + sizeof(BUTTON_A) /* not -1 cause space after it */ + yesS + 4 /* " || " */ + sizeof(BUTTON_B) + ++noS];
OSBlockMove(ovlMsg, extMsg, extMsgS, false);
OSBlockMove(ovlMsg + extMsgS, "\n\n" BUTTON_A " ", sizeof("\n\n" BUTTON_A) /* not -1 cause space after it */, false);
OSBlockMove(ovlMsg + extMsgS + sizeof("\n\n" BUTTON_A), yes, yesS, false);
OSBlockMove(ovlMsg + extMsgS + sizeof("\n\n" BUTTON_A) + yesS, " || " BUTTON_B " ", sizeof(" || " BUTTON_B), false);
OSBlockMove(ovlMsg + extMsgS + sizeof("\n\n" BUTTON_A) + yesS + sizeof(" || " BUTTON_B), no, noS, false);

void *ovl = addErrorOverlay(ovlMsg);
if(ovl == NULL)
return true;

bool ret = false;
while(AppRunning(true))
{
showFrame();

if(vpad.trigger & VPAD_BUTTON_A)
{
ret = true;
break;
}
if(vpad.trigger & VPAD_BUTTON_B)
break;
}

removeErrorOverlay(ovl);
return ret;
}

void humanize(uint64_t size, char *out)
{
const char *m;
Expand Down
7 changes: 3 additions & 4 deletions src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <cfw.h>
#include <crypto.h>
#include <exception.h>
#include <menu/utils.h>
#include <renderer.h>
#include <state.h>
#include <utils.h>
Expand Down Expand Up @@ -113,9 +114,7 @@ bool isChannel()

uint32_t homeButtonCallback(void *dummy)
{
(void)dummy;

if(shutdownEnabled)
if(shutdownEnabled && dummy == (void *)false && showExitOverlay())
{
shutdownEnabled = false;
app = APP_STATE_HOME;
Expand All @@ -136,7 +135,7 @@ void initState()
debugInit();
debugPrintf("NUSspli " NUSSPLI_VERSION);

ProcUIRegisterCallback(PROCUI_CALLBACK_HOME_BUTTON_DENIED, &homeButtonCallback, NULL, 100);
ProcUIRegisterCallback(PROCUI_CALLBACK_HOME_BUTTON_DENIED, &homeButtonCallback, (void *)false, 100);
OSEnableHomeButtonMenu(false);
ACPInitialize();

Expand Down

0 comments on commit 770e2d7

Please sign in to comment.