1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-08 06:25:37 -05:00

system updater: separated update finder from pkg manager (#419)

This commit is contained in:
max72bra
2025-10-14 14:18:34 +02:00
committed by GitHub
parent eb7e665c86
commit 061bb50b88

View File

@@ -14,13 +14,35 @@ Singleton {
property bool isChecking: false
property bool hasError: false
property string errorMessage: ""
property string updChecker: ""
property string pkgManager: ""
property string distribution: ""
property bool distributionSupported: false
property string shellVersion: ""
readonly property var archBasedSettings: {
"listUpdatesParams": ["-Qu"],
readonly property var archBasedUCSettings: {
"listUpdatesSettings": {
"params": [],
"correctExitCodes": [0, 2] // Exit code 0 = updates available, 2 = no updates
},
"parserSettings": {
"lineRegex": /^(\S+)\s+([^\s]+)\s+->\s+([^\s]+)$/,
"entryProducer": function (match) {
return {
"name": match[1],
"currentVersion": match[2],
"newVersion": match[3],
"description": `${match[1]} ${match[2]} ${match[3]}`
}
}
}
}
readonly property var archBasedPMSettings: {
"listUpdatesSettings": {
"params": ["-Qu"],
"correctExitCodes": [0, 1] // Exit code 0 = updates available, 1 = no updates
},
"upgradeSettings": {
"params": ["-Syu"],
"requiresSudo": false
@@ -38,11 +60,11 @@ Singleton {
}
}
readonly property var packageManagerParams: {
"yay": archBasedSettings,
"paru": archBasedSettings,
"dnf": {
"listUpdatesParams": ["list", "--upgrades", "--quiet", "--color=never"],
readonly property var fedoraBasedPMSettings: {
"listUpdatesSettings": {
"params": ["list", "--upgrades", "--quiet", "--color=never"],
"correctExitCodes": [0, 1] // Exit code 0 = updates available, 1 = no updates
},
"upgradeSettings": {
"params": ["upgrade"],
"requiresSudo": true
@@ -59,6 +81,14 @@ Singleton {
}
}
}
readonly property var updateCheckerParams: {
"checkupdates": archBasedUCSettings
}
readonly property var packageManagerParams: {
"yay": archBasedPMSettings,
"paru": archBasedPMSettings,
"dnf": fedoraBasedPMSettings
}
readonly property list<string> supportedDistributions: ["arch", "cachyos", "manjaro", "endeavouros", "fedora"]
readonly property int updateCount: availableUpdates.length
@@ -75,7 +105,9 @@ Singleton {
distributionSupported = supportedDistributions.includes(distribution)
if (distributionSupported) {
helperDetection.running = true
updateFinderDetection.running = true
pkgManagerDetection.running = true
checkForUpdates()
} else {
console.warn("SystemUpdate: Unsupported distribution:", distribution)
}
@@ -103,14 +135,29 @@ Singleton {
}
Process {
id: helperDetection
id: updateFinderDetection
command: ["sh", "-c", "which checkupdates"]
onExited: (exitCode) => {
if (exitCode === 0) {
const exeFound = stdout.text.trim()
updChecker = exeFound.split('/').pop()
} else {
console.warn("SystemUpdate: No update checker found. Will use package manager.")
}
}
stdout: StdioCollector {}
}
Process {
id: pkgManagerDetection
command: ["sh", "-c", "which paru || which yay || which dnf"]
onExited: (exitCode) => {
if (exitCode === 0) {
const helperPath = stdout.text.trim()
pkgManager = helperPath.split('/').pop()
checkForUpdates()
const exeFound = stdout.text.trim()
pkgManager = exeFound.split('/').pop()
} else {
console.warn("SystemUpdate: No package manager found")
}
@@ -124,8 +171,10 @@ Singleton {
onExited: (exitCode) => {
isChecking = false
if (exitCode === 0 || exitCode === 1) {
// Exit code 0 = updates available, 1 = no updates
const correctExitCodes = updChecker.length > 0 ?
[updChecker].concat(updateCheckerParams[updChecker].listUpdatesSettings.correctExitCodes) :
[pkgManager].concat(packageManagerParams[pkgManager].listUpdatesSettings.correctExitCodes)
if (correctExitCodes.includes(exitCode)) {
parseUpdates(stdout.text)
hasError = false
errorMessage = ""
@@ -147,11 +196,15 @@ Singleton {
}
function checkForUpdates() {
if (!distributionSupported || !pkgManager || isChecking) return
if (!distributionSupported || (!pkgManager || !updChecker) || isChecking) return
isChecking = true
hasError = false
updateChecker.command = [pkgManager].concat(packageManagerParams[pkgManager].listUpdatesParams)
if (updChecker.length > 0) {
updateChecker.command = [updChecker].concat(updateCheckerParams[updChecker].listUpdatesSettings.params)
} else {
updateChecker.command = [pkgManager].concat(packageManagerParams[pkgManager].listUpdatesSettings.params)
}
updateChecker.running = true
}