Implement openBrowser for wasm

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2022-07-05 16:45:02 +01:00
parent c14eee850b
commit 74b41e1713
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
5 changed files with 28 additions and 10 deletions

View file

@ -52,6 +52,10 @@
# include <unistd.h> # include <unistd.h>
#endif #endif
#ifdef DISTRHO_OS_WASM
# include <emscripten/emscripten.h>
#endif
const std::string CARDINAL_VERSION = "22.06"; const std::string CARDINAL_VERSION = "22.06";
namespace rack { namespace rack {
@ -268,6 +272,17 @@ void saveAsDialogUncompressed()
#endif #endif
} }
void openBrowser(const std::string& url)
{
#ifdef DISTRHO_OS_WASM
EM_ASM({
window.open(UTF8ToString($0), '_blank');
}, url.c_str());
#else
patchUtils::openBrowser(url);
#endif
}
} }
void async_dialog_filebrowser(const bool saving, void async_dialog_filebrowser(const bool saving,

View file

@ -66,6 +66,7 @@ void saveDialog(const std::string& path);
void saveAsDialog(); void saveAsDialog();
void saveAsDialogUncompressed(); void saveAsDialogUncompressed();
void appendSelectionContextMenu(rack::ui::Menu* menu); void appendSelectionContextMenu(rack::ui::Menu* menu);
void openBrowser(const std::string& url);
bool connectToRemote(); bool connectToRemote();
bool isRemoteConnected(); bool isRemoteConnected();

View file

@ -572,11 +572,11 @@ struct HelpButton : MenuButton {
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
menu->addChild(createMenuItem("Rack User manual", "F1", [=]() { menu->addChild(createMenuItem("Rack User manual", "F1", [=]() {
system::openBrowser("https://vcvrack.com/manual"); patchUtils::openBrowser("https://vcvrack.com/manual");
})); }));
menu->addChild(createMenuItem("Cardinal Project page", "", [=]() { menu->addChild(createMenuItem("Cardinal Project page", "", [=]() {
system::openBrowser("https://github.com/DISTRHO/Cardinal/"); patchUtils::openBrowser("https://github.com/DISTRHO/Cardinal/");
})); }));
menu->addChild(new ui::MenuSeparator); menu->addChild(new ui::MenuSeparator);

View file

@ -38,6 +38,8 @@
#include <ui/MenuSeparator.hpp> #include <ui/MenuSeparator.hpp>
#include <helpers.hpp> #include <helpers.hpp>
#include "../CardinalCommon.hpp"
namespace rack { namespace rack {
namespace plugin { namespace plugin {
@ -120,7 +122,7 @@ std::string Model::getManualUrl() {
void Model::appendContextMenu(ui::Menu* menu, bool inBrowser) { void Model::appendContextMenu(ui::Menu* menu, bool inBrowser) {
// plugin // plugin
menu->addChild(createMenuItem("Plugin: " + plugin->name, "", [=]() { menu->addChild(createMenuItem("Plugin: " + plugin->name, "", [=]() {
system::openBrowser(plugin->pluginUrl); patchUtils::openBrowser(plugin->pluginUrl);
}, plugin->pluginUrl == "")); }, plugin->pluginUrl == ""));
// version // version
@ -129,7 +131,7 @@ void Model::appendContextMenu(ui::Menu* menu, bool inBrowser) {
// author // author
if (plugin->author != "") { if (plugin->author != "") {
menu->addChild(createMenuItem("Author: " + plugin->author, "", [=]() { menu->addChild(createMenuItem("Author: " + plugin->author, "", [=]() {
system::openBrowser(plugin->authorUrl); patchUtils::openBrowser(plugin->authorUrl);
}, plugin->authorUrl.empty())); }, plugin->authorUrl.empty()));
} }
@ -137,7 +139,7 @@ void Model::appendContextMenu(ui::Menu* menu, bool inBrowser) {
std::string license = plugin->license; std::string license = plugin->license;
if (string::startsWith(license, "https://") || string::startsWith(license, "http://")) { if (string::startsWith(license, "https://") || string::startsWith(license, "http://")) {
menu->addChild(createMenuItem("License: Open in browser", "", [=]() { menu->addChild(createMenuItem("License: Open in browser", "", [=]() {
system::openBrowser(license); patchUtils::openBrowser(license);
})); }));
} }
else if (license != "") { else if (license != "") {
@ -158,28 +160,28 @@ void Model::appendContextMenu(ui::Menu* menu, bool inBrowser) {
std::string manualUrl = getManualUrl(); std::string manualUrl = getManualUrl();
if (manualUrl != "") { if (manualUrl != "") {
menu->addChild(createMenuItem("User manual", RACK_MOD_CTRL_NAME "+F1", [=]() { menu->addChild(createMenuItem("User manual", RACK_MOD_CTRL_NAME "+F1", [=]() {
system::openBrowser(manualUrl); patchUtils::openBrowser(manualUrl);
})); }));
} }
// donate // donate
if (plugin->donateUrl != "") { if (plugin->donateUrl != "") {
menu->addChild(createMenuItem("Donate", "", [=]() { menu->addChild(createMenuItem("Donate", "", [=]() {
system::openBrowser(plugin->donateUrl); patchUtils::openBrowser(plugin->donateUrl);
})); }));
} }
// source code // source code
if (plugin->sourceUrl != "") { if (plugin->sourceUrl != "") {
menu->addChild(createMenuItem("Source code", "", [=]() { menu->addChild(createMenuItem("Source code", "", [=]() {
system::openBrowser(plugin->sourceUrl); patchUtils::openBrowser(plugin->sourceUrl);
})); }));
} }
// changelog // changelog
if (plugin->changelogUrl != "") { if (plugin->changelogUrl != "") {
menu->addChild(createMenuItem("Changelog", "", [=]() { menu->addChild(createMenuItem("Changelog", "", [=]() {
system::openBrowser(plugin->changelogUrl); patchUtils::openBrowser(plugin->changelogUrl);
})); }));
} }

View file

@ -342,7 +342,7 @@ void Scene::onHoverKey(const HoverKeyEvent& e) {
e.consume(this); e.consume(this);
} }
if (e.key == GLFW_KEY_F1 && (e.mods & RACK_MOD_MASK) == 0) { if (e.key == GLFW_KEY_F1 && (e.mods & RACK_MOD_MASK) == 0) {
system::openBrowser("https://vcvrack.com/manual/"); patchUtils::openBrowser("https://vcvrack.com/manual/");
e.consume(this); e.consume(this);
} }
if (e.key == GLFW_KEY_F3 && (e.mods & RACK_MOD_MASK) == 0) { if (e.key == GLFW_KEY_F3 && (e.mods & RACK_MOD_MASK) == 0) {