diff --git a/src/project/internal/saveprojectscenario.cpp b/src/project/internal/saveprojectscenario.cpp index 19b4377..ef3aa01 100644 --- a/src/project/internal/saveprojectscenario.cpp +++ b/src/project/internal/saveprojectscenario.cpp @@ -22,6 +22,10 @@ #include "saveprojectscenario.h" +#ifdef Q_OS_WASM +#include +#endif + #include #include #include @@ -167,6 +171,26 @@ Promise SaveProjectScenario::saveProject(SaveMode saveMode, SaveLocationTyp return resolvedPromise(make_ret(Err::NoProjectError)); } +#ifdef Q_OS_WASM + //! NOTE Compose (web build): there are no save dialogs and no cloud in the browser. + //! If the page handles saving (Module.onSaveRequested), hand File > Save / Ctrl+S to it; + //! otherwise write to the in-memory project file without asking (no "cloud or computer?" prompt), + //! and the page gets the bytes through onProjectSaved. + if (saveMode != SaveMode::SaveSelection) { + emscripten::val handler = emscripten::val::module_property("onSaveRequested"); + if (!handler.isUndefined() && !handler.isNull()) { + handler(); + return resolvedPromise(muse::make_ok()); + } + + muse::io::path_t webPath = project->path(); + if (muse::io::suffix(webPath) != mu::engraving::MSCZ) { + webPath = muse::io::path_t("/mu/temp/") + muse::io::completeBasename(webPath) + "." + mu::engraving::MSCZ; + } + return saveProjectAt(SaveLocation(SaveLocationType::Local, webPath), SaveMode::Save, force); + } +#endif + const bool isExistingSave = saveMode == SaveMode::Save && !project->isNewlyCreated(); const bool wantNewCloudSave = saveLocationType == SaveLocationType::Cloud && !project->isCloudProject(); if (isExistingSave && !wantNewCloudSave) {