Skip to content

Commit d6a31b7

Browse files
committed
Remove GitHub Copilot authentication code from XPCService
1 parent 94398f6 commit d6a31b7

File tree

5 files changed

+63
-214
lines changed

5 files changed

+63
-214
lines changed

Copilot for Xcode/CopilotView.swift

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ struct CopilotView: View {
7979
isRunningAction = true
8080
defer { isRunningAction = false }
8181
do {
82-
let service = try getService()
83-
xpcServiceVersion = try await service.getXPCServiceVersion().version
84-
copilotStatus = try await service.checkStatus()
85-
version = try await service.getVersion()
86-
message = shouldRestartXPCService
87-
? "Please restart XPC Service to update it to the latest version."
88-
: nil
89-
isRunningAction = false
82+
// let service = try getService()
83+
// xpcServiceVersion = try await service.getXPCServiceVersion().version
84+
// copilotStatus = try await service.checkStatus()
85+
// version = try await service.getVersion()
86+
// message = shouldRestartXPCService
87+
// ? "Please restart XPC Service to update it to the latest version."
88+
// : nil
89+
// isRunningAction = false
9090
} catch {
9191
message = error.localizedDescription
9292
}
@@ -98,19 +98,19 @@ struct CopilotView: View {
9898
isRunningAction = true
9999
defer { isRunningAction = false }
100100
do {
101-
let service = try getService()
102-
let (uri, userCode) = try await service.signInInitiate()
103-
self.userCode = userCode
104-
guard let url = URL(string: uri) else {
105-
message = "Verification URI is incorrect."
106-
return
107-
}
108-
let pasteboard = NSPasteboard.general
109-
pasteboard.declareTypes([NSPasteboard.PasteboardType.string], owner: nil)
110-
pasteboard.setString(userCode, forType: NSPasteboard.PasteboardType.string)
111-
message = "Usercode \(userCode) already copied!"
112-
openURL(url)
113-
isUserCodeCopiedAlertPresented = true
101+
// let service = try getService()
102+
// let (uri, userCode) = try await service.signInInitiate()
103+
// self.userCode = userCode
104+
// guard let url = URL(string: uri) else {
105+
// message = "Verification URI is incorrect."
106+
// return
107+
// }
108+
// let pasteboard = NSPasteboard.general
109+
// pasteboard.declareTypes([NSPasteboard.PasteboardType.string], owner: nil)
110+
// pasteboard.setString(userCode, forType: NSPasteboard.PasteboardType.string)
111+
// message = "Usercode \(userCode) already copied!"
112+
// openURL(url)
113+
// isUserCodeCopiedAlertPresented = true
114114
} catch {
115115
message = error.localizedDescription
116116
}
@@ -122,14 +122,14 @@ struct CopilotView: View {
122122
isRunningAction = true
123123
defer { isRunningAction = false }
124124
do {
125-
let service = try getService()
126-
guard let userCode else {
127-
message = "Usercode is empty."
128-
return
129-
}
130-
let (username, status) = try await service.signInConfirm(userCode: userCode)
131-
self.username = username
132-
copilotStatus = status
125+
// let service = try getService()
126+
// guard let userCode else {
127+
// message = "Usercode is empty."
128+
// return
129+
// }
130+
// let (username, status) = try await service.signInConfirm(userCode: userCode)
131+
// self.username = username
132+
// copilotStatus = status
133133
} catch {
134134
message = error.localizedDescription
135135
}
@@ -138,14 +138,14 @@ struct CopilotView: View {
138138

139139
func signOut() {
140140
Task {
141-
isRunningAction = true
142-
defer { isRunningAction = false }
143-
do {
144-
let service = try getService()
145-
copilotStatus = try await service.signOut()
146-
} catch {
147-
message = error.localizedDescription
148-
}
141+
// isRunningAction = true
142+
// defer { isRunningAction = false }
143+
// do {
144+
// let service = try getService()
145+
// copilotStatus = try await service.signOut()
146+
// } catch {
147+
// message = error.localizedDescription
148+
// }
149149
}
150150
}
151151
}

Core/Sources/Client/AsyncXPCService.swift

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,6 @@ public struct AsyncXPCService {
1212
self.service = service
1313
}
1414

15-
public func checkStatus() async throws -> GitHubCopilotAccountStatus {
16-
try await withXPCServiceConnected(connection: connection) {
17-
service, continuation in
18-
service.checkStatus { status, error in
19-
if let error {
20-
continuation.reject(error)
21-
return
22-
}
23-
continuation.resume(
24-
status.flatMap(GitHubCopilotAccountStatus.init(rawValue:))
25-
?? GitHubCopilotAccountStatus.notAuthorized
26-
)
27-
}
28-
}
29-
}
30-
3115
public func getXPCServiceVersion() async throws -> (version: String, build: String) {
3216
try await withXPCServiceConnected(connection: connection) {
3317
service, continuation in
@@ -37,67 +21,6 @@ public struct AsyncXPCService {
3721
}
3822
}
3923

40-
public func getVersion() async throws -> String {
41-
try await withXPCServiceConnected(connection: connection) {
42-
service, continuation in
43-
service.getVersion { version, error in
44-
if let error {
45-
continuation.reject(error)
46-
return
47-
}
48-
continuation.resume(version ?? "--")
49-
}
50-
}
51-
}
52-
53-
public func signInInitiate() async throws -> (verificationUri: String, userCode: String) {
54-
try await withXPCServiceConnected(connection: connection) {
55-
service, continuation in
56-
service.signInInitiate { verificationUri, userCode, error in
57-
if let error {
58-
continuation.reject(error)
59-
return
60-
}
61-
continuation.resume((verificationUri ?? "", userCode ?? ""))
62-
}
63-
}
64-
}
65-
66-
public func signInConfirm(userCode: String) async throws
67-
-> (username: String, status: GitHubCopilotAccountStatus)
68-
{
69-
try await withXPCServiceConnected(connection: connection) {
70-
service, continuation in
71-
service.signInConfirm(userCode: userCode) { username, status, error in
72-
if let error {
73-
continuation.reject(error)
74-
return
75-
}
76-
continuation.resume((
77-
username ?? "",
78-
status.flatMap(GitHubCopilotAccountStatus.init(rawValue:)) ?? .alreadySignedIn
79-
))
80-
}
81-
}
82-
}
83-
84-
public func signOut() async throws -> GitHubCopilotAccountStatus {
85-
try await withXPCServiceConnected(connection: connection) {
86-
service, continuation in
87-
service.signOut { finishstatus, error in
88-
if let error {
89-
continuation.reject(error)
90-
return
91-
}
92-
continuation
93-
.resume(
94-
finishstatus
95-
.flatMap(GitHubCopilotAccountStatus.init(rawValue:)) ?? .notSignedIn
96-
)
97-
}
98-
}
99-
}
100-
10124
public func getSuggestedCode(editorContent: EditorContent) async throws -> UpdatedContent? {
10225
try await suggestionRequest(
10326
connection,

Core/Sources/HostApp/AccountSettings/CopilotView.swift

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import SuggestionModel
66
import SwiftUI
77

88
struct CopilotView: View {
9+
static var copilotAuthService: GitHubCopilotAuthServiceType?
10+
911
class Settings: ObservableObject {
1012
@AppStorage(\.nodePath) var nodePath: String
1113
@AppStorage(\.runNodeWith) var runNodeWith
@@ -18,11 +20,18 @@ struct CopilotView: View {
1820
@Environment(\.toast) var toast
1921
@StateObject var settings = Settings()
2022

21-
@State var copilotStatus: GitHubCopilotAccountStatus?
23+
@State var status: GitHubCopilotAccountStatus?
2224
@State var userCode: String?
2325
@State var version: String?
2426
@State var isRunningAction: Bool = false
2527
@State var isUserCodeCopiedAlertPresented = false
28+
29+
func getGitHubCopilotAuthService() throws -> GitHubCopilotAuthServiceType {
30+
if let service = Self.copilotAuthService { return service }
31+
let service = try GitHubCopilotAuthService()
32+
Self.copilotAuthService = service
33+
return service
34+
}
2635

2736
var body: some View {
2837
HStack {
@@ -56,12 +65,12 @@ struct CopilotView: View {
5665
}
5766

5867
VStack(alignment: .leading) {
59-
Text("Copilot Version: \(version ?? "Loading..")")
60-
Text("Status: \(copilotStatus?.description ?? "Loading..")")
68+
Text("Language Server Version: \(version ?? "Loading..")")
69+
Text("Status: \(status?.description ?? "Loading..")")
6170

6271
HStack(alignment: .center) {
6372
Button("Refresh") { checkStatus() }
64-
if copilotStatus == .notSignedIn {
73+
if status == .notSignedIn {
6574
Button("Sign In") { signIn() }
6675
.alert(isPresented: $isUserCodeCopiedAlertPresented) {
6776
Alert(
@@ -74,8 +83,8 @@ struct CopilotView: View {
7483
}
7584
Button("Confirm Sign-in") { confirmSignIn() }
7685
}
77-
if copilotStatus == .ok || copilotStatus == .alreadySignedIn ||
78-
copilotStatus == .notAuthorized
86+
if status == .ok || status == .alreadySignedIn ||
87+
status == .notAuthorized
7988
{
8089
Button("Sign Out") { signOut() }
8190
}
@@ -105,12 +114,12 @@ struct CopilotView: View {
105114
isRunningAction = true
106115
defer { isRunningAction = false }
107116
do {
108-
let service = try getService()
109-
copilotStatus = try await service.checkStatus()
110-
version = try await service.getVersion()
117+
let service = try getGitHubCopilotAuthService()
118+
status = try await service.checkStatus()
119+
version = try await service.version()
111120
isRunningAction = false
112121

113-
if copilotStatus != .ok {
122+
if status != .ok {
114123
toast(
115124
Text(
116125
"GitHub Copilot status is not \"ok\". Please check if you have a valid GitHub Copilot subscription."
@@ -129,7 +138,7 @@ struct CopilotView: View {
129138
isRunningAction = true
130139
defer { isRunningAction = false }
131140
do {
132-
let service = try getService()
141+
let service = try getGitHubCopilotAuthService()
133142
let (uri, userCode) = try await service.signInInitiate()
134143
self.userCode = userCode
135144
guard let url = URL(string: uri) else {
@@ -153,14 +162,14 @@ struct CopilotView: View {
153162
isRunningAction = true
154163
defer { isRunningAction = false }
155164
do {
156-
let service = try getService()
165+
let service = try getGitHubCopilotAuthService()
157166
guard let userCode else {
158167
toast(Text("Usercode is empty."), .error)
159168
return
160169
}
161170
let (username, status) = try await service.signInConfirm(userCode: userCode)
162171
self.settings.username = username
163-
copilotStatus = status
172+
self.status = status
164173
} catch {
165174
toast(Text(error.localizedDescription), .error)
166175
}
@@ -172,8 +181,8 @@ struct CopilotView: View {
172181
isRunningAction = true
173182
defer { isRunningAction = false }
174183
do {
175-
let service = try getService()
176-
copilotStatus = try await service.signOut()
184+
let service = try getGitHubCopilotAuthService()
185+
status = try await service.signOut()
177186
} catch {
178187
toast(Text(error.localizedDescription), .error)
179188
}
@@ -199,8 +208,8 @@ struct ActivityIndicatorView: NSViewRepresentable {
199208
struct CopilotView_Previews: PreviewProvider {
200209
static var previews: some View {
201210
VStack(alignment: .leading, spacing: 8) {
202-
CopilotView(copilotStatus: .notSignedIn, version: "1.0.0")
203-
CopilotView(copilotStatus: .alreadySignedIn, isRunningAction: true)
211+
CopilotView(status: .notSignedIn, version: "1.0.0")
212+
CopilotView(status: .alreadySignedIn, isRunningAction: true)
204213
}
205214
.frame(height: 800)
206215
.padding(.all, 8)

Core/Sources/Service/XPCService.swift

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -29,80 +29,6 @@ public class XPCService: NSObject, XPCServiceProtocol {
2929
)
3030
}
3131

32-
// MARK: - Copilot Auth
33-
34-
@ServiceActor
35-
var _gitHubCopilotAuthService: GitHubCopilotAuthServiceType?
36-
@ServiceActor
37-
var gitHubCopilotAuthService: GitHubCopilotAuthServiceType {
38-
get throws {
39-
if let _gitHubCopilotAuthService { return _gitHubCopilotAuthService }
40-
let newService = try GitHubCopilotAuthService()
41-
_gitHubCopilotAuthService = newService
42-
return newService
43-
}
44-
}
45-
46-
public func checkStatus(withReply reply: @escaping (String?, Error?) -> Void) {
47-
Task { @ServiceActor in
48-
do {
49-
let status = try await (try gitHubCopilotAuthService).checkStatus()
50-
reply(status.rawValue, nil)
51-
} catch {
52-
reply(nil, NSError.from(error))
53-
}
54-
}
55-
}
56-
57-
public func signInInitiate(withReply reply: @escaping (String?, String?, Error?) -> Void) {
58-
Task { @ServiceActor in
59-
do {
60-
let (verificationLink, userCode) = try await (try gitHubCopilotAuthService)
61-
.signInInitiate()
62-
reply(verificationLink, userCode, nil)
63-
} catch {
64-
reply(nil, nil, NSError.from(error))
65-
}
66-
}
67-
}
68-
69-
public func signInConfirm(
70-
userCode: String,
71-
withReply reply: @escaping (String?, String?, Error?) -> Void
72-
) {
73-
Task { @ServiceActor in
74-
do {
75-
let (username, status) = try await (try gitHubCopilotAuthService)
76-
.signInConfirm(userCode: userCode)
77-
reply(username, status.rawValue, nil)
78-
} catch {
79-
reply(nil, nil, NSError.from(error))
80-
}
81-
}
82-
}
83-
84-
public func getVersion(withReply reply: @escaping (String?, Error?) -> Void) {
85-
Task { @ServiceActor in
86-
do {
87-
let version = try await gitHubCopilotAuthService.version()
88-
reply(version, nil)
89-
} catch {
90-
reply(nil, NSError.from(error))
91-
}
92-
}
93-
}
94-
95-
public func signOut(withReply reply: @escaping (String?, Error?) -> Void) {
96-
Task { @ServiceActor in
97-
do {
98-
let status = try await gitHubCopilotAuthService.signOut()
99-
reply(status.rawValue, nil)
100-
} catch {
101-
reply(nil, NSError.from(error))
102-
}
103-
}
104-
}
105-
10632
// MARK: - Suggestion
10733

10834
@discardableResult

0 commit comments

Comments
 (0)