Skip to content

Commit

Permalink
Made some small refactorings.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdoe committed Jan 6, 2024
1 parent cdb1aed commit c4e206f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CCMenu/Source/Miscellaneous/WorkspaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class WorkspaceController {
NSApp.activate(ignoringOtherApps: true)
}

func openUrl(url: URL) {
NSWorkspace.shared.open(url)
}

func openWebPage(pipeline: Pipeline) {
if let error = pipeline.connectionError {
// TODO: Consider adding a UI test for this case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import SwiftUI
@MainActor
class GitHubAuthenticator: ObservableObject {
@Published var token: String?
// TODO: Consider making description as private(set) and move logic to didSet.
@Published var tokenDescription: String = ""
@Published private(set) var isWaitingForToken: Bool = false
@Environment(\.openURL) private var openUrl
Expand All @@ -20,13 +19,12 @@ class GitHubAuthenticator: ObservableObject {

let codeRequest = GitHubAPI.requestForDeviceCode()
guard let codeResponse = await fetchDeviceCode(request: codeRequest) else {
isWaitingForToken = false
tokenDescription = token ?? ""
// TODO: Consider adding error handling in fetchDeviceCode
cancelSignIn()
return
}
if !startDeviceFlowOnWebsite(response: codeResponse) {
isWaitingForToken = false
tokenDescription = token ?? ""
cancelSignIn()
return
}

Expand Down Expand Up @@ -55,7 +53,11 @@ class GitHubAuthenticator: ObservableObject {
}
NSPasteboard.general.prepareForNewContents()
NSPasteboard.general.setString(response.userCode, forType: .string)
openUrl(URL(string: response.verificationUri)!) // TODO: Find out how to call this outside a view
guard let url = URL(string: response.verificationUri) else {
// TODO: Consider adding error handling. But will GH really send a bad URL?
return false
}
WorkspaceController().openUrl(url: url)
return true
}

Expand Down Expand Up @@ -117,8 +119,7 @@ class GitHubAuthenticator: ObservableObject {
}

func openApplicationsOnWebsite() {
openUrl(GitHubAPI.applicationsUrl()) // TODO: Find out how to call this outside a view
WorkspaceController().openUrl(url: GitHubAPI.applicationsUrl())
}


}

0 comments on commit c4e206f

Please sign in to comment.