mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-20 06:44:32 +00:00
[Desktop] Startup maintenance screen (#2253)
Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
29
src/utils/refUtil.ts
Normal file
29
src/utils/refUtil.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useTimeout } from '@vueuse/core'
|
||||
import { type Ref, computed, ref, watch } from 'vue'
|
||||
|
||||
/**
|
||||
* Vue boolean ref (writable computed) with one difference: when set to `true` it stays that way for at least {@link minDuration}.
|
||||
* If set to `false` before {@link minDuration} has passed, it uses a timer to delay the change.
|
||||
* @param value The default value to set on this ref
|
||||
* @param minDuration The minimum time that this ref must be `true` for
|
||||
* @returns A custom boolean vue ref with a minimum activation time
|
||||
*/
|
||||
export function useMinLoadingDurationRef(
|
||||
value: Ref<boolean>,
|
||||
minDuration = 250
|
||||
) {
|
||||
const current = ref(value.value)
|
||||
|
||||
const { ready, start } = useTimeout(minDuration, {
|
||||
controls: true,
|
||||
immediate: false
|
||||
})
|
||||
|
||||
watch(value, (newValue) => {
|
||||
if (newValue && !current.value) start()
|
||||
|
||||
current.value = newValue
|
||||
})
|
||||
|
||||
return computed(() => current.value || !ready.value)
|
||||
}
|
||||
Reference in New Issue
Block a user