Skip to content

Commit

Permalink
Only hit the watchdog when BackendConnection.state === BackendConnect…
Browse files Browse the repository at this point in the history
…ion.Ready
  • Loading branch information
DanielMcInnes committed Dec 18, 2024
1 parent dda7a38 commit b7ac5e9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
8 changes: 8 additions & 0 deletions ApplicationContent.qml
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,12 @@ Item {
? "qrc:/qt/qml/Victron/VenusOS/components/InputPanel.qml"
: "qrc:/qt/qml/Victron/VenusOS/components/WasmVirtualKeyboardHandler.qml"
}

// Sometimes, the wasm code may crash. Use a watchdog to detect this and reload the page when necessary.
Timer {
running: Qt.platform.os === "wasm" && BackendConnection.state === BackendConnection.Ready
repeat: true
interval: 1000
onTriggered: BackendConnection.hitWatchdog()
}
}
14 changes: 5 additions & 9 deletions src/backendconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,6 @@ void BackendConnection::onReloadPageTimerExpired()
reloadPage();
}

// Sometimes, the wasm code may crash. Use a watchdog to detect this and reload the page when necessary.
void BackendConnection::onWatchdogTimerExpired()
{
emscripten_run_script("watchdogHit = true"); // 'watchdogHit' is defined in venus-gui-v2.html, which checks it periodically and reloads the page if not hit regularly.
}

// If the wasm itself changed the Security Profile, it should normally be notified
// that it is accepted by receiving a Network Config change. Since that event is send
// over a connection which is going to be disconnected, this acts as a fallback if
Expand Down Expand Up @@ -228,6 +222,11 @@ void BackendConnection::openUrl(const QString &url)
emscripten_run_script(ba.constData());
}

void BackendConnection::hitWatchdog()
{
emscripten_run_script("watchdogHit = true"); // 'watchdogHit' is defined in venus-gui-v2.html, which checks it periodically and reloads the page if not hit regularly.
}

#else

void BackendConnection::onNetworkConfigChanged(const QVariant var) { Q_UNUSED(var); }
Expand Down Expand Up @@ -278,9 +277,6 @@ void BackendConnection::initMqttConnection(const QString &address)

VeQItem *item = mqttProducer->services()->itemGetOrCreate("/platform/0/Network/ConfigChanged");
connect(item, &VeQItem::valueChanged, this, &BackendConnection::onNetworkConfigChanged);

connect(&mWatchdogTimer, &QTimer::timeout, this, &BackendConnection::onWatchdogTimerExpired);
mWatchdogTimer.start(1000);
#else
const QStringList parts = address.split(':');
if (parts.size() >= 2) {
Expand Down
10 changes: 3 additions & 7 deletions src/backendconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ class BackendConnection : public QObject
// Move this to some mock data manager when available
Q_INVOKABLE void setMockValue(const QString &uid, const QVariant &value);
Q_INVOKABLE QVariant mockValue(const QString &uid) const;
#if defined(VENUS_WEBASSEMBLY_BUILD)
Q_INVOKABLE void hitWatchdog();
#endif

Q_SIGNALS:
void stateChanged();
Expand All @@ -157,9 +160,6 @@ class BackendConnection : public QObject
private Q_SLOTS:
void onNetworkConfigChanged(const QVariant var);
void onReloadPageTimerExpired();
#if defined(VENUS_WEBASSEMBLY_BUILD)
void onWatchdogTimerExpired();
#endif

private:
explicit BackendConnection(QObject *parent = nullptr);
Expand Down Expand Up @@ -198,10 +198,6 @@ private Q_SLOTS:
AlarmBusitem *m_alarmBusItem = nullptr;
#endif
QNetworkAccessManager *m_network = nullptr;

#if defined(VENUS_WEBASSEMBLY_BUILD)
QTimer mWatchdogTimer;
#endif
};

class BackendConnectionTester : public QObject
Expand Down

0 comments on commit b7ac5e9

Please sign in to comment.