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>
#endif
#ifdef DISTRHO_OS_WASM
# include <emscripten/emscripten.h>
#endif
const std::string CARDINAL_VERSION = "22.06";
namespace rack {
@ -268,6 +272,17 @@ void saveAsDialogUncompressed()
#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,

View file

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

View file

@ -572,11 +572,11 @@ struct HelpButton : MenuButton {
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
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", "", [=]() {
system::openBrowser("https://github.com/DISTRHO/Cardinal/");
patchUtils::openBrowser("https://github.com/DISTRHO/Cardinal/");
}));
menu->addChild(new ui::MenuSeparator);

View file

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