mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-27 03:19:56 +00:00
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>
58 lines
1.8 KiB
TypeScript
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
|
|
}
|
|
}
|