forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAuthStatusChecker.swift
41 lines (36 loc) · 1.13 KB
/
AuthStatusChecker.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// AuthStatusChecker.swift
// ExtensionService
//
// Responsible for checking the logged in status of the user.
//
import Foundation
import GitHubCopilotService
class AuthStatusChecker {
var authService: GitHubCopilotAuthServiceType?
public func updateStatusInBackground(notify: @escaping (_ status: String, _ isOk: Bool) -> Void) {
Task {
do {
let status = try await self.getCurrentAuthStatus()
await MainActor.run {
notify(status.description, status == .ok)
}
} catch {
await MainActor.run {
notify("\(error)", false)
}
}
}
}
func getCurrentAuthStatus() async throws -> GitHubCopilotAccountStatus {
let service = try getAuthService()
let status = try await service.checkStatus()
return status
}
func getAuthService() throws -> GitHubCopilotAuthServiceType {
if let service = authService { return service }
let service = try GitHubCopilotService()
authService = service
return service
}
}