|
| 1 | +import Client |
1 | 2 | import Preferences |
2 | 3 | import SharedUIComponents |
3 | 4 | import SwiftUI |
| 5 | +import XPCShared |
4 | 6 |
|
5 | 7 | #if canImport(ProHostApp) |
6 | 8 | import ProHostApp |
@@ -30,7 +32,45 @@ struct SuggestionSettingsView: View { |
30 | 32 | var acceptSuggestionWithTab |
31 | 33 | @AppStorage(\.isSuggestionSenseEnabled) |
32 | 34 | var isSuggestionSenseEnabled |
33 | | - init() {} |
| 35 | + |
| 36 | + var refreshExtensionSuggestionFeatureProvidersTask: Task<Void, Never>? |
| 37 | + |
| 38 | + @MainActor |
| 39 | + @Published var extensionSuggestionFeatureProviders = [ExtensionSuggestionFeatureProvider]() |
| 40 | + |
| 41 | + init() { |
| 42 | + Task { @MainActor in |
| 43 | + refreshExtensionSuggestionFeatureProviders() |
| 44 | + } |
| 45 | + refreshExtensionSuggestionFeatureProvidersTask = Task { [weak self] in |
| 46 | + let sequence = await NotificationCenter.default |
| 47 | + .notifications(named: NSApplication.didBecomeActiveNotification) |
| 48 | + for await _ in sequence { |
| 49 | + guard let self else { return } |
| 50 | + await MainActor.run { |
| 51 | + self.refreshExtensionSuggestionFeatureProviders() |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + struct ExtensionSuggestionFeatureProvider: Identifiable { |
| 58 | + var id: String { bundleIdentifier } |
| 59 | + var name: String |
| 60 | + var bundleIdentifier: String |
| 61 | + } |
| 62 | + |
| 63 | + @MainActor |
| 64 | + func refreshExtensionSuggestionFeatureProviders() { |
| 65 | + guard let service = try? getService() else { return } |
| 66 | + Task { @MainActor in |
| 67 | + let services = try await service |
| 68 | + .send(requestBody: ExtensionServiceRequests.GetExtensionSuggestionServices()) |
| 69 | + extensionSuggestionFeatureProviders = services.map { |
| 70 | + .init(name: $0.name, bundleIdentifier: $0.bundleIdentifier) |
| 71 | + } |
| 72 | + } |
| 73 | + } |
34 | 74 | } |
35 | 75 |
|
36 | 76 | @StateObject var settings = Settings() |
@@ -61,6 +101,13 @@ struct SuggestionSettingsView: View { |
61 | 101 | Text("Codeium").tag(SuggestionFeatureProvider.builtIn($0)) |
62 | 102 | } |
63 | 103 | } |
| 104 | + |
| 105 | + ForEach(settings.extensionSuggestionFeatureProviders, id: \.id) { |
| 106 | + Text($0.name).tag(SuggestionFeatureProvider.extension( |
| 107 | + name: $0.name, |
| 108 | + bundleIdentifier: $0.bundleIdentifier |
| 109 | + )) |
| 110 | + } |
64 | 111 | } label: { |
65 | 112 | Text("Feature Provider") |
66 | 113 | } |
|
0 commit comments