first
This commit is contained in:
47
src/store/software.ts
Normal file
47
src/store/software.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { listen } from '@tauri-apps/api/event'
|
||||
|
||||
export const useSoftwareStore = defineStore('software', {
|
||||
state: () => ({
|
||||
essentials: [] as any[],
|
||||
updates: [] as any[],
|
||||
allSoftware: [] as any[],
|
||||
loading: false
|
||||
}),
|
||||
actions: {
|
||||
async fetchEssentials() {
|
||||
this.essentials = await invoke('get_essentials')
|
||||
},
|
||||
async fetchUpdates() {
|
||||
this.loading = true
|
||||
this.updates = await invoke('get_updates')
|
||||
this.loading = false
|
||||
},
|
||||
async fetchAll() {
|
||||
this.loading = true
|
||||
this.allSoftware = await invoke('get_all_software')
|
||||
this.loading = false
|
||||
},
|
||||
async install(id: string) {
|
||||
const software = this.findSoftware(id)
|
||||
if (software) software.status = 'pending'
|
||||
await invoke('install_software', { id })
|
||||
},
|
||||
findSoftware(id: string) {
|
||||
return this.essentials.find(s => s.id === id) ||
|
||||
this.updates.find(s => s.id === id) ||
|
||||
this.allSoftware.find(s => s.id === id)
|
||||
},
|
||||
initListener() {
|
||||
listen('install-status', (event: any) => {
|
||||
const { id, status, progress } = event.payload
|
||||
const software = this.findSoftware(id)
|
||||
if (software) {
|
||||
software.status = status
|
||||
software.progress = progress
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user