Skip to content

Commit

Permalink
Disable various features on WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
mortbopet committed Sep 26, 2023
1 parent 6fbe356 commit 1530917
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/edittab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "processorhandler.h"
#include "ripessettings.h"
#include "symbolnavigator.h"
#include "wasmSupport.h"

namespace Ripes {

Expand Down Expand Up @@ -87,6 +88,8 @@ EditTab::EditTab(QToolBar *toolbar, QWidget *parent)
&EditTab::sourceTypeChanged);
connect(m_ui->setCInput, &QRadioButton::toggled, m_buildAction,
&QAction::setEnabled);
// C compiler is not yet supported on WASM.
disableIfWasm(m_ui->setCInput);

// Ensure that changes to the current compiler path will disable C input, if
// the compiler is invalid
Expand Down
10 changes: 6 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "syscall/syscallviewer.h"
#include "syscall/systemio.h"
#include "version/version.h"
#include "wasmSupport.h"

#include "fancytabbar/fancytabbar.h"

Expand Down Expand Up @@ -204,7 +205,6 @@ void MainWindow::setupMenus() {
connect(loadAction, &QAction::triggered, this,
[=] { this->loadFileTriggered(); });
m_ui->menuFile->addAction(loadAction);

m_ui->menuFile->addSeparator();

auto *examplesMenu = m_ui->menuFile->addMenu("Load Example...");
Expand All @@ -231,7 +231,6 @@ void MainWindow::setupMenus() {
&EditTab::editorStateChanged, saveAction,
[saveAsAction](bool enabled) { saveAsAction->setEnabled(enabled); });
m_ui->menuFile->addAction(saveAsAction);

m_ui->menuFile->addSeparator();

const QIcon exitIcon = QIcon(":/icons/cancel.svg");
Expand All @@ -246,6 +245,9 @@ void MainWindow::setupMenus() {
m_ui->menuView->addAction(
static_cast<ProcessorTab *>(m_tabWidgets.at(ProcessorTabID).tab)
->m_displayValuesAction);

// File I/O is not yet supported on WASM due to sandboxing.
disableIfWasm(QList{loadAction, saveAction, saveAsAction, exitAction});
}

MainWindow::~MainWindow() { delete m_ui; }
Expand Down Expand Up @@ -360,8 +362,8 @@ void MainWindow::loadFileTriggered() {
}

void MainWindow::wiki() {
QDesktopServices::openUrl(
QUrl(QString("https://github.com/mortbopet/Ripes/blob/master/docs/README.md")));
QDesktopServices::openUrl(QUrl(QString(
"https://github.com/mortbopet/Ripes/blob/master/docs/README.md")));
}

void MainWindow::version() {
Expand Down
6 changes: 5 additions & 1 deletion src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "utilities/hexspinbox.h"
#include "utilities/scrolleventfilter.h"
#include "wasmSupport.h"

namespace Ripes {

Expand Down Expand Up @@ -148,7 +149,10 @@ SettingsDialog::SettingsDialog(QWidget *parent)
// Create settings pages
addPage("Environment", createEnvironmentPage());
addPage("Simulator", createSimulatorPage());
addPage("Compiler", createCompilerPage());
auto *compilerPage = createCompilerPage();
addPage("Compiler", compilerPage);
// No C compiler support (yet) for wasm.
disableIfWasm(compilerPage);
addPage("Editor", createEditorPage());

m_ui->settingsList->setCurrentRow(
Expand Down
22 changes: 22 additions & 0 deletions src/wasmSupport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <QWidget>

namespace Ripes {

// Disable a widget if we are running in a wasm environment.
template <typename T>
inline void disableIfWasm(T *widget) {
#ifdef __EMSCRIPTEN__
widget->setEnabled(false);
#endif
}

// Disables a list of widgets if we are running in a wasm environment.
template <typename TList>
inline void disableIfWasm(TList widgets) {
for (auto *widget : widgets)
disableIfWasm(widget);
}

} // namespace Ripes

0 comments on commit 1530917

Please sign in to comment.