autofmt arch stuff

This commit is contained in:
LemmyCook 2025-08-24 10:46:28 -04:00
parent 9ba5abc047
commit 9666ce4f5a
3 changed files with 399 additions and 393 deletions

View file

@ -22,8 +22,8 @@ NPanel {
// Small delay to ensure data is fully updated
Qt.callLater(() => {
// Force a UI update by triggering a property change
ArchUpdaterService.updatePackages = ArchUpdaterService.updatePackages;
}, 100);
ArchUpdaterService.updatePackages = ArchUpdaterService.updatePackages
}, 100)
}
}
}
@ -65,11 +65,14 @@ NPanel {
}
}
NDivider { Layout.fillWidth: true }
NDivider {
Layout.fillWidth: true
}
// Update summary
Text {
text: ArchUpdaterService.updatePackages.length + " package" + (ArchUpdaterService.updatePackages.length !== 1 ? "s" : "") + " can be updated"
text: ArchUpdaterService.updatePackages.length + " package" + (ArchUpdaterService.updatePackages.length
!== 1 ? "s" : "") + " can be updated"
font.pointSize: Style.fontSizeL * scaling
font.family: Settings.data.ui.fontDefault
font.weight: Style.fontWeightMedium
@ -117,15 +120,15 @@ NPanel {
id: checkbox
icon: "check_box_outline_blank"
onClicked: {
const isSelected = ArchUpdaterService.isPackageSelected(modelData.name);
const isSelected = ArchUpdaterService.isPackageSelected(modelData.name)
if (isSelected) {
ArchUpdaterService.togglePackageSelection(modelData.name);
icon = "check_box_outline_blank";
colorFg = Color.mOnSurfaceVariant;
ArchUpdaterService.togglePackageSelection(modelData.name)
icon = "check_box_outline_blank"
colorFg = Color.mOnSurfaceVariant
} else {
ArchUpdaterService.togglePackageSelection(modelData.name);
icon = "check_box";
colorFg = Color.mPrimary;
ArchUpdaterService.togglePackageSelection(modelData.name)
icon = "check_box"
colorFg = Color.mPrimary
}
}
colorBg: Color.transparent
@ -136,8 +139,8 @@ NPanel {
Component.onCompleted: {
// Set initial state
if (ArchUpdaterService.isPackageSelected(modelData.name)) {
icon = "check_box";
colorFg = Color.mPrimary;
icon = "check_box"
colorFg = Color.mPrimary
}
}
}
@ -173,8 +176,6 @@ NPanel {
}
}
// Action buttons
RowLayout {
Layout.fillWidth: true
@ -184,7 +185,7 @@ NPanel {
icon: "refresh"
tooltipText: "Check for updates"
onClicked: {
ArchUpdaterService.doPoll();
ArchUpdaterService.doPoll()
}
colorBg: Color.mSurfaceVariant
colorFg: Color.mOnSurface
@ -197,7 +198,7 @@ NPanel {
tooltipText: ArchUpdaterService.updateInProgress ? "Update in progress..." : "Update all packages"
enabled: !ArchUpdaterService.updateInProgress
onClicked: {
ArchUpdaterService.runUpdate();
ArchUpdaterService.runUpdate()
}
colorBg: ArchUpdaterService.updateInProgress ? Color.mSurfaceVariant : Color.mPrimary
colorFg: ArchUpdaterService.updateInProgress ? Color.mOnSurfaceVariant : Color.mOnPrimary
@ -211,13 +212,13 @@ NPanel {
enabled: !ArchUpdaterService.updateInProgress && ArchUpdaterService.selectedPackagesCount > 0
onClicked: {
if (ArchUpdaterService.selectedPackagesCount > 0) {
ArchUpdaterService.runSelectiveUpdate();
ArchUpdaterService.runSelectiveUpdate()
}
}
colorBg: ArchUpdaterService.updateInProgress ? Color.mSurfaceVariant :
(ArchUpdaterService.selectedPackagesCount > 0 ? Color.mSecondary : Color.mSurfaceVariant)
colorFg: ArchUpdaterService.updateInProgress ? Color.mOnSurfaceVariant :
(ArchUpdaterService.selectedPackagesCount > 0 ? Color.mOnSecondary : Color.mOnSurfaceVariant)
colorBg: ArchUpdaterService.updateInProgress ? Color.mSurfaceVariant : (ArchUpdaterService.selectedPackagesCount
> 0 ? Color.mSecondary : Color.mSurfaceVariant)
colorFg: ArchUpdaterService.updateInProgress ? Color.mOnSurfaceVariant : (ArchUpdaterService.selectedPackagesCount
> 0 ? Color.mOnSecondary : Color.mOnSurfaceVariant)
Layout.fillWidth: true
Layout.preferredHeight: 35 * scaling
}

View file

@ -18,12 +18,15 @@ NIconButton {
// Enhanced icon states with better visual feedback
icon: {
if (ArchUpdaterService.busy) return "sync"
if (ArchUpdaterService.busy)
return "sync"
if (ArchUpdaterService.updatePackages.length > 0) {
// Show different icons based on update count
const count = ArchUpdaterService.updatePackages.length
if (count > 50) return "system_update_alt" // Many updates
if (count > 10) return "system_update" // Moderate updates
if (count > 50)
return "system_update_alt" // Many updates
if (count > 10)
return "system_update" // Moderate updates
return "system_update" // Few updates
}
return "task_alt"
@ -32,40 +35,39 @@ NIconButton {
// Enhanced tooltip with more information
tooltipText: {
if (ArchUpdaterService.busy)
return "Checking for updates…";
return "Checking for updates…"
var count = ArchUpdaterService.updatePackages.length;
var count = ArchUpdaterService.updatePackages.length
if (count === 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:");
var header = count === 1 ? "One package can be upgraded:" : (count + " packages can be upgraded:")
var list = ArchUpdaterService.updatePackages || [];
var s = "";
var limit = Math.min(list.length, 8); // Reduced to 8 for better readability
var list = ArchUpdaterService.updatePackages || []
var s = ""
var limit = Math.min(list.length, 8)
// Reduced to 8 for better readability
for (var i = 0; i < limit; ++i) {
var p = list[i];
s += (i ? "\n" : "") + (p.name + ": " + p.oldVersion + " → " + p.newVersion);
var p = list[i]
s += (i ? "\n" : "") + (p.name + ": " + p.oldVersion + " → " + p.newVersion)
}
if (list.length > 8)
s += "\n… and " + (list.length - 8) + " more";
s += "\n… and " + (list.length - 8) + " more"
return header + "\n\n" + s + "\n\nClick to update system";
return header + "\n\n" + s + "\n\nClick to update system"
}
// Enhanced click behavior with confirmation
onClicked: {
if (ArchUpdaterService.busy)
return;
return
if (ArchUpdaterService.updatePackages.length > 0) {
// Show confirmation dialog for updates
PanelService.updatePanel.toggle(screen);
PanelService.updatePanel.toggle(screen)
} else {
// Just refresh if no updates available
ArchUpdaterService.doPoll();
ArchUpdaterService.doPoll()
}
}
}

View file

@ -1,4 +1,5 @@
pragma Singleton
import Quickshell
import QtQuick
import Quickshell.Io
@ -20,124 +21,126 @@ Singleton {
command: ["checkupdates"]
onExited: function (exitCode) {
if (exitCode !== 0 && exitCode !== 2) {
console.warn("[UpdateService] checkupdates failed (code:", exitCode, ")");
updatePackages = [];
return;
console.warn("[UpdateService] checkupdates failed (code:", exitCode, ")")
updatePackages = []
return
}
}
stdout: StdioCollector {
onStreamFinished: {
parseCheckupdatesOutput(text);
parseCheckupdatesOutput(text)
}
}
}
// Parse checkupdates output
function parseCheckupdatesOutput(output) {
const lines = output.trim().split('\n').filter(line => line.trim());
const packages = [];
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]+)$/);
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]}`
});
"name": m[1],
"oldVersion": m[2],
"newVersion": m[3],
"description": `${m[1]} ${m[2]} -> ${m[3]}`
})
}
}
updatePackages = packages;
updatePackages = packages
}
// Check for updates
function doPoll() {
if (busy) return;
checkupdatesProcess.running = true;
if (busy)
return
checkupdatesProcess.running = true
}
// Update all packages
function runUpdate() {
if (updates === 0) {
doPoll();
return;
doPoll()
return
}
updateInProgress = true;
Quickshell.execDetached(["pkexec", "pacman", "-Syu", "--noconfirm"]);
updateInProgress = true
Quickshell.execDetached(["pkexec", "pacman", "-Syu", "--noconfirm"])
// Refresh after updates with multiple attempts
refreshAfterUpdate();
refreshAfterUpdate()
}
// Update selected packages
function runSelectiveUpdate() {
if (selectedPackages.length === 0) return;
if (selectedPackages.length === 0)
return
updateInProgress = true;
const command = ["pkexec", "pacman", "-S", "--noconfirm"].concat(selectedPackages);
Quickshell.execDetached(command);
updateInProgress = true
const command = ["pkexec", "pacman", "-S", "--noconfirm"].concat(selectedPackages)
Quickshell.execDetached(command)
// Clear selection and refresh
selectedPackages = [];
selectedPackagesCount = 0;
refreshAfterUpdate();
selectedPackages = []
selectedPackagesCount = 0
refreshAfterUpdate()
}
// Package selection functions
function togglePackageSelection(packageName) {
const index = selectedPackages.indexOf(packageName);
const index = selectedPackages.indexOf(packageName)
if (index > -1) {
selectedPackages.splice(index, 1);
selectedPackages.splice(index, 1)
} else {
selectedPackages.push(packageName);
selectedPackages.push(packageName)
}
selectedPackagesCount = selectedPackages.length;
selectedPackagesCount = selectedPackages.length
}
function selectAllPackages() {
selectedPackages = updatePackages.map(pkg => pkg.name);
selectedPackagesCount = selectedPackages.length;
selectedPackages = updatePackages.map(pkg => pkg.name)
selectedPackagesCount = selectedPackages.length
}
function deselectAllPackages() {
selectedPackages = [];
selectedPackagesCount = 0;
selectedPackages = []
selectedPackagesCount = 0
}
function isPackageSelected(packageName) {
return selectedPackages.indexOf(packageName) > -1;
return selectedPackages.indexOf(packageName) > -1
}
// Robust refresh after updates
function refreshAfterUpdate() {
// First refresh attempt after 3 seconds
Qt.callLater(() => {
doPoll();
}, 3000);
doPoll()
}, 3000)
// Second refresh attempt after 8 seconds
Qt.callLater(() => {
doPoll();
}, 8000);
doPoll()
}, 8000)
// Third refresh attempt after 15 seconds
Qt.callLater(() => {
doPoll();
updateInProgress = false;
}, 15000);
doPoll()
updateInProgress = false
}, 15000)
// Final refresh attempt after 30 seconds
Qt.callLater(() => {
doPoll();
}, 30000);
doPoll()
}, 30000)
}
// Notification helper
function notify(title, body) {
Quickshell.execDetached(["notify-send", "-a", "UpdateService", "-i", "system-software-update", title, body]);
Quickshell.execDetached(["notify-send", "-a", "UpdateService", "-i", "system-software-update", title, body])
}
// Auto-poll every 15 minutes