refaktor
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
pragma Singleton
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
// Per-workspace icon cache: maps workspaceId -> array of icon strings
|
||||
property var workspaceIcons: ({})
|
||||
|
||||
function iconsForWorkspace(workspaceId) {
|
||||
return root.workspaceIcons[workspaceId] || []
|
||||
}
|
||||
|
||||
function matchIcon(name) {
|
||||
if (!name) return ""
|
||||
var lower = name.toLowerCase()
|
||||
if (iconMap[lower]) return iconMap[lower]
|
||||
for (var key in iconMap) {
|
||||
if (key.endsWith("*") && key.startsWith("*")) {
|
||||
var middle = key.slice(1, -1)
|
||||
if (lower.indexOf(middle) !== -1) return iconMap[key]
|
||||
} else if (key.endsWith("*")) {
|
||||
var prefix = key.slice(0, -1)
|
||||
if (lower.startsWith(prefix)) return iconMap[key]
|
||||
} else if (key.startsWith("*")) {
|
||||
var suffix = key.slice(1)
|
||||
if (lower.endsWith(suffix)) return iconMap[key]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Process {
|
||||
id: clientsProc
|
||||
command: ["hyprctl", "clients", "-j"]
|
||||
running: true
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
try {
|
||||
var data = JSON.parse(this.text.trim())
|
||||
var newIcons = {}
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var client = data[i]
|
||||
var wid = client.workspace.id
|
||||
var icon = root.matchIcon(client.initialTitle) || root.matchIcon(client.initialClass)
|
||||
if (icon) {
|
||||
if (!newIcons[wid]) newIcons[wid] = []
|
||||
newIcons[wid].push(icon)
|
||||
}
|
||||
}
|
||||
root.workspaceIcons = newIcons
|
||||
} catch (e) {
|
||||
// hyprctl output was not valid JSON
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: 1000
|
||||
running: true
|
||||
repeat: true
|
||||
triggeredOnStart: true
|
||||
onTriggered: clientsProc.running = true
|
||||
}
|
||||
|
||||
readonly property var iconMap: ({
|
||||
"grayjay": "",
|
||||
"ablaze floorp": "",
|
||||
"floorp": "",
|
||||
"librewolf": "",
|
||||
"midori": "",
|
||||
"brave-browser": "",
|
||||
"chromium": "",
|
||||
"org.mozilla.thunderbird": "",
|
||||
"kitty": "",
|
||||
"alacritty": "",
|
||||
"vlc media player": "",
|
||||
"mpv": "",
|
||||
"ffplay": "",
|
||||
"org.kde.kdenlive": "",
|
||||
"discord": "",
|
||||
"vesktop": "",
|
||||
"signal": "",
|
||||
"xyz.chatboxapp.app": "",
|
||||
"visual studio code": "",
|
||||
"vscodium": "",
|
||||
"jetbrains-idea": "",
|
||||
"jetbrains-studio": "",
|
||||
"org.xfce.mousepad": "",
|
||||
"org.keepassxc.keepassxc": "",
|
||||
"yubico authenticator": "",
|
||||
"com.nextcloud*": "",
|
||||
"octopi": "",
|
||||
"steam*": "",
|
||||
"org.prismlauncher*": "",
|
||||
"minecraft*": "",
|
||||
"game": "",
|
||||
"blender": "",
|
||||
"krita": "",
|
||||
"virt*": "",
|
||||
"remote-viewer": "",
|
||||
"qpwgraph": "",
|
||||
"carla": "",
|
||||
"com.obsproject.studio": "",
|
||||
"hyprland-share-picker": "",
|
||||
"libreoffice-startcenter": "",
|
||||
"libreoffice-base": "",
|
||||
"libreoffice-calc": "",
|
||||
"libreoffice-draw": "",
|
||||
"libreoffice-impress": "",
|
||||
"libreoffice-math": "",
|
||||
"libreoffice-writer": "",
|
||||
"*rnote": "",
|
||||
"xreader": "",
|
||||
"*xournalpp*": "",
|
||||
"qpdfview.local.qpdfview": "",
|
||||
"mission center": "",
|
||||
"qdirstat": "",
|
||||
"disks": "",
|
||||
"nemo": "",
|
||||
"org.gnome.nautilus": "",
|
||||
"org.kde.dolphin": "",
|
||||
"xdg-desktop-portal-gtk": "",
|
||||
"nwg-look": "",
|
||||
"qt5ct": "",
|
||||
"qt6ct": "",
|
||||
"sddm-conf": "",
|
||||
"blueman*": "",
|
||||
"nm-connection-editor": "",
|
||||
"calculator": "",
|
||||
"*vpn": "",
|
||||
"*cisco*": "",
|
||||
"*qbittorrent*": "",
|
||||
"xilinx*": "",
|
||||
"vsim": "",
|
||||
"*boxbuddy*": "",
|
||||
"fladder": "",
|
||||
"crunchyroll": "",
|
||||
"netflix": "",
|
||||
"primevideo": "",
|
||||
"viewnior": "",
|
||||
"gimp": "",
|
||||
"*inkscape*": "",
|
||||
"lightburn": "",
|
||||
"wofi": "",
|
||||
"org.gnome.Settings": "",
|
||||
"pavucontrol": "",
|
||||
"nm-applet": ""
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
singleton AppsState AppsState.qml
|
||||
@@ -4,6 +4,7 @@ import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
Item {
|
||||
property bool available: false
|
||||
property real percentage: 0
|
||||
property bool charging: false
|
||||
property real energy: 0
|
||||
@@ -14,37 +15,30 @@ Item {
|
||||
|
||||
function parseUpower(line) {
|
||||
line = line.trim()
|
||||
|
||||
if (line.startsWith("percentage:")) {
|
||||
percentage = parseInt(line.split(":")[1])
|
||||
// console.log("percentage =", percentage)
|
||||
}
|
||||
|
||||
else if (line.startsWith("state:")) {
|
||||
charging = !line.includes("discharging")
|
||||
// console.log("charging =", charging)
|
||||
}
|
||||
|
||||
else if (line.startsWith("energy:")) {
|
||||
energy = parseFloat(line.split(":")[1])
|
||||
// console.log("energy =", energy)
|
||||
}
|
||||
|
||||
else if (line.startsWith("voltage:")) {
|
||||
voltage = parseFloat(line.split(":")[1])
|
||||
// console.log("voltage =", voltage)
|
||||
}
|
||||
|
||||
else if (line.startsWith("energy-rate:")) {
|
||||
energy_rate = parseFloat(line.split(":")[1])
|
||||
// console.log("energy_rate =", energy_rate)
|
||||
}
|
||||
|
||||
else if (line.startsWith("charge-cycles:")) {
|
||||
charge_cycle = parseInt(line.split(":")[1])
|
||||
// console.log("charge_cycle =", charge_cycle)
|
||||
}
|
||||
|
||||
else if (line.startsWith("time to empty:")) {
|
||||
time_to_empty = parseFloat(line.split(":")[1])
|
||||
// console.log("time_to_empty =", time_to_empty)
|
||||
@@ -53,12 +47,25 @@ Item {
|
||||
|
||||
Process {
|
||||
id: upowerProc
|
||||
command: ["bash", "-c", "upower -i $(upower -e | grep BAT)"]
|
||||
|
||||
command: ["bash", "-c", "upower -i $(upower -e | grep '^/org/freedesktop/UPower/devices/battery')"]
|
||||
stdout: SplitParser {
|
||||
onRead: function(data) {
|
||||
parseUpower(data)
|
||||
// console.log("battery available:", data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: batteryAvailable
|
||||
command: ["sh", "-c", "upower -e | grep -q '^/org/freedesktop/UPower/devices/battery' && echo '1' || echo '0'"]
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
const hasBattery = this.text.trim() === "1"
|
||||
available = hasBattery
|
||||
if (hasBattery) {
|
||||
pollTimer.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,16 +75,11 @@ Item {
|
||||
interval: 1000
|
||||
running: false
|
||||
repeat: true
|
||||
triggeredOnStart: true
|
||||
triggeredOnStart: false
|
||||
onTriggered: upowerProc.running = true
|
||||
}
|
||||
|
||||
function start() {
|
||||
pollTimer.start()
|
||||
upowerProc.running = true
|
||||
}
|
||||
|
||||
function stop() {
|
||||
pollTimer.stop()
|
||||
Component.onCompleted: {
|
||||
batteryAvailable.running = true
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,27 @@ pragma Singleton
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import "../../../../config"
|
||||
|
||||
QtObject {
|
||||
Item {
|
||||
property int idle: 0
|
||||
|
||||
Process {
|
||||
id: statusScript
|
||||
command: ["sh", "-c", Config.configDir + "/modules/bar/scripts/Idle.sh --status"]
|
||||
running: true
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
idle = this.text.trim() === "0" ? 1 : 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: 5000
|
||||
running: true
|
||||
repeat: true
|
||||
triggeredOnStart: true
|
||||
onTriggered: statusScript.running = true
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ pragma Singleton
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import "../../../../config"
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
@@ -9,7 +10,6 @@ QtObject {
|
||||
property string status: "..."
|
||||
property bool running: false
|
||||
|
||||
// Timer property
|
||||
property Timer networkTimer: Timer {
|
||||
interval: 10000
|
||||
repeat: true
|
||||
@@ -17,15 +17,13 @@ QtObject {
|
||||
onTriggered: networkScript.running = true
|
||||
}
|
||||
|
||||
// Process property
|
||||
property Process networkScript: Process {
|
||||
running: true
|
||||
command: ["sh", "-c", Quickshell.env("HOME") + "/.config/quickshell/modules/bar/scripts/Network.sh"]
|
||||
command: ["sh", "-c", Config.configDir + "/modules/bar/scripts/Network.sh"]
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
root.status = this.text.trim()
|
||||
// console.log("Network status:", root.status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user