Files
ComfyUI_frontend/src/workbench/extensions/manager/composables/nodePack/usePackUpdateStatus.ts
Comfy Org PR Bot 36027a858f [backport core/1.35] feat(manager): add Try Update button for nightly packs (#7635)
Backport of #7610 to `core/1.35`

Automatically created by backport workflow.

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-7635-backport-core-1-35-feat-manager-add-Try-Update-button-for-nightly-packs-2ce6d73d36508135a070e17689cee5e7)
by [Unito](https://www.unito.io)

Co-authored-by: Johnpaul Chiwetelu <49923152+Myestery@users.noreply.github.com>
2025-12-19 17:21:11 -07:00

58 lines
1.8 KiB
TypeScript

import { toValue } from '@vueuse/core'
import { compare, valid } from 'semver'
import type { MaybeRefOrGetter } from 'vue'
import { computed } from 'vue'
import type { components } from '@/types/comfyRegistryTypes'
import { useComfyManagerStore } from '@/workbench/extensions/manager/stores/comfyManagerStore'
export const usePackUpdateStatus = (
nodePackSource: MaybeRefOrGetter<components['schemas']['Node']>
) => {
const { isPackInstalled, isPackEnabled, getInstalledPackVersion } =
useComfyManagerStore()
// Use toValue to unwrap the source reactively inside computeds
const nodePack = computed(() => toValue(nodePackSource))
const isInstalled = computed(() => isPackInstalled(nodePack.value?.id))
const isEnabled = computed(() => isPackEnabled(nodePack.value?.id))
const installedVersion = computed(() =>
getInstalledPackVersion(nodePack.value?.id ?? '')
)
const latestVersion = computed(() => nodePack.value?.latest_version?.version)
const isNightlyPack = computed(
() => !!installedVersion.value && !valid(installedVersion.value)
)
const isUpdateAvailable = computed(() => {
if (
!isInstalled.value ||
isNightlyPack.value ||
!latestVersion.value ||
!installedVersion.value
) {
return false
}
return compare(latestVersion.value, installedVersion.value) > 0
})
/**
* Nightly packs can always "try update" since we cannot compare git hashes
* to determine if an update is actually available. This allows users to
* pull the latest changes from the repository.
*/
const canTryNightlyUpdate = computed(
() => isInstalled.value && isEnabled.value && isNightlyPack.value
)
return {
isUpdateAvailable,
isNightlyPack,
canTryNightlyUpdate,
installedVersion,
latestVersion
}
}