Skip to content

Commit 770e2d7

Browse files
committed
Add exit confirmation.
See #339. Signed-off-by: Thomas Rohloff <[email protected]>
1 parent 44edfbe commit 770e2d7

File tree

7 files changed

+53
-9
lines changed

7 files changed

+53
-9
lines changed

data/locale/German.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
"Are you really sure you want to brick your Wii U?": "Bist du sicher das du deine Konsole zerstören willst?",
180180
"You're on your own doing this,\ndo you understand the consequences?": "Du bist selbst verantwortlich wenn du fortfährst,\nverstehst du die Konsequenzen?",
181181

182+
"Do you really want to exit?": "Willst du wirklich beenden?",
182183
"Search": "Suche",
183184
"unknown": "unbekannten",
184185
"Yes": "Ja",

include/menu/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extern "C"
6363
void showNoSpaceOverlay(NUSDEV dev);
6464
void humanize(uint64_t size, char *out);
6565
void getFreeSpaceString(NUSDEV dev, char *out);
66+
bool showExitOverlay();
6667

6768
#ifdef __cplusplus
6869
}

meta/baselocale.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
"Are you really sure you want to brick your Wii U?": "Are you really sure you want to brick your Wii U?",
191191
"You're on your own doing this,\ndo you understand the consequences?": "You're on your own doing this,\ndo you understand the consequences?",
192192

193+
"Do you really want to exit?": "Do you really want to exit?",
193194
"Search": "Search",
194195
"unknown": "unknown",
195196
"Yes": "Yes",

src/ioQueue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ bool checkForQueueErrors()
171171
}
172172

173173
if(AppRunning(true))
174-
homeButtonCallback(NULL);
174+
homeButtonCallback((void *)true);
175175
}
176176

177177
return true;

src/menu/mainMenu.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@ void mainMenu()
105105

106106
if(vpad.trigger & VPAD_BUTTON_B)
107107
{
108-
drawByeFrame();
109-
return;
108+
if(showExitOverlay())
109+
{
110+
drawByeFrame();
111+
return;
112+
}
110113
}
111-
112-
if(vpad.trigger & VPAD_BUTTON_A)
114+
else if(vpad.trigger & VPAD_BUTTON_A)
113115
{
114116
switch(cursorPos)
115117
{

src/menu/menuUtils.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,46 @@ void showNoSpaceOverlay(NUSDEV dev)
430430
removeErrorOverlay(ovl);
431431
}
432432
}
433+
434+
bool showExitOverlay()
435+
{
436+
const char *extMsg = localise("Do you really want to exit?");
437+
const char *yes = localise("Yes");
438+
const char *no = localise("No");
439+
440+
size_t extMsgS = strlen(extMsg);
441+
size_t yesS = strlen(yes);
442+
size_t noS = strlen(no);
443+
444+
char ovlMsg[extMsgS + 2 /* "\n\n" */ + sizeof(BUTTON_A) /* not -1 cause space after it */ + yesS + 4 /* " || " */ + sizeof(BUTTON_B) + ++noS];
445+
OSBlockMove(ovlMsg, extMsg, extMsgS, false);
446+
OSBlockMove(ovlMsg + extMsgS, "\n\n" BUTTON_A " ", sizeof("\n\n" BUTTON_A) /* not -1 cause space after it */, false);
447+
OSBlockMove(ovlMsg + extMsgS + sizeof("\n\n" BUTTON_A), yes, yesS, false);
448+
OSBlockMove(ovlMsg + extMsgS + sizeof("\n\n" BUTTON_A) + yesS, " || " BUTTON_B " ", sizeof(" || " BUTTON_B), false);
449+
OSBlockMove(ovlMsg + extMsgS + sizeof("\n\n" BUTTON_A) + yesS + sizeof(" || " BUTTON_B), no, noS, false);
450+
451+
void *ovl = addErrorOverlay(ovlMsg);
452+
if(ovl == NULL)
453+
return true;
454+
455+
bool ret = false;
456+
while(AppRunning(true))
457+
{
458+
showFrame();
459+
460+
if(vpad.trigger & VPAD_BUTTON_A)
461+
{
462+
ret = true;
463+
break;
464+
}
465+
if(vpad.trigger & VPAD_BUTTON_B)
466+
break;
467+
}
468+
469+
removeErrorOverlay(ovl);
470+
return ret;
471+
}
472+
433473
void humanize(uint64_t size, char *out)
434474
{
435475
const char *m;

src/state.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <cfw.h>
2525
#include <crypto.h>
2626
#include <exception.h>
27+
#include <menu/utils.h>
2728
#include <renderer.h>
2829
#include <state.h>
2930
#include <utils.h>
@@ -113,9 +114,7 @@ bool isChannel()
113114

114115
uint32_t homeButtonCallback(void *dummy)
115116
{
116-
(void)dummy;
117-
118-
if(shutdownEnabled)
117+
if(shutdownEnabled && dummy == (void *)false && showExitOverlay())
119118
{
120119
shutdownEnabled = false;
121120
app = APP_STATE_HOME;
@@ -136,7 +135,7 @@ void initState()
136135
debugInit();
137136
debugPrintf("NUSspli " NUSSPLI_VERSION);
138137

139-
ProcUIRegisterCallback(PROCUI_CALLBACK_HOME_BUTTON_DENIED, &homeButtonCallback, NULL, 100);
138+
ProcUIRegisterCallback(PROCUI_CALLBACK_HOME_BUTTON_DENIED, &homeButtonCallback, (void *)false, 100);
140139
OSEnableHomeButtonMenu(false);
141140
ACPInitialize();
142141

0 commit comments

Comments
 (0)