diff --git a/ApplicationLibrary/Views/Profile/ImportProfileViewModel.swift b/ApplicationLibrary/Views/Profile/ImportProfileViewModel.swift index 292f2b2..1bf8d76 100644 --- a/ApplicationLibrary/Views/Profile/ImportProfileViewModel.swift +++ b/ApplicationLibrary/Views/Profile/ImportProfileViewModel.swift @@ -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() diff --git a/ApplicationLibrary/Views/Profile/NewProfileMenuView.swift b/ApplicationLibrary/Views/Profile/NewProfileMenuView.swift index 39b553f..ab8f41b 100644 --- a/ApplicationLibrary/Views/Profile/NewProfileMenuView.swift +++ b/ApplicationLibrary/Views/Profile/NewProfileMenuView.swift @@ -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") } diff --git a/Library/Database/Profile+Transferable.swift b/Library/Database/Profile+Transferable.swift index 5e63f36..6bfab3d 100644 --- a/Library/Database/Profile+Transferable.swift +++ b/Library/Database/Profile+Transferable.swift @@ -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 {