Skip to content

Commit

Permalink
feat: add alert and backup feature for incompatible profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayideyia committed Dec 22, 2024
1 parent 613177d commit 9a01adf
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions frontend/src/stores/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parse, stringify } from 'yaml'
import { debounce, ignoredError } from '@/utils'
import { Readfile, Writefile } from '@/bridge'
import { ProfilesFilePath, ProxyGroup, FinalDnsType } from '@/constant'
import { useAlert } from '@/hooks'

export type ProfileType = {
id: string
Expand Down Expand Up @@ -117,6 +118,22 @@ export const useProfilesStore = defineStore('profiles', () => {
const data = await ignoredError(Readfile, ProfilesFilePath)
data && (profiles.value = parse(data))

const profilesCount = profiles.value.length

profiles.value = profiles.value.filter((profile) => {
return !(profile as any).route
})

if (profilesCount !== profiles.value.length) {
const { alert } = useAlert()
const filteredProfiles = profiles.value.filter((profile) => (profile as any).route)
Writefile('data/.cache/latest-profiles.yaml', stringify(filteredProfiles))
alert(
'Tip',
'The incompatible profiles has been saved to the file: data/.cache/profiles-backup.yaml.'
)
}

// compatibility code
profiles.value.forEach((profile) => {
if (!profile.tunConfig['address']) {
Expand Down

0 comments on commit 9a01adf

Please sign in to comment.