Auto-select newly created or imported profile
This commit is contained in:
@@ -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,10 +82,16 @@ public struct NewProfileMenuView: View {
|
||||
private var otherBody: some View {
|
||||
Group {
|
||||
if let request = importRequest {
|
||||
NewProfileView(request)
|
||||
NewProfileView(request, onSuccess: { profile in
|
||||
await SharedPreferences.selectedProfileID.set(profile.mustID)
|
||||
dismiss()
|
||||
})
|
||||
.environmentObject(environments)
|
||||
} else if let request = localImportRequest {
|
||||
NewProfileView(localImportRequest: request)
|
||||
NewProfileView(localImportRequest: request, onSuccess: { profile in
|
||||
await SharedPreferences.selectedProfileID.set(profile.mustID)
|
||||
dismiss()
|
||||
})
|
||||
.environmentObject(environments)
|
||||
} else {
|
||||
menuContent
|
||||
@@ -156,7 +164,10 @@ public struct NewProfileMenuView: View {
|
||||
}
|
||||
#else
|
||||
FormNavigationLink {
|
||||
NewProfileView()
|
||||
NewProfileView(onSuccess: { profile in
|
||||
await SharedPreferences.selectedProfileID.set(profile.mustID)
|
||||
dismiss()
|
||||
})
|
||||
.environmentObject(environments)
|
||||
} label: {
|
||||
Label("Create Manually", systemImage: "square.and.pencil")
|
||||
|
||||
@@ -42,7 +42,8 @@ public extension LibboxProfileContent {
|
||||
return content!
|
||||
}
|
||||
|
||||
func importProfile() async throws {
|
||||
@discardableResult
|
||||
func importProfile() async throws -> Profile {
|
||||
let nextProfileID = try await ProfileManager.nextID()
|
||||
let profileConfigDirectory = FilePath.sharedDirectory.appendingPathComponent("configs", isDirectory: true)
|
||||
try FileManager.default.createDirectory(at: profileConfigDirectory, withIntermediateDirectories: true)
|
||||
@@ -53,7 +54,10 @@ public extension LibboxProfileContent {
|
||||
lastUpdatedAt = Date(timeIntervalSince1970: Double(lastUpdated))
|
||||
}
|
||||
let uniqueProfileName = try await ProfileManager.uniqueName(name)
|
||||
try await ProfileManager.create(Profile(name: uniqueProfileName, type: ProfileType(rawValue: Int(type))!, path: profileConfig.relativePath, remoteURL: remotePath, autoUpdate: autoUpdate, autoUpdateInterval: autoUpdateInterval, lastUpdated: lastUpdatedAt))
|
||||
let profile = Profile(name: uniqueProfileName, type: ProfileType(rawValue: Int(type))!, path: profileConfig.relativePath, remoteURL: remotePath, autoUpdate: autoUpdate, autoUpdateInterval: autoUpdateInterval, lastUpdated: lastUpdatedAt)
|
||||
try await ProfileManager.create(profile)
|
||||
await SharedPreferences.selectedProfileID.set(profile.mustID)
|
||||
return profile
|
||||
}
|
||||
|
||||
func generateShareFile() throws -> URL {
|
||||
|
||||
Reference in New Issue
Block a user