diff --git a/CMakeLists.txt b/CMakeLists.txt index 93382c8..2690e47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,12 @@ elseif(EMSCRIPTEN) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIMGUI_DISABLE_FILE_FUNCTIONS") set_target_properties(raven PROPERTIES SUFFIX .html) target_link_libraries(raven PUBLIC ${LIBS}) + # Make sure the shell file is rebuilt when the HTML file changes. + set_property( + TARGET raven + PROPERTY LINK_DEPENDS + ${CMAKE_CURRENT_LIST_DIR}/shell_minimal.html + ) else() target_sources(raven PUBLIC main_glfw.cpp) endif() diff --git a/app.cpp b/app.cpp index af0ca6b..649a7aa 100644 --- a/app.cpp +++ b/app.cpp @@ -15,6 +15,8 @@ #ifndef EMSCRIPTEN #include "nfd.h" +#else +#include #endif #include "mz.h" @@ -759,6 +761,13 @@ void SaveTheme() { std::string OpenFileDialog() { #ifdef EMSCRIPTEN + // https://stackoverflow.com/a/69935189 + EM_ASM( + var file_selector = document.createElement('input'); + file_selector.setAttribute('type', 'file'); + file_selector.setAttribute('onchange','Module.LoadStringFromEvent(event)'); + file_selector.click(); + ); return ""; #else nfdchar_t* outPath = NULL; @@ -803,11 +812,13 @@ void DrawMenu() { if (path != "") LoadFile(path); } +#ifndef EMSCRIPTEN if (ImGui::MenuItem("Save As...")) { auto path = SaveFileDialog(); if (path != "") SaveFile(path); } +#endif if (ImGui::MenuItem("Revert")) { LoadFile(appState.file_path); } diff --git a/shell_minimal.html b/shell_minimal.html index d45b812..72ca4a5 100644 --- a/shell_minimal.html +++ b/shell_minimal.html @@ -4,6 +4,7 @@ Raven +