Skip to content

Commit 13e297c

Browse files
committed
refactor(ai-providers): show provider name in on-device attribution and share the System Settings opener
1 parent 3667d72 commit 13e297c

4 files changed

Lines changed: 25 additions & 28 deletions

File tree

TablePro/Core/AI/AppleIntelligence/AppleIntelligenceAvailability.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@
33
// TablePro
44
//
55

6+
import AppKit
67
import Foundation
78
#if canImport(FoundationModels)
89
import FoundationModels
910
#endif
1011

1112
enum AppleIntelligenceAvailability {
13+
static func openSystemSettings() {
14+
let identifiers = [
15+
"x-apple.systempreferences:com.apple.Siri-Settings.extension",
16+
"x-apple.systempreferences:"
17+
]
18+
for identifier in identifiers {
19+
if let url = URL(string: identifier), NSWorkspace.shared.open(url) {
20+
return
21+
}
22+
}
23+
}
24+
1225
static func currentStatus() -> AppleIntelligenceStatus {
1326
#if canImport(FoundationModels)
1427
guard #available(macOS 26, *) else { return .osNotSupported }

TablePro/Views/AIChat/AIChatMessageView.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ struct AIChatMessageView: View {
2323
}
2424
}
2525

26+
private var modelLabel: String? {
27+
guard let modelId = message.modelId, !modelId.isEmpty else { return nil }
28+
if modelId == AIProviderType.appleIntelligenceModelID {
29+
return AIProviderType.appleIntelligence.displayName
30+
}
31+
return modelId
32+
}
33+
2634
var body: some View {
2735
VStack(alignment: .leading, spacing: 4) {
2836
if message.role == .user {
@@ -77,8 +85,8 @@ struct AIChatMessageView: View {
7785
.buttonStyle(.plain)
7886
.foregroundStyle(.secondary)
7987
}
80-
if let modelId = message.modelId, !modelId.isEmpty {
81-
Text(modelId)
88+
if let modelLabel {
89+
Text(modelLabel)
8290
.font(.caption2)
8391
.foregroundStyle(.tertiary)
8492
.lineLimit(1)

TablePro/Views/Settings/AIProviderDetailSheet.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ struct AIProviderDetailSheet: View {
161161
}
162162
if appleIntelligenceStatus.canOpenSystemSettings {
163163
Button(String(localized: "Open System Settings")) {
164-
openAppleIntelligenceSystemSettings()
164+
AppleIntelligenceAvailability.openSystemSettings()
165165
}
166166
}
167167
} header: {
@@ -173,18 +173,6 @@ struct AIProviderDetailSheet: View {
173173
}
174174
}
175175

176-
private func openAppleIntelligenceSystemSettings() {
177-
let identifiers = [
178-
"x-apple.systempreferences:com.apple.Siri-Settings.extension",
179-
"x-apple.systempreferences:"
180-
]
181-
for identifier in identifiers {
182-
if let url = URL(string: identifier), NSWorkspace.shared.open(url) {
183-
return
184-
}
185-
}
186-
}
187-
188176
private var apiKeyAuthSection: some View {
189177
Section {
190178
SecureField(String(localized: "API Key"), text: $apiKey)

TablePro/Views/Settings/AISettingsView.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,7 @@ struct AISettingsView: View {
234234
return
235235
}
236236
if appleIntelligenceStatus.canOpenSystemSettings {
237-
openAppleIntelligenceSystemSettings()
238-
}
239-
}
240-
241-
private func openAppleIntelligenceSystemSettings() {
242-
let identifiers = [
243-
"x-apple.systempreferences:com.apple.Siri-Settings.extension",
244-
"x-apple.systempreferences:"
245-
]
246-
for identifier in identifiers {
247-
if let url = URL(string: identifier), NSWorkspace.shared.open(url) {
248-
return
249-
}
237+
AppleIntelligenceAvailability.openSystemSettings()
250238
}
251239
}
252240

0 commit comments

Comments
 (0)