Skip to content

Commit de914d2

Browse files
committed
fix state
1 parent 18cca24 commit de914d2

3 files changed

Lines changed: 63 additions & 3 deletions

File tree

src/panda_sdl/frontend_sdl.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,6 @@ void FrontendSDL::initialize(SDL_Window* existingWindow, SDL_GLContext existingC
292292
imgui->setExitToSelectorCallback([this]() {
293293
returnToSelector = true;
294294
programRunning = false;
295-
emu.reset(Emulator::ReloadOption::NoReload);
296-
emu.romType = ROMType::None;
297295
});
298296
#endif
299297
}
@@ -749,6 +747,14 @@ bool FrontendSDL::consumeReturnToSelector() {
749747
return false;
750748
}
751749
returnToSelector = false;
750+
emu.reset(Emulator::ReloadOption::NoReload);
751+
emu.romType = ROMType::None;
752+
emuPaused = false;
753+
#ifdef IMGUI_FRONTEND
754+
if (imgui) {
755+
imgui->setPaused(false);
756+
}
757+
#endif
752758
return true;
753759
}
754760
#endif

src/panda_sdl/panda_fsui.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cmath>
1111
#include <cstdio>
1212
#include <cstring>
13+
#include <filesystem>
1314
#include <set>
1415
#include <string>
1516
#include <string_view>
@@ -19,6 +20,7 @@
1920

2021
#include "IconsFontAwesome5.h"
2122
#include "IconsPromptFont.h"
23+
#include "helpers.hpp"
2224
#include "config.hpp"
2325
#include "emulator.hpp"
2426
#include "frontend_settings.hpp"
@@ -113,6 +115,56 @@ namespace
113115
return value;
114116
}
115117

118+
std::string percentEncodeUrl(std::string_view value)
119+
{
120+
std::string encoded;
121+
encoded.reserve(value.size());
122+
for (unsigned char c : value) {
123+
const bool unreserved =
124+
(c >= 'a' && c <= 'z') ||
125+
(c >= 'A' && c <= 'Z') ||
126+
(c >= '0' && c <= '9') ||
127+
c == '-' || c == '_' || c == '.' || c == '~' || c == '/' || c == ':';
128+
if (unreserved) {
129+
encoded.push_back(static_cast<char>(c));
130+
} else {
131+
static constexpr char hex[] = "0123456789ABCDEF";
132+
encoded.push_back('%');
133+
encoded.push_back(hex[c >> 4]);
134+
encoded.push_back(hex[c & 0x0F]);
135+
}
136+
}
137+
return encoded;
138+
}
139+
140+
std::string fileUrlForPath(const std::filesystem::path& path)
141+
{
142+
std::error_code ec;
143+
const std::filesystem::path absolute = std::filesystem::absolute(path, ec);
144+
const std::string generic = (ec || absolute.empty()) ? path.generic_string() : absolute.generic_string();
145+
std::string url = "file://";
146+
#ifdef _WIN32
147+
url.push_back('/');
148+
#endif
149+
url += percentEncodeUrl(generic);
150+
return url;
151+
}
152+
153+
bool openUrl(std::string_view url)
154+
{
155+
const std::string url_string(url);
156+
if (SDL_OpenURL(url_string.c_str()) != 0) {
157+
Helpers::warn("Failed to open URL %s: %s", url_string.c_str(), SDL_GetError());
158+
return false;
159+
}
160+
return true;
161+
}
162+
163+
bool openPathInBrowser(const std::filesystem::path& path)
164+
{
165+
return openUrl(fileUrlForPath(path));
166+
}
167+
116168
const char* windowIconFilename(FrontendSettings::WindowIcon icon)
117169
{
118170
switch (icon) {
@@ -1332,6 +1384,8 @@ bool PandaFsuiAdapter::initialize(const fsui::FontStack& fonts)
13321384
};
13331385
fsuiContext.host.detect_prompt_icon_pack = []() { return fsui::DetectPromptIconPackFromSDL(); };
13341386
fsuiContext.host.detect_swap_north_west_gamepad_buttons = []() { return false; };
1387+
fsuiContext.host.open_file_browser = [this](const std::filesystem::path& path) { openPathInBrowser(path); };
1388+
fsuiContext.host.open_url = [](std::string_view url) { openUrl(url); };
13351389
fsuiContext.host.runtime_overlay_options = fsui::RuntimeOverlayOptions{
13361390
.show_inputs = true,
13371391
.show_settings = true,

third_party/fsui

Submodule fsui updated from 31ca34f to 199f742

0 commit comments

Comments
 (0)