Skip to content

Commit c827108

Browse files
Connect install button
1 parent 21f7138 commit c827108

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

CodeEdit/Features/Settings/Pages/Extensions/ExtensionsSettingsRowView.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct ExtensionsSettingsRowView: View, Equatable {
1212
let subtitle: String
1313
let icon: String
1414
let onCancel: (() -> Void)
15+
let onInstall: (() async -> Void)
1516

1617
private let cleanedTitle: String
1718
private let cleanedSubtitle: String
@@ -26,12 +27,14 @@ struct ExtensionsSettingsRowView: View, Equatable {
2627
title: String,
2728
subtitle: String,
2829
icon: String,
29-
onCancel: @escaping (() -> Void)
30+
onCancel: @escaping (() -> Void),
31+
onInstall: @escaping () async -> Void
3032
) {
3133
self.title = title
3234
self.subtitle = subtitle
3335
self.icon = icon
3436
self.onCancel = onCancel
37+
self.onInstall = onInstall
3538

3639
self.cleanedTitle = title
3740
.replacingOccurrences(of: "-", with: " ")
@@ -117,10 +120,14 @@ struct ExtensionsSettingsRowView: View, Equatable {
117120
} else if isHovering {
118121
Button {
119122
isInstalling = true
120-
withAnimation(.linear(duration: 2)) {
121-
installProgress = 1.0
123+
withAnimation(.linear(duration: 3)) {
124+
installProgress = 0.75
122125
}
123-
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
126+
Task {
127+
await onInstall()
128+
withAnimation(.linear(duration: 1)) {
129+
installProgress = 1.0
130+
}
124131
isInstalling = false
125132
isInstalled = true
126133
isEnabled = true

CodeEdit/Features/Settings/Pages/Extensions/ExtensionsSettingsView.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import SwiftUI
99

1010
struct ExtensionsSettingsView: View {
11+
@State private var didError = false
12+
@State private var installationFailure: InstallationFailure?
1113
@State private var registryItems: [RegistryItem] = []
1214
@State private var isLoading = true
1315

@@ -27,7 +29,14 @@ struct ExtensionsSettingsView: View {
2729
title: item.name,
2830
subtitle: item.description,
2931
icon: "GitHubIcon",
30-
onCancel: { }
32+
onCancel: { },
33+
onInstall: {
34+
do {
35+
try await RegistryManager.shared.installPackage(package: item)
36+
} catch {
37+
installationFailure = InstallationFailure(error: error.localizedDescription)
38+
}
39+
}
3140
)
3241
.listRowInsets(EdgeInsets(top: 8, leading: 8, bottom: 8, trailing: 8))
3342
}
@@ -40,6 +49,15 @@ struct ExtensionsSettingsView: View {
4049
.onReceive(NotificationCenter.default.publisher(for: .RegistryUpdatedNotification)) { _ in
4150
loadRegistryItems()
4251
}
52+
.alert(
53+
"Installation Failed",
54+
isPresented: $didError,
55+
presenting: installationFailure
56+
) { _ in
57+
Button("Dismiss") { }
58+
} message: { details in
59+
Text(details.error)
60+
}
4361
}
4462

4563
private func loadRegistryItems() {
@@ -50,3 +68,8 @@ struct ExtensionsSettingsView: View {
5068
}
5169
}
5270
}
71+
72+
private struct InstallationFailure: Identifiable {
73+
let error: String
74+
let id = UUID()
75+
}

0 commit comments

Comments
 (0)