mirror of
https://github.com/EasyTier/EasyTier.git
synced 2024-11-16 03:32:43 +08:00
🎈 perf: func
This commit is contained in:
parent
da0777293f
commit
bf6b46ec8e
|
@ -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>> {
|
||||
|
|
|
@ -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]
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user