Skip to content

Commit

Permalink
prolinux-tool mobile form
Browse files Browse the repository at this point in the history
  • Loading branch information
Seshpenguin committed Nov 1, 2023
1 parent e952a24 commit 187a38b
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 38 deletions.
2 changes: 1 addition & 1 deletion ocs2-prolinuxd
Submodule ocs2-prolinuxd updated 1 files
+1 −1 src/index.ts
6 changes: 4 additions & 2 deletions prolinux-tool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ def set_wsapp(self, wsapp):
self.wsapp = wsapp

ws_msg = Signal(dict)
@Slot(str)
@Slot(dict)
def ws_send(self, message):
print("Sending Message:")
self.wsapp.ws_send(message)
msg = json.dumps(message)
print(msg)
self.wsapp.ws_send(msg)


class WebsocketWorker(QRunnable):
Expand Down
202 changes: 167 additions & 35 deletions prolinux-tool/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import QtQuick
import QtQuick.Controls as Controls
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard 1.0 as FormCard
import org.kde.kirigamiaddons.components 1.0 as Components

// Provides basic features needed for all kirigami applications
Kirigami.ApplicationWindow {
Expand All @@ -14,37 +16,63 @@ Kirigami.ApplicationWindow {
// and provides additional context for the translators
title: "ProLinux Tool"

function handleStatus(msg) {
configOpts.description = `Status: ${msg.payload.data.status}
Cloud Connected: ${msg.payload.data.ocsConnnected}
Cloud Ready: ${msg.payload.data.ocsReady}
Selected Root: ${msg.payload.data.selectedRoot}
Locked Root: ${msg.payload.data.lockedRoot}
Disable Kexec: ${msg.payload.data.disableKexec}
Hostname: ${msg.payload.data.hostname}`
version.description = msg.payload.data.buildInfo.product + " " + msg.payload.data.buildInfo.variant + " " + msg.payload.data.buildInfo.channel
buildStr.description = msg.payload.data.buildInfo.buildnum + "-" + msg.payload.data.buildInfo.uuid + " (" + msg.payload.data.buildInfo.builddate + ")"

// config
configRootLock.checked = msg.payload.data.lockedRoot
configDisableKexec.checked = msg.payload.data.disableKexec ?? false

configHostname.description = msg.payload.data.hostname
hostnamePromptDialogTextField.text = msg.payload.data.hostname

showPassiveNotification("Refreshed")
}

function handleWSMessage(msg) {
console.log(JSON.stringify(msg))
console.log(JSON.stringify(msg));
/* {"action":"result","payload":{"forAction":"status","status":true,"data":{"status":"ok","ocsConnnected":false,"ocsReady":false,"modules":["pl2"],"selectedRoot":"a","lockedRoot":true,"hostname":""},"config":{"prolinuxd":{"modules":["pl2"]},"ocs2":{"gateway_url":"wss://update.sineware.ca/gateway","client_type":"prolinux,plasma-mobile-nightly","access_token":""},"pl2":{"selected_root":"a","locked_root":true,"hostname":""}}},"id":1}*/

configOpts.text = "System Configuration: " + `
Status: ${msg.payload.data.status}
Cloud Connected: ${msg.payload.data.ocsConnnected}
Cloud Ready: ${msg.payload.data.ocsReady}
Selected Root: ${msg.payload.data.selectedRoot}
Locked Root: ${msg.payload.data.lockedRoot}
Hostname: ${msg.payload.data.hostname}
`
version.text = "Version: " + msg.payload.data.buildInfo.product + " " + msg.payload.data.buildInfo.variant + " " + msg.payload.data.buildInfo.channel
buildStr.text = "Build String: " + msg.payload.data.buildInfo.buildnum + "-" + msg.payload.data.buildInfo.uuid + " (" + msg.payload.data.buildInfo.builddate + ")"
}
Timer {
id: timer
function setTimeout(cb, delayTime) {
timer.interval = delayTime;
timer.repeat = false;
timer.triggered.connect(cb);
timer.triggered.connect(function release () {
timer.triggered.disconnect(cb);
timer.triggered.disconnect(release);
});
timer.start();
switch(msg.action) {
case "result":
if(msg.payload.status != true) {
console.log("Error: " + msg.payload.data)
showPassiveNotification("Error: " + msg.payload.data);
return;
}
switch(msg.payload.forAction) {
case "status":
handleStatus(msg);
break;
case "set-locked-root":
showPassiveNotification("Root Lock Set")
break;
case "set-disable-kexec":
showPassiveNotification("Disable Kexec Set");
break;
case "set-hostname":
showPassiveNotification("Hostname Set");
break;
default:
console.log("Unknown result action: " + msg.payload.forAction);
showPassiveNotification("Unknown result action: " + msg.payload.forAction);
}
break;
default:
console.log("Unknown action: " + msg.action);
showPassiveNotification("Unknown action: " + msg.action);
}
}

Component.onCompleted: {
wsapp.ws_send('{ "action": "status", "payload": {}, "id": 1}')
wsapp.ws_send({ "action": "status", "payload": {}, "id": 1})
}

globalDrawer: Kirigami.GlobalDrawer {
Expand All @@ -61,28 +89,132 @@ Kirigami.ApplicationWindow {

// Set the first page that will be loaded when the app opens
// This can also be set to an id of a KirigamiPage
pageStack.initialPage: Kirigami.Page {
pageStack.initialPage: Kirigami.ScrollablePage {
actions: [Kirigami.Action {
text: "Refresh"
icon.name: "view-refresh"
onTriggered: {
console.log("Refresh")
wsapp.ws_send('{ "action": "status", "payload": {}, "id": 1}')
wsapp.ws_send({ "action": "status", "payload": {}, "id": 1})

}
}]
topPadding: Kirigami.Units.gridUnit
leftPadding: 0
rightPadding: 0
bottomPadding: Kirigami.Units.gridUnit

Kirigami.PromptDialog {
id: hostnamePromptDialog
title: "System Hostname"

standardButtons: Kirigami.Dialog.NoButton
customFooterActions: [
Kirigami.Action {
text: "Set Hostname"
icon.name: "dialog-ok"
onTriggered: {
console.log("Set Hostname: " + hostnamePromptDialogTextField.text)
wsapp.ws_send({
action: "set-hostname",
payload: {
hostname: hostnamePromptDialogTextField.text
},
id: 1
})
hostnamePromptDialog.close();
}
},
Kirigami.Action {
text: "Cancel"
icon.name: "dialog-cancel"
onTriggered: {
hostnamePromptDialog.close();
}
}
]

Controls.TextField {
id: hostnamePromptDialogTextField
placeholderText: "Hostname"
}
}

ColumnLayout {
RowLayout {
id: grid
Text { text: "ProLinux System Overview"; font.bold: true; }
FormCard.FormHeader {
title: "ProLinux System Overview"
}
RowLayout {
Text { id: configOpts; text: "System Configuration: xx"; font.bold: true; }
FormCard.FormCard {
FormCard.FormTextDelegate {
id: configOpts
text: "System Configuration"
description: ""
}

FormCard.FormDelegateSeparator {}

FormCard.FormTextDelegate {
id: version
text: "Version"
description: ""
}

FormCard.FormDelegateSeparator {}

FormCard.FormTextDelegate {
id: buildStr
text: "Build String"
description: ""
}
}
RowLayout {
Text { id: version; text: "Version: xx"; font.bold: true; }
Text { id: buildStr; text: "Build String: xx"; font.bold: true; }

FormCard.FormHeader {
title: "System Configuration"
}
FormCard.FormCard {
FormCard.FormSwitchDelegate {
id: configRootLock
text: "Root Lock"
description: "Enables the read-only root lock overlay."
onCheckedChanged: {
console.log("Root Lock: " + configRootLock.checked)
wsapp.ws_send({
action: "set-locked-root",
payload: {
lockedRoot: configRootLock.checked
},
id: 1
})
}
}
FormCard.FormDelegateSeparator {}

FormCard.FormSwitchDelegate {
id: configDisableKexec
text: "Disable Kexec"
description: "When enabled, Kexec-based boot mechanism is bypassed.\nFor advanced uses only, this will break your system!"
onCheckedChanged: {
console.log("Disable Kexec: " + configDisableKexec.checked)
wsapp.ws_send({
action: "set-disable-kexec",
payload: {
disableKexec: configDisableKexec.checked
},
id: 1
})
}
}
FormCard.FormDelegateSeparator {}

FormCard.FormButtonDelegate {
id: configHostname
text: "Hostname"
description: ""
onClicked: hostnamePromptDialog.open()
}
}

}

}
}

0 comments on commit 187a38b

Please sign in to comment.