Auto-select newly created or imported profile

This commit is contained in:
世界
2025-12-07 18:12:47 +08:00
parent 9b25243b6a
commit 2da9397ef6
3 changed files with 28 additions and 11 deletions
@@ -143,7 +143,9 @@
lastUpdated = Date(timeIntervalSince1970: Double(content.lastUpdated))
}
let uniqueProfileName = try await ProfileManager.uniqueName(content.name)
try await ProfileManager.create(Profile(name: uniqueProfileName, type: type, path: profileConfig.relativePath, remoteURL: content.remotePath, autoUpdate: content.autoUpdate, lastUpdated: lastUpdated))
let profile = Profile(name: uniqueProfileName, type: type, path: profileConfig.relativePath, remoteURL: content.remotePath, autoUpdate: content.autoUpdate, lastUpdated: lastUpdated)
try await ProfileManager.create(profile)
await SharedPreferences.selectedProfileID.set(profile.mustID)
await reset()
await MainActor.run {
environments.profileUpdate.send()
@@ -63,13 +63,15 @@ public struct NewProfileMenuView: View {
handleFileImport(result)
}
.sheet(isPresented: $showNewProfile) {
NewProfileView(onSuccess: { _ in
NewProfileView(onSuccess: { profile in
await SharedPreferences.selectedProfileID.set(profile.mustID)
dismiss()
})
.environmentObject(environments)
}
.sheet(item: $localImportRequest) { request in
NewProfileView(localImportRequest: request, onSuccess: { _ in
NewProfileView(localImportRequest: request, onSuccess: { profile in
await SharedPreferences.selectedProfileID.set(profile.mustID)
dismiss()
})
.environmentObject(environments)
@@ -80,11 +82,17 @@ public struct NewProfileMenuView: View {
private var otherBody: some View {
Group {
if let request = importRequest {
NewProfileView(request)
.environmentObject(environments)
NewProfileView(request, onSuccess: { profile in
await SharedPreferences.selectedProfileID.set(profile.mustID)
dismiss()
})
.environmentObject(environments)
} else if let request = localImportRequest {
NewProfileView(localImportRequest: request)
.environmentObject(environments)
NewProfileView(localImportRequest: request, onSuccess: { profile in
await SharedPreferences.selectedProfileID.set(profile.mustID)
dismiss()
})
.environmentObject(environments)
} else {
menuContent
}
@@ -156,8 +164,11 @@ public struct NewProfileMenuView: View {
}
#else
FormNavigationLink {
NewProfileView()
.environmentObject(environments)
NewProfileView(onSuccess: { profile in
await SharedPreferences.selectedProfileID.set(profile.mustID)
dismiss()
})
.environmentObject(environments)
} label: {
Label("Create Manually", systemImage: "square.and.pencil")
}