Skip to content

Commit 7245e9c

Browse files
committed
Display XPC Service version in app, warn if outdated.
1 parent 111edb7 commit 7245e9c

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

Copilot for Xcode/CopilotView.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ struct CopilotView: View {
1212
@State var version: String?
1313
@State var isRunningAction: Bool = false
1414
@State var isUserCodeCopiedAlertPresented = false
15+
@State var xpcServiceVersion: String?
16+
var shouldRestartXPCService: Bool {
17+
xpcServiceVersion != (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String)
18+
}
1519

1620
var body: some View {
1721
Section {
@@ -20,7 +24,8 @@ struct CopilotView: View {
2024
Text("Copilot")
2125
.font(.title)
2226
.padding(.bottom, 12)
23-
Text("Version: \(version ?? "Loading..")")
27+
Text("XPCService Version: \(xpcServiceVersion ?? "Loading..")")
28+
Text("Copilot Version: \(version ?? "Loading..")")
2429
Text("Status: \(copilotStatus?.description ?? "Loading..")")
2530
HStack(alignment: .center) {
2631
Button("Refresh") { checkStatus() }
@@ -74,9 +79,12 @@ struct CopilotView: View {
7479
defer { isRunningAction = false }
7580
do {
7681
let service = try getService()
82+
xpcServiceVersion = try await service.getXPCServiceVersion().version
7783
copilotStatus = try await service.checkStatus()
7884
version = try await service.getVersion()
79-
message = nil
85+
message = shouldRestartXPCService
86+
? "Please restart XPC Service to update it to the latest version."
87+
: nil
8088
isRunningAction = false
8189
} catch {
8290
message = error.localizedDescription
@@ -159,9 +167,9 @@ struct ActivityIndicatorView: NSViewRepresentable {
159167
struct CopilotView_Previews: PreviewProvider {
160168
static var previews: some View {
161169
VStack(alignment: .leading, spacing: 8) {
162-
CopilotView(copilotStatus: .notSignedIn, version: "1.0.0")
170+
CopilotView(copilotStatus: .notSignedIn, version: "1.0.0", xpcServiceVersion: "0.0.0")
163171

164-
CopilotView(copilotStatus: .alreadySignedIn, message: "Error")
172+
CopilotView(copilotStatus: .alreadySignedIn, message: "Error", xpcServiceVersion: Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "")
165173

166174
CopilotView(copilotStatus: .alreadySignedIn, isRunningAction: true)
167175
}

Core/Sources/Client/AsyncXPCService.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public struct AsyncXPCService {
2424
}
2525
}
2626
}
27+
28+
public func getXPCServiceVersion() async throws -> (version: String, build: String) {
29+
try await withXPCServiceConnected(connection: connection) {
30+
service, continuation in
31+
service.getXPCServiceVersion { version, build in
32+
continuation.resume((version, build))
33+
}
34+
}
35+
}
2736

2837
public func getVersion() async throws -> String {
2938
try await withXPCServiceConnected(connection: connection) {

Core/Sources/Service/XPCService.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import XPCShared
1414
var workspaces = [URL: Workspace]()
1515

1616
public class XPCService: NSObject, XPCServiceProtocol {
17+
public func getXPCServiceVersion(withReply reply: @escaping (String, String) -> Void) {
18+
reply(
19+
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "N/A",
20+
Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "N/A")
21+
}
22+
1723
@ServiceActor
1824
lazy var authService: CopilotAuthServiceType = Environment.createAuthService()
1925

Core/Sources/XPCShared/XPCServiceProtocol.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ public protocol XPCServiceProtocol {
4343
editorContent: Data,
4444
withReply reply: @escaping () -> Void
4545
)
46+
47+
func getXPCServiceVersion(withReply reply: @escaping (String, String) -> Void)
4648
}

0 commit comments

Comments
 (0)