diff options
| author | Nippy <nippy@rp1.hu> | 2026-05-08 19:50:49 +0200 |
|---|---|---|
| committer | Nippy <nippy@rp1.hu> | 2026-05-08 19:50:49 +0200 |
| commit | 3462bcc46ecf74f576ea4397f16492c16bd75b10 (patch) | |
| tree | c5ab7aef4498647e057bda8d49c11e5f9dda74c9 /raveos-hyprland-theme/theme-data/dms/Common/DankSocket.qml | |
| parent | 56616f693b4f263cbf0d47da43b67424efa6022d (diff) | |
| download | RaveOS-PKGBUILD-3462bcc46ecf74f576ea4397f16492c16bd75b10.tar.gz RaveOS-PKGBUILD-3462bcc46ecf74f576ea4397f16492c16bd75b10.zip | |
raveos update
Diffstat (limited to 'raveos-hyprland-theme/theme-data/dms/Common/DankSocket.qml')
| -rw-r--r-- | raveos-hyprland-theme/theme-data/dms/Common/DankSocket.qml | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/raveos-hyprland-theme/theme-data/dms/Common/DankSocket.qml b/raveos-hyprland-theme/theme-data/dms/Common/DankSocket.qml new file mode 100644 index 0000000..93471ba --- /dev/null +++ b/raveos-hyprland-theme/theme-data/dms/Common/DankSocket.qml @@ -0,0 +1,62 @@ +import QtQuick +import Quickshell.Io + +Item { + id: root + + property alias path: socket.path + property alias parser: socket.parser + property bool connected: false + + property int reconnectBaseMs: 400 + property int reconnectMaxMs: 15000 + + property int _reconnectAttempt: 0 + + signal connectionStateChanged() + + onConnectedChanged: { + socket.connected = connected + } + + Socket { + id: socket + + onConnectionStateChanged: { + root.connectionStateChanged() + if (connected) { + root._reconnectAttempt = 0 + return + } + if (root.connected) { + root._scheduleReconnect() + } + } + } + + Timer { + id: reconnectTimer + interval: 0 + repeat: false + onTriggered: { + socket.connected = false + Qt.callLater(() => socket.connected = true) + } + } + + function send(data) { + const json = typeof data === "string" ? data : JSON.stringify(data) + const message = json.endsWith("\n") ? json : json + "\n" + socket.write(message) + socket.flush() + } + + function _scheduleReconnect() { + const pow = Math.min(_reconnectAttempt, 10) + const base = Math.min(reconnectBaseMs * Math.pow(2, pow), reconnectMaxMs) + const jitter = Math.floor(Math.random() * Math.floor(base / 4)) + reconnectTimer.interval = base + jitter + reconnectTimer.restart() + _reconnectAttempt++ + } +} |