-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathAuthStatusChecker.swift
More file actions
41 lines (36 loc) · 1.14 KB
/
AuthStatusChecker.swift
File metadata and controls
41 lines (36 loc) · 1.14 KB
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()
DispatchQueue.main.async {
notify(status.description, status == .ok)
}
} catch {
DispatchQueue.main.async {
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
}
}