From ac5f0c0923eb6714d1a1db15beae1f8c7da22fb3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 22 Jun 2026 12:16:06 +0200 Subject: [PATCH] Stop node on leave --- src/qml/BlockchainView.qml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/qml/BlockchainView.qml b/src/qml/BlockchainView.qml index d2219b9..0cf7213 100644 --- a/src/qml/BlockchainView.qml +++ b/src/qml/BlockchainView.qml @@ -1,6 +1,7 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts +import QtQuick.Window import Logos.Theme import Logos.Controls @@ -35,6 +36,41 @@ Rectangle { root.ready = root.backend !== null && logos.isViewModuleReady("blockchain_ui") } + // Graceful shutdown: if the window is closed while the node is running, + // veto the close, stop the node, then close once it has stopped. + property bool quitting: false + + function _nodeBusy() { + return root.backend + && (root.backend.status === BlockchainBackend.Running + || root.backend.status === BlockchainBackend.Starting + || root.backend.status === BlockchainBackend.Stopping) + } + + Connections { + target: root.Window.window + enabled: root.Window.window !== null + ignoreUnknownSignals: true + function onClosing(close) { + if (!root.quitting && root._nodeBusy()) { + root.quitting = true + close.accepted = false + root.backend.stopBlockchain() + } + } + } + + // Once the stop initiated above completes, finish closing the window. + Connections { + target: root.backend + enabled: root.quitting && root.backend !== null + ignoreUnknownSignals: true + function onStatusChanged() { + if (root.quitting && !root._nodeBusy() && root.Window.window) + root.Window.window.close() + } + } + // Models live on the C++ backend and are auto-remoted by ui-host as // "/". QML acquires them via logos.model(...). readonly property var accountsModel: logos.model("blockchain_ui", "accounts")