Line data Source code
1 : #pragma once
2 : #include <SDL.h>
3 :
4 : /**
5 : * @brief Displays a native modal popup to ask the user if they wish to restore
6 : * the previous session after a crash.
7 : * * @return true if the user clicks "Restore", false if "Discard".
8 : */
9 :
10 12 : inline bool promptRestoreSession() {
11 : #if defined(__EMSCRIPTEN__) || defined(AMPLITRON_HEADLESS)
12 : // Blocking message boxes not supported in WebAssembly or headless test builds.
13 12 : return false;
14 : #else
15 0 : if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
16 0 : if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) return false;
17 0 : }
18 :
19 0 : const SDL_MessageBoxButtonData buttons[] = {
20 : {SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1, "Restore"},
21 : {SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 0, "Discard"},
22 : };
23 :
24 0 : const SDL_MessageBoxData messageboxdata = {
25 : SDL_MESSAGEBOX_WARNING,
26 : nullptr,
27 : "Amplitron Recovery",
28 : "Amplitron closed unexpectedly during your last session.\n\n"
29 : "Would you like to restore your previous pedal chain configuration?",
30 : SDL_arraysize(buttons),
31 0 : buttons,
32 0 : nullptr};
33 :
34 0 : int buttonid;
35 0 : if (SDL_ShowMessageBox(&messageboxdata, &buttonid) < 0) return false;
36 0 : return buttonid == 1;
37 : #endif
38 0 : }
|