delete last profile

This commit is contained in:
pompurin404 2024-08-28 21:23:53 +08:00
parent cf6642d2e8
commit 4239498f57
No known key found for this signature in database

View File

@ -76,7 +76,9 @@ export async function addProfileItem(item: Partial<IProfileItem>): Promise<void>
export async function removeProfileItem(id: string): Promise<void> { export async function removeProfileItem(id: string): Promise<void> {
const config = await getProfileConfig() const config = await getProfileConfig()
config.items = config.items?.filter((item) => item.id !== id) config.items = config.items?.filter((item) => item.id !== id)
let shouldRestart = false
if (config.current === id) { if (config.current === id) {
shouldRestart = true
if (config.items.length > 0) { if (config.items.length > 0) {
config.current = config.items[0].id config.current = config.items[0].id
} else { } else {
@ -87,6 +89,9 @@ export async function removeProfileItem(id: string): Promise<void> {
if (existsSync(profilePath(id))) { if (existsSync(profilePath(id))) {
await rm(profilePath(id)) await rm(profilePath(id))
} }
if (shouldRestart) {
await restartCore()
}
} }
export async function getCurrentProfileItem(): Promise<IProfileItem> { export async function getCurrentProfileItem(): Promise<IProfileItem> {