fix bad data update

This commit is contained in:
SrGooglo 2024-01-25 23:12:01 +01:00
parent 33f73fefbb
commit 0774fbed8c
3 changed files with 36 additions and 5 deletions

View File

@ -119,8 +119,13 @@ export default async function apply(pkg_id, changes) {
await updateInstalledPackage(pkg)
sendToRender(`new:notification`, {
type: "success",
message: "Changes applied!",
})
sendToRender(`pkg:update:status`, {
id: pkg_id,
...pkg,
status: "installed",
statusText: "Changes applied!",
})

View File

@ -7,7 +7,7 @@ import initManifest from "../../utils/initManifest"
import parseStringVars from "../../utils/parseStringVars"
import sendToRender from "../../utils/sendToRender"
export default async function execute(pkg_id) {
export default async function execute(pkg_id, { force = false } = {}) {
let pkg = await getInstalledPackages(pkg_id)
if (!pkg) {
@ -26,12 +26,38 @@ export default async function execute(pkg_id) {
if (pkg.remote_url) {
pkg = {
...pkg,
...await readManifest(pkg.remote_url, { just_read: true }),
...await readManifest(pkg, { just_read: true }),
}
}
pkg = await initManifest(pkg)
if (pkg.check_updates_after_execute === true) {
if (pkg._original_manifest) {
if ((pkg._original_manifest.version !== pkg.version) && !force) {
console.log(`[${pkg_id}] execute() | Update available (${pkg._original_manifest.version} -> ${pkg.version}). Aborting...`,)
console.log(pkg._original_manifest)
sendToRender("pkg:update_available", {
manifest: pkg._original_manifest,
current_version: pkg._original_manifest.version,
new_version: pkg.version,
})
sendToRender("pkg:update:status", {
id: pkg_id,
status: "installed",
})
return false
}
}
}
if (typeof pkg.after_execute === "function") {
await pkg.after_execute(pkg)
}
if (typeof pkg.execute === "string") {
pkg.execute = parseStringVars(pkg.execute, pkg)

View File

@ -84,7 +84,7 @@ export default async function update(pkg_id) {
// update render
sendToRender(`pkg:update:status`, {
id: pkg_id,
...pkg,
status: "installed",
})
@ -97,7 +97,7 @@ export default async function update(pkg_id) {
} catch (error) {
// update render
sendToRender(`pkg:update:status`, {
id: pkg_id,
...pkg,
status: "error",
statusText: error.toString(),
})