Line data Source code
1 : import { useAsyncState } from '@vueuse/core'
2 : import { defineStore } from 'pinia'
3 :
4 : import { isCloud, isDesktop } from '@/platform/distribution/types'
5 : import type { SystemStats } from '@comfyorg/api-client/types'
6 : import { api } from '@/scripts/api'
7 :
8 2356 : export const useSystemStatsStore = defineStore('systemStats', () => {
9 2355 : const fetchSystemStatsData = async () => {
10 2355 : try {
11 2355 : return await api.getSystemStats()
12 : } catch (err) {
13 0 : console.error('Error fetching system stats:', err)
14 0 : throw err
15 : }
16 : }
17 :
18 2355 : const {
19 : state: systemStats,
20 : isLoading,
21 : error,
22 : isReady: isInitialized,
23 : execute: refetchSystemStats
24 : } = useAsyncState<SystemStats | null>(
25 : fetchSystemStatsData,
26 : null, // initial value
27 : {
28 : immediate: true
29 : }
30 : )
31 :
32 4435 : function getFormFactor(): string {
33 : if (isCloud) {
34 : return 'cloud'
35 : }
36 :
37 4435 : if (!systemStats.value?.system.os) {
38 0 : return 'other'
39 : }
40 :
41 4435 : const os = systemStats.value.system.os.toLowerCase()
42 :
43 : if (isDesktop) {
44 : if (os.includes('windows')) {
45 : return 'desktop-windows'
46 : }
47 : if (os.includes('darwin') || os.includes('mac')) {
48 : return 'desktop-mac'
49 : }
50 : } else {
51 : // Git/source installation
52 4435 : if (os.includes('windows')) {
53 0 : return 'git-windows'
54 : }
55 4435 : if (os.includes('darwin') || os.includes('mac')) {
56 0 : return 'git-mac'
57 : }
58 4435 : if (os.includes('linux')) {
59 4393 : return 'git-linux'
60 : }
61 : }
62 :
63 42 : return 'other'
64 : }
65 :
66 2355 : return {
67 : systemStats,
68 : isLoading,
69 : error,
70 : isInitialized,
71 : refetchSystemStats,
72 : getFormFactor
73 : }
74 : })
|