From e3e99c6a48733f8a47f8a5c69864954a5ddbcb1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blak?= Date: Wed, 4 Jan 2023 17:05:07 +0100 Subject: [PATCH] feat(general): Initial setup for app monitoring tool Closes: #8786 --- Makefile | 6 ++++ monitoring/HotComponentFromSource.qml | 44 +++++++++++++++++++++++++++ monitoring/HotLoader.qml | 13 ++++++++ monitoring/Main.qml | 35 +++++++++++++++++++++ monitoring/MonitorEntryPoint.qml | 40 ++++++++++++++++++++++++ ui/nim-status-client.pro | 2 ++ vendor/DOtherSide | 2 +- 7 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 monitoring/HotComponentFromSource.qml create mode 100644 monitoring/HotLoader.qml create mode 100644 monitoring/Main.qml create mode 100644 monitoring/MonitorEntryPoint.qml diff --git a/Makefile b/Makefile index bebca928d..7bc952080 100644 --- a/Makefile +++ b/Makefile @@ -147,6 +147,12 @@ else DOTHERSIDE_BUILD_CMD := cmake --build . --config Release $(HANDLE_OUTPUT) endif +MONITORING ?= false +ifneq ($(MONITORING), false) + DOTHERSIDE_CMAKE_PARAMS := ${DOTHERSIDE_CMAKE_PARAMS} -DMONITORING:BOOL=ON -DMONITORING_QML_ENTRY_POINT:STRING="/../monitoring/Main.qml" +endif + + # Qt5 dirs (we can't indent with tabs here) ifneq ($(detected_OS),Windows) QT5_LIBDIR := $(shell qmake -query QT_INSTALL_LIBS 2>/dev/null) diff --git a/monitoring/HotComponentFromSource.qml b/monitoring/HotComponentFromSource.qml new file mode 100644 index 000000000..80a472e0d --- /dev/null +++ b/monitoring/HotComponentFromSource.qml @@ -0,0 +1,44 @@ +import QtQuick 2.14 + +QtObject { + id: root + + property string source + property bool rethrowErrors: true + readonly property alias component: d.component + readonly property alias errors: d.errors // QQmlError + + onSourceChanged: d.createComponent() + + readonly property QtObject _d: QtObject { + id: d + + property Component component + property var errors: null + + function createComponent() { + if (component) { + component.destroy() + component = null + } + + try { + component = Qt.createQmlObject(root.source, + this, + "HotComponentFromSource_dynamicSnippet" + ) + d.errors = null + } catch (e) { + d.errors = e + + if (root.rethrowErrors) + throw e + } + } + } + + Component.onCompleted: { + if (root.source) + d.createComponent() + } +} diff --git a/monitoring/HotLoader.qml b/monitoring/HotLoader.qml new file mode 100644 index 000000000..557eabde0 --- /dev/null +++ b/monitoring/HotLoader.qml @@ -0,0 +1,13 @@ +import QtQuick 2.14 + +Loader { + sourceComponent: hotComponent.component + + property alias source: hotComponent.source + property alias rethrowErrors: hotComponent.rethrowErrors + readonly property alias errors: hotComponent.errors + + HotComponentFromSource { + id: hotComponent + } +} diff --git a/monitoring/Main.qml b/monitoring/Main.qml new file mode 100644 index 000000000..e24ca774b --- /dev/null +++ b/monitoring/Main.qml @@ -0,0 +1,35 @@ +import QtQuick 2.14 +import QtQuick.Controls 2.14 + +ApplicationWindow { + id: monitorRoot + + width: 800 + height: 600 + + visible: true + title: "Status Monitor" + + Timer { + interval: 1000 + running: true + repeat: true + + onTriggered: { + const xhr = new XMLHttpRequest() + xhr.open("GET", "MonitorEntryPoint.qml", false) + xhr.send() + + const content = xhr.responseText + + if (loader.source != content) + loader.source = content + } + } + + HotLoader { + id: loader + + anchors.fill: parent + } +} diff --git a/monitoring/MonitorEntryPoint.qml b/monitoring/MonitorEntryPoint.qml new file mode 100644 index 000000000..4159f65f3 --- /dev/null +++ b/monitoring/MonitorEntryPoint.qml @@ -0,0 +1,40 @@ +import QtQuick 2.14 +import QtQuick.Controls 2.14 +import QtQuick.Layouts 1.14 + +import Monitoring 1.0 + + +Component { + ColumnLayout { + anchors.fill: parent + anchors.margins: 10 + + spacing: 15 + + Label { + Layout.fillWidth: true + + text: "Context properties:" + font.bold: true + } + + ListView { + id: lv + + Layout.fillWidth: true + Layout.fillHeight: true + + clip: true + + + model: Monitor.contexPropertiesNames + + spacing: 5 + + delegate: Text { + text: modelData + } + } + } +} diff --git a/ui/nim-status-client.pro b/ui/nim-status-client.pro index a6a53490e..90dde7f91 100644 --- a/ui/nim-status-client.pro +++ b/ui/nim-status-client.pro @@ -16,6 +16,7 @@ lupdate_only{ SOURCES += $$files("$$PWD/*qmldir", true) SOURCES += $$files("$$PWD/*.qml", true) SOURCES += $$files("$$PWD/*.js", true) +SOURCES += $$files("$$PWD/../monitoring/*.qml", true) } # Other *.ts files will be provided by Lokalise platform @@ -28,6 +29,7 @@ OTHER_FILES += $$files("$$PWD/*qmldir", true) OTHER_FILES += $$files("$$PWD/*.qml", true) OTHER_FILES += $$files("$$PWD/*.js", true) OTHER_FILES += $$files("$$PWD/../src/*.nim", true) +OTHER_FILES += $$files("$$PWD/../monitoring/*.qml", true) # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = $$PWD/imports \ diff --git a/vendor/DOtherSide b/vendor/DOtherSide index 742a139b0..7f2dd4383 160000 --- a/vendor/DOtherSide +++ b/vendor/DOtherSide @@ -1 +1 @@ -Subproject commit 742a139b07338f23390b5d6ee84924424bbc8974 +Subproject commit 7f2dd438325925ae3db073e19eec63a49253e735