🎈 perf: func

This commit is contained in:
m1m1sha 2024-05-08 19:09:39 +08:00
parent da0777293f
commit bf6b46ec8e
2 changed files with 13 additions and 12 deletions

View File

@ -2,15 +2,15 @@ import { invoke } from '@tauri-apps/api/tauri'
import type { NetworkConfig, NetworkInstanceRunningInfo } from '~/types/network'
export async function parseNetworkConfig(cfg: NetworkConfig): Promise<string> {
return await invoke('parse_network_config', { cfg: JSON.stringify(cfg) })
return invoke<string>('parse_network_config', { cfg: JSON.stringify(cfg) })
}
export async function runNetworkInstance(cfg: NetworkConfig): Promise<string> {
return await invoke<string>('run_network_instance', { cfg: JSON.stringify(cfg) })
return invoke<string>('run_network_instance', { cfg: JSON.stringify(cfg) })
}
export async function retainNetworkInstance(instanceIds: string[]): Promise<string> {
return await invoke<string>('retain_network_instance', { instanceIds: JSON.stringify(instanceIds) })
return invoke<string>('retain_network_instance', { instanceIds: JSON.stringify(instanceIds) })
}
export async function collectNetworkInfos(): Promise<Record<string, NetworkInstanceRunningInfo>> {

View File

@ -73,18 +73,19 @@ export const useNetworkStore = defineStore('networkStore', {
},
loadFromLocalStorage() {
const networkList = JSON.parse(localStorage.getItem('networkList') || '[]')
const result = []
for (const cfg of networkList) {
result.push({
...DEFAULT_NETWORK_CONFIG,
...cfg,
let networkList: NetworkConfig[]
try {
networkList = JSON.parse(localStorage.getItem('networkList') || '[]')
networkList = networkList.map((cfg) => {
return { ...DEFAULT_NETWORK_CONFIG(), ...cfg } as NetworkConfig
})
}
if (result.length === 0)
result.push(DEFAULT_NETWORK_CONFIG)
catch {
networkList = [DEFAULT_NETWORK_CONFIG()]
}
this.networkList = result
this.networkList = networkList
this.curNetwork = this.networkList[0]
},