ArchUpdater: add AUR support

This commit is contained in:
Ly-sec 2025-08-27 09:28:58 +02:00
parent 74e65d75cb
commit a1f87c50bc
3 changed files with 195 additions and 80 deletions

View file

@ -16,6 +16,7 @@ NPanel {
// When the panel opens // When the panel opens
onOpened: { onOpened: {
ArchUpdaterService.doPoll() ArchUpdaterService.doPoll()
ArchUpdaterService.doAurPoll()
} }
panelContent: Rectangle { panelContent: Rectangle {
@ -61,8 +62,7 @@ NPanel {
// Update summary // Update summary
Text { Text {
text: ArchUpdaterService.updatePackages.length + " package" + (ArchUpdaterService.updatePackages.length text: ArchUpdaterService.totalUpdates + " package" + (ArchUpdaterService.totalUpdates !== 1 ? "s" : "") + " can be updated"
!== 1 ? "s" : "") + " can be updated"
font.pointSize: Style.fontSizeL * scaling font.pointSize: Style.fontSizeL * scaling
font.family: Settings.data.ui.fontDefault font.family: Settings.data.ui.fontDefault
font.weight: Style.fontWeightMedium font.weight: Style.fontWeightMedium
@ -72,31 +72,35 @@ NPanel {
// Package selection info // Package selection info
Text { Text {
text: ArchUpdaterService.selectedPackagesCount + " of " + ArchUpdaterService.updatePackages.length + " packages selected" text: ArchUpdaterService.selectedPackagesCount + " of " + ArchUpdaterService.totalUpdates + " packages selected"
font.pointSize: Style.fontSizeS * scaling font.pointSize: Style.fontSizeS * scaling
font.family: Settings.data.ui.fontDefault font.family: Settings.data.ui.fontDefault
color: Color.mOnSurfaceVariant color: Color.mOnSurfaceVariant
Layout.fillWidth: true Layout.fillWidth: true
} }
// Package list // Unified list
Rectangle { Rectangle {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
color: Color.mSurfaceVariant color: Color.mSurfaceVariant
radius: Style.radiusM * scaling radius: Style.radiusM * scaling
// Combine repo and AUR lists in order: repos first, then AUR
property var items: (ArchUpdaterService.repoPackages || []).concat(ArchUpdaterService.aurPackages || [])
ListView { ListView {
id: packageListView id: unifiedList
anchors.fill: parent anchors.fill: parent
anchors.margins: Style.marginS * scaling anchors.margins: Style.marginS * scaling
clip: true clip: true
model: ArchUpdaterService.updatePackages model: parent.items
spacing: Style.marginXS * scaling spacing: Style.marginXS * scaling
cacheBuffer: 300 * scaling
delegate: Rectangle { delegate: Rectangle {
width: packageListView.width width: unifiedList.width
height: 50 * scaling height: 56 * scaling
color: Color.transparent color: Color.transparent
radius: Style.radiusS * scaling radius: Style.radiusS * scaling
@ -105,34 +109,16 @@ NPanel {
anchors.margins: Style.marginS * scaling anchors.margins: Style.marginS * scaling
spacing: Style.marginS * scaling spacing: Style.marginS * scaling
// Checkbox for selection // Checkbox for selection (pure bindings; no imperative state)
NIconButton { NIconButton {
id: checkbox id: checkbox
icon: "check_box_outline_blank" icon: ArchUpdaterService.isPackageSelected(modelData.name) ? "check_box" : "check_box_outline_blank"
onClicked: { onClicked: ArchUpdaterService.togglePackageSelection(modelData.name)
const isSelected = ArchUpdaterService.isPackageSelected(modelData.name)
if (isSelected) {
ArchUpdaterService.togglePackageSelection(modelData.name)
icon = "check_box_outline_blank"
colorFg = Color.mOnSurfaceVariant
} else {
ArchUpdaterService.togglePackageSelection(modelData.name)
icon = "check_box"
colorFg = Color.mPrimary
}
}
colorBg: Color.transparent colorBg: Color.transparent
colorFg: Color.mOnSurfaceVariant colorFg: ArchUpdaterService.isPackageSelected(
modelData.name) ? ((modelData.source === "aur") ? Color.mSecondary : Color.mPrimary) : Color.mOnSurfaceVariant
Layout.preferredWidth: 30 * scaling Layout.preferredWidth: 30 * scaling
Layout.preferredHeight: 30 * scaling Layout.preferredHeight: 30 * scaling
Component.onCompleted: {
// Set initial state
if (ArchUpdaterService.isPackageSelected(modelData.name)) {
icon = "check_box"
colorFg = Color.mPrimary
}
}
} }
// Package info // Package info
@ -140,6 +126,10 @@ NPanel {
Layout.fillWidth: true Layout.fillWidth: true
spacing: Style.marginXXS * scaling spacing: Style.marginXXS * scaling
RowLayout {
Layout.fillWidth: true
spacing: Style.marginXS * scaling
Text { Text {
text: modelData.name text: modelData.name
font.pointSize: Style.fontSizeM * scaling font.pointSize: Style.fontSizeM * scaling
@ -149,6 +139,27 @@ NPanel {
Layout.fillWidth: true Layout.fillWidth: true
} }
// Source badge (custom rectangle)
Rectangle {
visible: !!modelData.source
radius: 9999
color: modelData.source === "aur" ? Color.mSecondary : Color.mPrimary
Layout.alignment: Qt.AlignVCenter
implicitHeight: Math.max(Style.fontSizeXS * 1.7 * scaling, 16 * scaling)
// Width based on label content + horizontal padding
implicitWidth: badgeText.implicitWidth + Math.max(12 * scaling, Style.marginS * scaling)
NText {
id: badgeText
anchors.centerIn: parent
text: modelData.source === "aur" ? "AUR" : "Repo"
font.pointSize: Style.fontSizeXS * scaling
font.weight: Style.fontWeightBold
color: modelData.source === "aur" ? Color.mOnSecondary : Color.mOnPrimary
}
}
}
Text { Text {
text: modelData.oldVersion + " → " + modelData.newVersion text: modelData.oldVersion + " → " + modelData.newVersion
font.pointSize: Style.fontSizeS * scaling font.pointSize: Style.fontSizeS * scaling
@ -176,6 +187,7 @@ NPanel {
tooltipText: "Check for updates" tooltipText: "Check for updates"
onClicked: { onClicked: {
ArchUpdaterService.doPoll() ArchUpdaterService.doPoll()
ArchUpdaterService.doAurPoll()
} }
colorBg: Color.mSurfaceVariant colorBg: Color.mSurfaceVariant
colorFg: Color.mOnSurface colorFg: Color.mOnSurface

View file

@ -14,62 +14,79 @@ NIconButton {
sizeRatio: 0.8 sizeRatio: 0.8
colorBg: Color.mSurfaceVariant colorBg: Color.mSurfaceVariant
colorFg: Color.mOnSurface // Highlight color based on update source
colorFg: {
if (ArchUpdaterService.totalUpdates === 0)
return Color.mOnSurface
if (ArchUpdaterService.updates > 0 && ArchUpdaterService.aurUpdates > 0)
return Color.mPrimary
if (ArchUpdaterService.updates > 0)
return Color.mPrimary
return Color.mSecondary
}
colorBorder: Color.transparent colorBorder: Color.transparent
colorBorderHover: Color.transparent colorBorderHover: Color.transparent
// Enhanced icon states with better visual feedback // Icon states
icon: { icon: {
if (ArchUpdaterService.busy) if (ArchUpdaterService.busy || ArchUpdaterService.aurBusy)
return "sync" return "sync"
if (ArchUpdaterService.updatePackages.length > 0) { if (ArchUpdaterService.totalUpdates > 0) {
// Show different icons based on update count const count = ArchUpdaterService.totalUpdates
const count = ArchUpdaterService.updatePackages.length
if (count > 50) if (count > 50)
return "system_update_alt" // Many updates return "system_update_alt"
if (count > 10) if (count > 10)
return "system_update" // Moderate updates return "system_update"
return "system_update" // Few updates return "system_update"
} }
return "task_alt" return "task_alt"
} }
// Enhanced tooltip with more information // Tooltip with repo vs AUR breakdown and sample lists
tooltipText: { tooltipText: {
if (ArchUpdaterService.busy) if (ArchUpdaterService.busy || ArchUpdaterService.aurBusy)
return "Checking for updates…" return "Checking for updates…"
var count = ArchUpdaterService.updatePackages.length const repoCount = ArchUpdaterService.updates
if (count === 0) const aurCount = ArchUpdaterService.aurUpdates
const total = ArchUpdaterService.totalUpdates
if (total === 0)
return "System is up to date ✓" return "System is up to date ✓"
var header = count === 1 ? "One package can be upgraded:" : (count + " packages can be upgraded:") let header = total === 1 ? "One package can be upgraded:" : (total + " packages can be upgraded:")
var list = ArchUpdaterService.updatePackages || [] function sampleList(arr, n, colorLabel) {
var s = "" const limit = Math.min(arr.length, n)
var limit = Math.min(list.length, 8) let s = ""
// Reduced to 8 for better readability
for (var i = 0; i < limit; ++i) { for (var i = 0; i < limit; ++i) {
var p = list[i] const p = arr[i]
s += (i ? "\n" : "") + (p.name + ": " + p.oldVersion + " → " + p.newVersion) s += (i ? "\n" : "") + (p.name + ": " + p.oldVersion + " → " + p.newVersion)
} }
if (list.length > 8) if (arr.length > limit)
s += "\n… and " + (list.length - 8) + " more" s += "\n… and " + (arr.length - limit) + " more"
return (colorLabel ? (colorLabel + "\n") : "") + (s || "None")
return header + "\n\n" + s + "\n\nClick to update system" }
const repoHeader = repoCount > 0 ? ("Repo (" + repoCount + "):") : "Repo: 0"
const aurHeader = aurCount > 0 ? ("AUR (" + aurCount + "):") : "AUR: 0"
const repoBlock = repoCount > 0 ? (repoHeader + "\n\n" + sampleList(ArchUpdaterService.repoPackages,
5)) : repoHeader
const aurBlock = aurCount > 0 ? (aurHeader + "\n\n" + sampleList(ArchUpdaterService.aurPackages, 5)) : aurHeader
return header + "\n\n" + repoBlock + "\n\n" + aurBlock + "\n\nClick to update system"
} }
// Enhanced click behavior with confirmation
onClicked: { onClicked: {
if (ArchUpdaterService.busy) if (ArchUpdaterService.busy || ArchUpdaterService.aurBusy)
return return
if (ArchUpdaterService.updatePackages.length > 0) { if (ArchUpdaterService.totalUpdates > 0) {
// Show confirmation dialog for updates
PanelService.getPanel("archUpdaterPanel").toggle(screen, this) PanelService.getPanel("archUpdaterPanel").toggle(screen, this)
} else { } else {
// Just refresh if no updates available
ArchUpdaterService.doPoll() ArchUpdaterService.doPoll()
ArchUpdaterService.doAurPoll()
} }
} }
} }

View file

@ -10,29 +10,54 @@ Singleton {
// Core properties // Core properties
readonly property bool busy: checkupdatesProcess.running readonly property bool busy: checkupdatesProcess.running
readonly property int updates: updatePackages.length readonly property bool aurBusy: checkAurUpdatesProcess.running
property var updatePackages: [] readonly property int updates: repoPackages.length
readonly property int aurUpdates: aurPackages.length
readonly property int totalUpdates: updates + aurUpdates
property var repoPackages: []
property var aurPackages: []
property var selectedPackages: [] property var selectedPackages: []
property int selectedPackagesCount: 0 property int selectedPackagesCount: 0
property bool updateInProgress: false property bool updateInProgress: false
// Initial check // Initial check
Component.onCompleted: doPoll() Component.onCompleted: {
doPoll()
doAurPoll()
}
// Process for checking updates // Process for checking repo updates
Process { Process {
id: checkupdatesProcess id: checkupdatesProcess
command: ["checkupdates"] command: ["checkupdates"]
onExited: function (exitCode) { onExited: function (exitCode) {
if (exitCode !== 0 && exitCode !== 2) { if (exitCode !== 0 && exitCode !== 2) {
Logger.warn("ArchUpdater", "checkupdates failed (code:", exitCode, ")") Logger.warn("ArchUpdater", "checkupdates failed (code:", exitCode, ")")
updatePackages = [] repoPackages = []
} }
} }
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
parseCheckupdatesOutput(text) parseCheckupdatesOutput(text)
Logger.log("ArchUpdater", "found", updatePackages.length, "upgradable package(s)") Logger.log("ArchUpdater", "found", repoPackages.length, "repo package(s) to upgrade")
}
}
}
// Process for checking AUR updates
Process {
id: checkAurUpdatesProcess
command: ["sh", "-c", "command -v yay >/dev/null 2>&1 && yay -Qua || command -v paru >/dev/null 2>&1 && paru -Qua || echo ''"]
onExited: function (exitCode) {
if (exitCode !== 0) {
Logger.warn("ArchUpdater", "AUR check failed (code:", exitCode, ")")
aurPackages = []
}
}
stdout: StdioCollector {
onStreamFinished: {
parseAurUpdatesOutput(text)
Logger.log("ArchUpdater", "found", aurPackages.length, "AUR package(s) to upgrade")
} }
} }
} }
@ -49,12 +74,34 @@ Singleton {
"name": m[1], "name": m[1],
"oldVersion": m[2], "oldVersion": m[2],
"newVersion": m[3], "newVersion": m[3],
"description": `${m[1]} ${m[2]} -> ${m[3]}` "description": `${m[1]} ${m[2]} -> ${m[3]}`,
"source": "repo"
}) })
} }
} }
updatePackages = packages repoPackages = packages
}
// Parse AUR updates output
function parseAurUpdatesOutput(output) {
const lines = output.trim().split('\n').filter(line => line.trim())
const packages = []
for (const line of lines) {
const m = line.match(/^(\S+)\s+([^\s]+)\s+->\s+([^\s]+)$/)
if (m) {
packages.push({
"name": m[1],
"oldVersion": m[2],
"newVersion": m[3],
"description": `${m[1]} ${m[2]} -> ${m[3]}`,
"source": "aur"
})
}
}
aurPackages = packages
} }
// Check for updates // Check for updates
@ -64,15 +111,26 @@ Singleton {
checkupdatesProcess.running = true checkupdatesProcess.running = true
} }
// Update all packages // Check for AUR updates
function doAurPoll() {
if (aurBusy)
return
checkAurUpdatesProcess.running = true
}
// Update all packages (repo + AUR)
function runUpdate() { function runUpdate() {
if (updates === 0) { if (totalUpdates === 0) {
doPoll() doPoll()
doAurPoll()
return return
} }
updateInProgress = true updateInProgress = true
// Update repos first, then AUR
Quickshell.execDetached(["pkexec", "pacman", "-Syu", "--noconfirm"]) Quickshell.execDetached(["pkexec", "pacman", "-Syu", "--noconfirm"])
Quickshell.execDetached(
["sh", "-c", "command -v yay >/dev/null 2>&1 && yay -Sua --noconfirm || command -v paru >/dev/null 2>&1 && paru -Sua --noconfirm || true"])
// Refresh after updates with multiple attempts // Refresh after updates with multiple attempts
refreshAfterUpdate() refreshAfterUpdate()
@ -84,8 +142,29 @@ Singleton {
return return
updateInProgress = true updateInProgress = true
const command = ["pkexec", "pacman", "-S", "--noconfirm"].concat(selectedPackages) // Split selected packages by source
Quickshell.execDetached(command) const repoPkgs = selectedPackages.filter(pkg => {
const repoPkg = repoPackages.find(p => p.name === pkg)
return repoPkg && repoPkg.source === "repo"
})
const aurPkgs = selectedPackages.filter(pkg => {
const aurPkg = aurPackages.find(p => p.name === pkg)
return aurPkg && aurPkg.source === "aur"
})
// Update repo packages
if (repoPkgs.length > 0) {
const repoCommand = ["pkexec", "pacman", "-S", "--noconfirm"].concat(repoPkgs)
Quickshell.execDetached(repoCommand)
}
// Update AUR packages
if (aurPkgs.length > 0) {
const aurCommand = ["sh", "-c", `command -v yay >/dev/null 2>&1 && yay -S ${aurPkgs.join(
' ')} --noconfirm || command -v paru >/dev/null 2>&1 && paru -S ${aurPkgs.join(
' ')} --noconfirm || true`]
Quickshell.execDetached(aurCommand)
}
// Clear selection and refresh // Clear selection and refresh
selectedPackages = [] selectedPackages = []
@ -105,7 +184,7 @@ Singleton {
} }
function selectAllPackages() { function selectAllPackages() {
selectedPackages = updatePackages.map(pkg => pkg.name) selectedPackages = [...repoPackages.map(pkg => pkg.name), ...aurPackages.map(pkg => pkg.name)]
selectedPackagesCount = selectedPackages.length selectedPackagesCount = selectedPackages.length
} }
@ -123,22 +202,26 @@ Singleton {
// First refresh attempt after 3 seconds // First refresh attempt after 3 seconds
Qt.callLater(() => { Qt.callLater(() => {
doPoll() doPoll()
doAurPoll()
}, 3000) }, 3000)
// Second refresh attempt after 8 seconds // Second refresh attempt after 8 seconds
Qt.callLater(() => { Qt.callLater(() => {
doPoll() doPoll()
doAurPoll()
}, 8000) }, 8000)
// Third refresh attempt after 15 seconds // Third refresh attempt after 15 seconds
Qt.callLater(() => { Qt.callLater(() => {
doPoll() doPoll()
doAurPoll()
updateInProgress = false updateInProgress = false
}, 15000) }, 15000)
// Final refresh attempt after 30 seconds // Final refresh attempt after 30 seconds
Qt.callLater(() => { Qt.callLater(() => {
doPoll() doPoll()
doAurPoll()
}, 30000) }, 30000)
} }
@ -152,6 +235,9 @@ Singleton {
interval: 15 * 60 * 1000 // 15 minutes interval: 15 * 60 * 1000 // 15 minutes
repeat: true repeat: true
running: true running: true
onTriggered: doPoll() onTriggered: {
doPoll()
doAurPoll()
}
} }
} }