yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
file_dialog_web.cc
Go to the documentation of this file.
1#include "util/file_util.h"
2
3#include <string>
4#include <vector>
5
6#ifdef __EMSCRIPTEN__
7#include <emscripten.h>
8#endif
9
10namespace yaze {
11namespace util {
12
13// Web implementation of FileDialogWrapper
14// Triggers the existing file input element in the HTML
15
17 const FileDialogOptions& options) {
18 (void)options;
19 return ShowOpenFileDialog();
20}
21
23#ifdef __EMSCRIPTEN__
24 // Trigger the existing file input element
25 // The file input handler in app.js will handle the file selection
26 // and call LoadRomFromWeb, which will update the ROM
27 EM_ASM({
28 var romInput = document.getElementById('rom-input');
29 if (romInput) {
30 romInput.click();
31 }
32 });
33
34 // Return empty string - the actual loading happens asynchronously
35 // via the file input handler which calls LoadRomFromWeb
36 return "";
37#else
38 return "";
39#endif
40}
41
43 const FileDialogOptions& options,
44 std::function<void(const std::string&)> callback) {
45 if (!callback) {
46 return;
47 }
48 callback(ShowOpenFileDialog(options));
49}
50
52 // Folder picking not supported on web in the same way
53 return "";
54}
55
57 const std::string& default_name, const std::string& default_extension) {
58 // TODO(web): Implement download trigger via JS
59 return "";
60}
61
63 const std::string& folder_path) {
64 // Emscripten's VFS might support this if mounted
65 return {};
66}
67
68std::vector<std::string> FileDialogWrapper::GetFilesInFolder(
69 const std::string& folder_path) {
70 return {};
71}
72
73} // namespace util
74} // namespace yaze
static void ShowOpenFileDialogAsync(const FileDialogOptions &options, std::function< void(const std::string &)> callback)
static std::string ShowSaveFileDialog(const std::string &default_name="", const std::string &default_extension="")
ShowSaveFileDialog opens a save file dialog and returns the selected filepath. Uses global feature fl...
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath. Uses global feature flag to...
static std::string ShowOpenFolderDialog()
ShowOpenFolderDialog opens a file dialog and returns the selected folder path. Uses global feature fl...
static std::vector< std::string > GetFilesInFolder(const std::string &folder_path)
static std::vector< std::string > GetSubdirectoriesInFolder(const std::string &folder_path)