Skip to content

Commit 9288320

Browse files
committed
Merge branch 'feature/warn-to-restart-xpc-service' into develop
2 parents 53d05fe + 92579f9 commit 9288320

11 files changed

Lines changed: 45 additions & 6 deletions

File tree

Config.debug.xcconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
#include "Version.xcconfig"
2+
13
BUNDLE_IDENTIFIER_BASE = dev.com.intii.CopilotForXcode
24
EXTENSION_BUNDLE_NAME = Copilot Dev

Config.xcconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
#include "Version.xcconfig"
2+
13
BUNDLE_IDENTIFIER_BASE = com.intii.CopilotForXcode
24
EXTENSION_BUNDLE_NAME = Copilot

Copilot for Xcode.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
C8189B202938973000C9DCDA /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
151151
C8189B222938973000C9DCDA /* Copilot_for_Xcode.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Copilot_for_Xcode.entitlements; sourceTree = "<group>"; };
152152
C8189B282938979000C9DCDA /* Core */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Core; sourceTree = "<group>"; };
153+
C81E867D296FE4420026E908 /* Version.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Version.xcconfig; sourceTree = "<group>"; };
153154
C832A47B2940C71D000989F2 /* copilot */ = {isa = PBXFileReference; lastKnownFileType = folder; name = copilot; path = copilot.vim/copilot; sourceTree = "<group>"; };
154155
C83B2B79293D9C8C00C5ACCD /* LaunchAgentManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchAgentManager.swift; sourceTree = "<group>"; };
155156
C83B2B7B293D9FB400C5ACCD /* CopilotView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CopilotView.swift; sourceTree = "<group>"; };
@@ -246,6 +247,7 @@
246247
C832A47B2940C71D000989F2 /* copilot */,
247248
C8520308293D805800460097 /* README.md */,
248249
C887BC832965D96000931567 /* DEVELOPMENT.md */,
250+
C81E867D296FE4420026E908 /* Version.xcconfig */,
249251
C81458AD293A009600135263 /* Config.xcconfig */,
250252
C81458AE293A009800135263 /* Config.debug.xcconfig */,
251253
C8189B282938979000C9DCDA /* Core */,

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
}

DEVELOPMENT.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ Testing Real-time Suggestions is a little bit different because the Apple Script
3434

3535
Just run both the XPCService and the EditorExtension Target.
3636

37+
## App Versioning
3738

39+
The app version and all targets' version in controlled by `Version.xcconfig`.

EditorExtension/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<plist version="1.0">
44
<dict>
55
<key>CFBundleShortVersionString</key>
6-
<string>$(MARKETING_VERSION)</string>
6+
<string>$(APP_VERSION)</string>
77
<key>NSHumanReadableCopyright</key>
88
<string></string>
99
<key>CFBundleDevelopmentRegion</key>
@@ -15,7 +15,7 @@
1515
<key>CFBundleExecutable</key>
1616
<string>$(EXECUTABLE_NAME)</string>
1717
<key>CFBundleVersion</key>
18-
<string>$(CURRENT_PROJECT_VERSION)</string>
18+
<string>$(APP_BUILD)</string>
1919
<key>CFBundleInfoDictionaryVersion</key>
2020
<string>6.0</string>
2121
<key>CFBundleIdentifier</key>

Version.xcconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
APP_VERSION = 0.4.0
2+
APP_BUILD = 13

0 commit comments

Comments
 (0)