mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-19 22:09:37 +00:00
72 lines
1.5 KiB
TypeScript
72 lines
1.5 KiB
TypeScript
import { useAsyncState } from '@vueuse/core'
|
|
import { defineStore } from 'pinia'
|
|
|
|
import type { SystemStats } from '@/schemas/apiSchema'
|
|
import { api } from '@/scripts/api'
|
|
import { isElectron } from '@/utils/envUtil'
|
|
|
|
export const useSystemStatsStore = defineStore('systemStats', () => {
|
|
const fetchSystemStatsData = async () => {
|
|
try {
|
|
return await api.getSystemStats()
|
|
} catch (err) {
|
|
console.error('Error fetching system stats:', err)
|
|
throw err
|
|
}
|
|
}
|
|
|
|
const {
|
|
state: systemStats,
|
|
isLoading,
|
|
error,
|
|
isReady: isInitialized,
|
|
execute: refetchSystemStats
|
|
} = useAsyncState<SystemStats | null>(
|
|
fetchSystemStatsData,
|
|
null, // initial value
|
|
{
|
|
immediate: true
|
|
}
|
|
)
|
|
|
|
function getFormFactor(): string {
|
|
if (!systemStats.value?.system?.os) {
|
|
return 'other'
|
|
}
|
|
|
|
const os = systemStats.value.system.os.toLowerCase()
|
|
const isDesktop = isElectron()
|
|
|
|
if (isDesktop) {
|
|
if (os.includes('windows')) {
|
|
return 'desktop-windows'
|
|
}
|
|
if (os.includes('darwin') || os.includes('mac')) {
|
|
return 'desktop-mac'
|
|
}
|
|
} else {
|
|
// Git/source installation
|
|
if (os.includes('windows')) {
|
|
return 'git-windows'
|
|
}
|
|
if (os.includes('darwin') || os.includes('mac')) {
|
|
return 'git-mac'
|
|
}
|
|
if (os.includes('linux')) {
|
|
return 'git-linux'
|
|
}
|
|
}
|
|
|
|
return 'other'
|
|
}
|
|
|
|
return {
|
|
systemStats,
|
|
isLoading,
|
|
error,
|
|
isInitialized,
|
|
refetchSystemStats,
|
|
getFormFactor
|
|
}
|
|
})
|