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 isChecking: false
property bool hasError: false property bool hasError: false
property string errorMessage: "" property string errorMessage: ""
property string updChecker: ""
property string pkgManager: "" property string pkgManager: ""
property string distribution: "" property string distribution: ""
property bool distributionSupported: false property bool distributionSupported: false
property string shellVersion: "" property string shellVersion: ""
readonly property var archBasedSettings: { readonly property var archBasedUCSettings: {
"listUpdatesParams": ["-Qu"], "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": { "upgradeSettings": {
"params": ["-Syu"], "params": ["-Syu"],
"requiresSudo": false "requiresSudo": false
@@ -38,28 +60,36 @@ Singleton {
} }
} }
readonly property var packageManagerParams: { readonly property var fedoraBasedPMSettings: {
"yay": archBasedSettings, "listUpdatesSettings": {
"paru": archBasedSettings, "params": ["list", "--upgrades", "--quiet", "--color=never"],
"dnf": { "correctExitCodes": [0, 1] // Exit code 0 = updates available, 1 = no updates
"listUpdatesParams": ["list", "--upgrades", "--quiet", "--color=never"], },
"upgradeSettings": { "upgradeSettings": {
"params": ["upgrade"], "params": ["upgrade"],
"requiresSudo": true "requiresSudo": true
}, },
"parserSettings": { "parserSettings": {
"lineRegex": /^([^\s]+)\s+([^\s]+)\s+.*$/, "lineRegex": /^([^\s]+)\s+([^\s]+)\s+.*$/,
"entryProducer": function (match) { "entryProducer": function (match) {
return { return {
"name": match[1], "name": match[1],
"currentVersion": "", "currentVersion": "",
"newVersion": match[2], "newVersion": match[2],
"description": `${match[1]} ${match[2]}` "description": `${match[1]} ${match[2]}`
}
} }
} }
} }
} }
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 list<string> supportedDistributions: ["arch", "cachyos", "manjaro", "endeavouros", "fedora"]
readonly property int updateCount: availableUpdates.length readonly property int updateCount: availableUpdates.length
readonly property bool helperAvailable: pkgManager !== "" && distributionSupported readonly property bool helperAvailable: pkgManager !== "" && distributionSupported
@@ -75,7 +105,9 @@ Singleton {
distributionSupported = supportedDistributions.includes(distribution) distributionSupported = supportedDistributions.includes(distribution)
if (distributionSupported) { if (distributionSupported) {
helperDetection.running = true updateFinderDetection.running = true
pkgManagerDetection.running = true
checkForUpdates()
} else { } else {
console.warn("SystemUpdate: Unsupported distribution:", distribution) console.warn("SystemUpdate: Unsupported distribution:", distribution)
} }
@@ -98,19 +130,34 @@ Singleton {
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
shellVersion = text.trim() shellVersion = text.trim()
} }
} }
} }
Process { 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"] command: ["sh", "-c", "which paru || which yay || which dnf"]
onExited: (exitCode) => { onExited: (exitCode) => {
if (exitCode === 0) { if (exitCode === 0) {
const helperPath = stdout.text.trim() const exeFound = stdout.text.trim()
pkgManager = helperPath.split('/').pop() pkgManager = exeFound.split('/').pop()
checkForUpdates()
} else { } else {
console.warn("SystemUpdate: No package manager found") console.warn("SystemUpdate: No package manager found")
} }
@@ -124,8 +171,10 @@ Singleton {
onExited: (exitCode) => { onExited: (exitCode) => {
isChecking = false isChecking = false
if (exitCode === 0 || exitCode === 1) { const correctExitCodes = updChecker.length > 0 ?
// Exit code 0 = updates available, 1 = no updates [updChecker].concat(updateCheckerParams[updChecker].listUpdatesSettings.correctExitCodes) :
[pkgManager].concat(packageManagerParams[pkgManager].listUpdatesSettings.correctExitCodes)
if (correctExitCodes.includes(exitCode)) {
parseUpdates(stdout.text) parseUpdates(stdout.text)
hasError = false hasError = false
errorMessage = "" errorMessage = ""
@@ -147,11 +196,15 @@ Singleton {
} }
function checkForUpdates() { function checkForUpdates() {
if (!distributionSupported || !pkgManager || isChecking) return if (!distributionSupported || (!pkgManager || !updChecker) || isChecking) return
isChecking = true isChecking = true
hasError = false 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 updateChecker.running = true
} }
@@ -194,7 +247,7 @@ Singleton {
const params = packageManagerParams[pkgManager].upgradeSettings.params.join(" ") const params = packageManagerParams[pkgManager].upgradeSettings.params.join(" ")
const sudo = packageManagerParams[pkgManager].upgradeSettings.requiresSudo ? "sudo" : "" const sudo = packageManagerParams[pkgManager].upgradeSettings.requiresSudo ? "sudo" : ""
const updateCommand = `${sudo} ${pkgManager} ${params} && echo "Updates complete! Press Enter to close..." && read` const updateCommand = `${sudo} ${pkgManager} ${params} && echo "Updates complete! Press Enter to close..." && read`
updater.command = [terminal, "-e", "sh", "-c", updateCommand] updater.command = [terminal, "-e", "sh", "-c", updateCommand]
} }
updater.running = true updater.running = true