swadhinbiswas Enable media/microphone/active-window, add Docker/Power/Wallpaper/SystemOverview plugins, deploy terminal/starship/nvim/opencode configs · 8/22/2026
ed1a3ac
339 lines · 9.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Quickshell
import Quickshell.Io
import qs.Commons
import qs.Ui

Item {
  id: root

  property var shell: null
  property var manifest: null
  property bool opened: false

  property string cpuUsage: "--"
  property string memUsage: "--"
  property string memTotal: "--"
  property string diskUsage: "--"
  property string gpuTemp: "--"
  property string netRx: "--"
  property string netTx: "--"
  property string uptime: "--"
  property string kernel: "--"
  property string hostname: "--"
  property string cpuModel: "--"
  property real prevCpuIdle: 0
  property real prevCpuTotal: 0

  function open(payloadJson) {
    opened = true
    refresh()
  }

  function close() {
    opened = false
  }

  function dismiss() {
    if (shell && typeof shell.hide === "function")
      shell.hide((manifest && manifest.id) || "deomarchy.system-overview")
    else close()
  }

  function refresh() {
    if (!cpuProc.running) cpuProc.running = true
    if (!memProc.running) memProc.running = true
    if (!diskProc.running) diskProc.running = true
    if (!tempProc.running) tempProc.running = true
    if (!netProc.running) netProc.running = true
    if (!uptimeProc.running) uptimeProc.running = true
    if (!infoProc.running) infoProc.running = true
  }

  function parseCpuLine(raw) {
    var line = String(raw || "").trim()
    var parts = line.split(/\s+/)
    if (parts.length < 5) return
    var idle = parseFloat(parts[3]) || 0
    var total = 0
    for (var i = 1; i < parts.length; i++) total += parseFloat(parts[i]) || 0
    if (prevCpuTotal > 0) {
      var dTotal = total - prevCpuTotal
      var dIdle = idle - prevCpuIdle
      if (dTotal > 0) cpuUsage = Math.round((1 - dIdle / dTotal) * 100) + "%"
    }
    prevCpuIdle = idle
    prevCpuTotal = total
  }

  function parseMem(raw) {
    var lines = String(raw || "").trim().split("\n")
    var total = 0
    var avail = 0
    for (var i = 0; i < lines.length; i++) {
      var parts = lines[i].trim().split(/\s+/)
      if (parts[0] === "MemTotal:") total = parseFloat(parts[1]) || 0
      if (parts[0] === "MemAvailable:") avail = parseFloat(parts[1]) || 0
    }
    if (total > 0) {
      memTotal = (total / 1048576).toFixed(1) + " GB"
      var used = total - avail
      memUsage = Math.round(used / total * 100) + "%"
    }
  }

  function parseDisk(raw) {
    var line = String(raw || "").trim()
    var parts = line.split(/\s+/)
    if (parts.length >= 5) diskUsage = parts[4] || "--"
  }

  function parseTemp(raw) {
    var line = String(raw || "").trim()
    var temp = parseFloat(line)
    if (isFinite(temp)) gpuTemp = Math.round(temp / 1000) + "\u00b0C"
    else gpuTemp = "--"
  }

  function parseNet(raw) {
    var lines = String(raw || "").trim().split("\n")
    var totalRx = 0
    var totalTx = 0
    for (var i = 1; i < lines.length; i++) {
      var parts = lines[i].trim().split(/[\s:]+/)
      if (parts.length < 10) continue
      var iface = parts[0]
      if (iface === "lo" || iface === "") continue
      totalRx += parseFloat(parts[1]) || 0
      totalTx += parseFloat(parts[9]) || 0
    }
    netRx = formatBytes(totalRx)
    netTx = formatBytes(totalTx)
  }

  function parseUptime(raw) {
    var sec = parseFloat(String(raw || "").trim())
    if (!isFinite(sec) || sec < 0) { uptime = "--"; return }
    var d = Math.floor(sec / 86400)
    var h = Math.floor((sec % 86400) / 3600)
    var m = Math.floor((sec % 3600) / 60)
    var parts = []
    if (d > 0) parts.push(d + "d")
    if (h > 0) parts.push(h + "h")
    parts.push(m + "m")
    uptime = parts.join(" ")
  }

  function parseInfo(raw) {
    var lines = String(raw || "").trim().split("\n")
    for (var i = 0; i < lines.length; i++) {
      var line = lines[i].trim()
      if (line.indexOf("hostname") === 0) hostname = line.split("=", 2)[1] || "--"
      if (line.indexOf("kernel") === 0) kernel = line.split("=", 2)[1] || "--"
      if (line.indexOf("model name") === 0) cpuModel = line.split(":", 2)[1] || "--"
    }
  }

  function formatBytes(b) {
    if (b < 1024) return Math.round(b) + " B"
    if (b < 1048576) return (b / 1024).toFixed(1) + " KB"
    if (b < 1073741824) return (b / 1048576).toFixed(1) + " MB"
    return (b / 1073741824).toFixed(2) + " GB"
  }

  Component.onCompleted: {
    refresh()
    kernelProc.running = true
  }

  Process {
    id: cpuProc
    command: ["bash", "-c", "head -1 /proc/stat"]
    stdout: StdioCollector {
      waitForEnd: true
      onStreamFinished: root.parseCpuLine(text)
    }
  }

  Process {
    id: memProc
    command: ["bash", "-c", "head -2 /proc/meminfo"]
    stdout: StdioCollector {
      waitForEnd: true
      onStreamFinished: root.parseMem(text)
    }
  }

  Process {
    id: diskProc
    command: ["bash", "-c", "df -h / | tail -1"]
    stdout: StdioCollector {
      waitForEnd: true
      onStreamFinished: root.parseDisk(text)
    }
  }

  Process {
    id: tempProc
    command: ["bash", "-c", "cat /sys/class/thermal/thermal_zone0/temp 2>/dev/null || echo ''"]
    stdout: StdioCollector {
      waitForEnd: true
      onStreamFinished: root.parseTemp(text)
    }
  }

  Process {
    id: netProc
    command: ["bash", "-c", "head -5 /proc/net/dev"]
    stdout: StdioCollector {
      waitForEnd: true
      onStreamFinished: root.parseNet(text)
    }
  }

  Process {
    id: uptimeProc
    command: ["bash", "-c", "cut -d. -f1 /proc/uptime"]
    stdout: StdioCollector {
      waitForEnd: true
      onStreamFinished: root.parseUptime(text)
    }
  }

  Process {
    id: kernelProc
    command: ["bash", "-c", "echo hostname=$(hostname) && echo kernel=$(uname -r) && grep 'model name' /proc/cpuinfo | head -1"]
    stdout: StdioCollector {
      waitForEnd: true
      onStreamFinished: root.parseInfo(text)
    }
  }

  Process {
    id: infoProc
    command: ["bash", "-c", "echo hostname=$(hostname) && echo kernel=$(uname -r) && grep 'model name' /proc/cpuinfo | head -1"]
    stdout: StdioCollector {
      waitForEnd: true
      onStreamFinished: root.parseInfo(text)
    }
  }

  Timer {
    interval: 2000
    running: root.opened
    repeat: true
    onTriggered: root.refresh()
  }

  PanelController {
    id: controller
    open: root.opened
    onOpenChanged: {
      if (!open) root.close()
    }

    Rectangle {
      id: panelBg
      anchors.fill: parent
      color: Color.background
      radius: Style.radius.l

      ColumnLayout {
        anchors.fill: parent
        anchors.margins: Style.space(16)
        spacing: Style.space(10)

        RowLayout {
          Layout.fillWidth: true

          Text {
            text: "System Overview"
            color: Color.foreground
            font.family: Style.font.family
            font.pixelSize: Style.font.title
            font.bold: true
            Layout.fillWidth: true
          }

          Text {
            text: root.hostname
            color: Color.foreground
            font.family: Style.font.family
            font.pixelSize: Style.font.caption
            opacity: 0.6
          }

          Button {
            text: "Close"
            font.family: Style.font.family
            font.pixelSize: Style.font.caption
            onClicked: root.dismiss()
          }
        }

        Rectangle {
          Layout.fillWidth: true
          height: 1
          color: Qt.darker(Color.foreground, 2.5)
        }

        Repeater {
          model: ListModel {
            ListElement { label: "Kernel"; value: "kernel" }
            ListElement { label: "CPU"; value: "cpu" }
            ListElement { label: "CPU Usage"; value: "cpuUsage" }
            ListElement { label: "Memory"; value: "mem" }
            ListElement { label: "Disk /"; value: "disk" }
            ListElement { label: "GPU Temp"; value: "gpu" }
            ListElement { label: "Network RX"; value: "netrx" }
            ListElement { label: "Network TX"; value: "nettx" }
            ListElement { label: "Uptime"; value: "uptime" }
          }

          RowLayout {
            required property var modelData
            Layout.fillWidth: true
            spacing: Style.space(8)

            Text {
              text: modelData.label
              color: Color.foreground
              font.family: Style.font.family
              font.pixelSize: Style.font.body
              font.bold: true
              Layout.preferredWidth: Style.space(100)
            }

            Text {
              text: {
                switch (modelData.value) {
                  case "kernel": return root.kernel
                  case "cpu": return root.cpuModel
                  case "cpuUsage": return root.cpuUsage
                  case "mem": return root.memUsage + " of " + root.memTotal
                  case "disk": return root.diskUsage
                  case "gpu": return root.gpuTemp
                  case "netrx": return "\u2193 " + root.netRx
                  case "nettx": return "\u2191 " + root.netTx
                  case "uptime": return root.uptime
                  default: return "--"
                }
              }
              color: Color.foreground
              font.family: Style.font.family
              font.pixelSize: Style.font.body
              opacity: 0.85
              Layout.fillWidth: true
              elide: Text.ElideRight
            }
          }
        }

        Item { Layout.fillHeight: true }
      }
    }
  }
}