mirror of
https://github.com/oxen-io/lokinet-control-panel.git
synced 2023-12-14 05:53:00 +01:00
Add version (queried from daemon's RPC API)
This commit is contained in:
parent
4b44ec5aeb
commit
b47fcca04f
4 changed files with 81 additions and 1 deletions
|
@ -10,6 +10,7 @@ Container {
|
|||
id: connectionButtonPanel
|
||||
property var connected: false
|
||||
property var running: false
|
||||
property var version: ""
|
||||
|
||||
property color tint: null
|
||||
property bool hovering: false
|
||||
|
@ -21,7 +22,7 @@ Container {
|
|||
onRunningChanged: updateState();
|
||||
onHoveringChanged: updateState();
|
||||
|
||||
Layout.preferredHeight: 59
|
||||
Layout.preferredHeight: 129
|
||||
Layout.preferredWidth: Style.appWidth
|
||||
|
||||
contentItem: Rectangle {
|
||||
|
@ -30,6 +31,7 @@ Container {
|
|||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: statusTextGroup
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
spacing: 4
|
||||
|
@ -57,6 +59,35 @@ Container {
|
|||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: versionTextGroup
|
||||
anchors.left: parent.left
|
||||
anchors.top: statusTextGroup.bottom
|
||||
spacing: 4
|
||||
anchors.margins: 16
|
||||
|
||||
|
||||
// "version"
|
||||
Text {
|
||||
id: versionLabelText
|
||||
|
||||
text: "Version"
|
||||
font.family: Style.weakTextFont
|
||||
color: Style.weakTextColor
|
||||
font.pointSize: Style.weakTextSize
|
||||
font.capitalization: Font.AllUppercase
|
||||
}
|
||||
// version text
|
||||
Text {
|
||||
id: versionText
|
||||
|
||||
text: version
|
||||
font.family: Style.strongTextFont
|
||||
color: Style.strongTextColor
|
||||
font.pointSize: Style.strongTextSize
|
||||
}
|
||||
}
|
||||
|
||||
// tooltip
|
||||
ToolTip {
|
||||
id: statusTooltip
|
||||
|
|
|
@ -10,6 +10,7 @@ ColumnLayout {
|
|||
|
||||
property var isConnected: false
|
||||
property var isRunning: false
|
||||
property var lokiVersion: ""
|
||||
property var lokiAddress: ""
|
||||
property var numPathsBuilt: 0
|
||||
property var numRoutersKnown: 0
|
||||
|
@ -23,6 +24,7 @@ ColumnLayout {
|
|||
ConnectionButtonPanel {
|
||||
connected: isConnected
|
||||
running: isRunning
|
||||
version: lokiVersion
|
||||
}
|
||||
|
||||
// address panel
|
||||
|
@ -65,6 +67,21 @@ ColumnLayout {
|
|||
stateApiPoller.pollImmediately();
|
||||
stateApiPoller.setIntervalMs(3000);
|
||||
stateApiPoller.startPolling();
|
||||
|
||||
// query daemon version
|
||||
apiClient.llarpVersion(function(response, err) {
|
||||
if (err) {
|
||||
console.log("Received error when trying to wakeup lokinet daemon: ", err);
|
||||
} else {
|
||||
try {
|
||||
const msg = JSON.parse(response);
|
||||
lokiVersion = msg.result.version;
|
||||
} catch (err) {
|
||||
console.log("Couldn't pull version out of payload", err);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function handleStateResults(payload, error) {
|
||||
|
|
|
@ -25,3 +25,27 @@ bool LokinetApiClient::llarpAdminWakeup(QJSValue callback) {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
// LokinetApiClient::llarpVersion
|
||||
bool LokinetApiClient::llarpVersion(QJSValue callback) {
|
||||
|
||||
if (! callback.isUndefined() && ! callback.isCallable()) {
|
||||
qDebug() << "callback should be a function (if present)";
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string jsonRpcPayload = R"JSON({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "llarp.version",
|
||||
"params": {},
|
||||
"id": "empty"
|
||||
})JSON";
|
||||
m_httpClient.postJson("http://localhost:1190", jsonRpcPayload, [=](QNetworkReply* reply) mutable {
|
||||
QJSValueList args;
|
||||
args << QJSValue(reply->readAll().data());
|
||||
args << QJSValue(reply->error());
|
||||
callback.call(args);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,14 @@ public:
|
|||
* @return true if the asynchronous request could be made, false otherwise
|
||||
*/
|
||||
Q_INVOKABLE bool llarpAdminWakeup(QJSValue callback);
|
||||
|
||||
/**
|
||||
* Invoke the `llarp.version` endpoint.
|
||||
*
|
||||
* @param callback is an optional JS function to invoke on success
|
||||
* @return true if the asynchronous request could be made, false otherwise
|
||||
*/
|
||||
Q_INVOKABLE bool llarpVersion(QJSValue callback);
|
||||
|
||||
private:
|
||||
|
||||
|
|
Loading…
Reference in a new issue