Skip to content

Commit

Permalink
Merge pull request #33 from menubar-apps/add-sequoia-support
Browse files Browse the repository at this point in the history
Fix TabView in Preferences
  • Loading branch information
streetturtle authored Nov 16, 2024
2 parents 00fe133 + 21800f6 commit 0ff4449
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 51 deletions.
44 changes: 16 additions & 28 deletions pullBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,7 @@ import KeychainAccess

@main
class AppDelegate: NSObject, NSApplicationDelegate {

@Default(.showAssigned) var showAssigned
@Default(.showCreated) var showCreated
@Default(.showRequested) var showRequested

@Default(.showAvatar) var showAvatar
@Default(.showLabels) var showLabels

@Default(.refreshRate) var refreshRate
@Default(.buildType) var buildType
@Default(.counterType) var counterType

@Default(.githubUsername) var githubUsername

@FromKeychain(.githubToken) var githubToken

let ghClient = GitHubClient()
Expand All @@ -51,7 +39,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
statusBarItem.menu = menu

timer = Timer.scheduledTimer(
timeInterval: Double(refreshRate * 60),
timeInterval: Double(Defaults[.refreshRate] * 60),
target: self,
selector: #selector(refreshMenu),
userInfo: nil,
Expand Down Expand Up @@ -86,7 +74,7 @@ extension AppDelegate {
NSLog("Refreshing menu")
self.menu.removeAllItems()

if (githubUsername == "" || githubToken == "") {
if (Defaults[.githubUsername] == "" || githubToken == "") {
addMenuFooterItems()
return
}
Expand All @@ -99,23 +87,23 @@ extension AppDelegate {

let group = DispatchGroup()

if showAssigned {
if Defaults[.showAssigned] {
group.enter()
ghClient.getAssignedPulls() { pulls in
assignedPulls?.append(contentsOf: pulls)
group.leave()
}
}

if showCreated {
if Defaults[.showCreated] {
group.enter()
ghClient.getCreatedPulls() { pulls in
createdPulls?.append(contentsOf: pulls)
group.leave()
}
}

if showRequested {
if Defaults[.showRequested] {
group.enter()
ghClient.getReviewRequestedPulls() { pulls in
reviewRequestedPulls?.append(contentsOf: pulls)
Expand All @@ -128,8 +116,8 @@ extension AppDelegate {
if let assignedPulls = assignedPulls, let createdPulls = createdPulls, let reviewRequestedPulls = reviewRequestedPulls {
self.statusBarItem.button?.title = ""

if self.showAssigned && !assignedPulls.isEmpty {
if self.counterType == .assigned {
if Defaults[.showAssigned] && !assignedPulls.isEmpty {
if Defaults[.counterType] == .assigned {
self.statusBarItem.button?.title = String(assignedPulls.count)
}

Expand All @@ -140,8 +128,8 @@ extension AppDelegate {
self.menu.addItem(.separator())
}

if self.showCreated && !createdPulls.isEmpty {
if self.counterType == .created {
if Defaults[.showCreated] && !createdPulls.isEmpty {
if Defaults[.counterType] == .created {
self.statusBarItem.button?.title = String(createdPulls.count)
}

Expand All @@ -152,8 +140,8 @@ extension AppDelegate {
self.menu.addItem(.separator())
}

if self.showRequested && !reviewRequestedPulls.isEmpty {
if self.counterType == .reviewRequested {
if Defaults[.showRequested] && !reviewRequestedPulls.isEmpty {
if Defaults[.counterType] == .reviewRequested {
self.statusBarItem.button?.title = String(reviewRequestedPulls.count)
}

Expand Down Expand Up @@ -195,7 +183,7 @@ extension AppDelegate {
.appendIcon(iconName: "person")
.appendString(string: pull.node.author.login)

if !pull.node.labels.nodes.isEmpty && self.showLabels {
if !pull.node.labels.nodes.isEmpty && Defaults[.showLabels] {
issueItemTitle
.appendNewLine()
.appendIcon(iconName: "tag", color: NSColor(.secondary))
Expand All @@ -208,7 +196,7 @@ extension AppDelegate {

issueItemTitle.appendNewLine()

let approvedByMe = pull.node.reviews.edges.contains{ $0.node.author.login == githubUsername }
let approvedByMe = pull.node.reviews.edges.contains{ $0.node.author.login == Defaults[.githubUsername] }
issueItemTitle
.appendIcon(iconName: "check-circle", color: approvedByMe ? NSColor(named: "green")! : NSColor.secondaryLabelColor)
.appendString(string: " " + String(pull.node.reviews.totalCount))
Expand All @@ -219,7 +207,7 @@ extension AppDelegate {
.appendIcon(iconName: "calendar")
.appendString(string: pull.node.createdAt.getElapsedInterval())

if showAvatar {
if Defaults[.showAvatar] {
var image = NSImage()
if let imageURL = pull.node.author.avatarUrl {
image = NSImage.imageFromUrl(fromURL: imageURL) ?? NSImage(named: "person")!
Expand Down Expand Up @@ -400,7 +388,7 @@ extension AppDelegate {
if (windowTitle == "Preferences") {
timer?.invalidate()
timer = Timer.scheduledTimer(
timeInterval: Double(refreshRate * 60),
timeInterval: Double(Defaults[.refreshRate] * 60),
target: self,
selector: #selector(refreshMenu),
userInfo: nil,
Expand Down
29 changes: 12 additions & 17 deletions pullBar/GitHub/GitHubClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@ import KeychainAccess

public class GitHubClient {

@Default(.githubApiBaseUrl) var githubApiBaseUrl
@Default(.githubUsername) var githubUsername
@Default(.githubAdditionalQuery) var githubAdditionalQuery
@FromKeychain(.githubToken) var githubToken

@Default(.buildType) var buildType

func getAssignedPulls(completion:@escaping (([Edge]) -> Void)) -> Void {

if (githubUsername == "" || githubToken == "") {
if (Defaults[.githubUsername] == "" || githubToken == "") {
completion([Edge]())
}

Expand All @@ -30,14 +25,14 @@ public class GitHubClient {
.accept("application/json")
]

let graphQlQuery = buildGraphQlQuery(queryString: "is:open is:pr assignee:\(githubUsername) archived:false \(githubAdditionalQuery)")
let graphQlQuery = buildGraphQlQuery(queryString: "is:open is:pr assignee:\(Defaults[.githubUsername]) archived:false \(Defaults[.githubAdditionalQuery])")

let parameters = [
"query": graphQlQuery,
"variables":[]
] as [String: Any]

AF.request(githubApiBaseUrl + "/graphql", method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
AF.request(Defaults[.githubApiBaseUrl] + "/graphql", method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
.validate(statusCode: 200..<300)
.responseDecodable(of: GraphQlSearchResp.self, decoder: GithubDecoder()) { response in
switch response.result {
Expand All @@ -53,22 +48,22 @@ public class GitHubClient {

func getCreatedPulls(completion:@escaping (([Edge]) -> Void)) -> Void {

if (githubUsername == "" || githubToken == "") {
if (Defaults[.githubUsername] == "" || githubToken == "") {
completion([Edge]())
}

let headers: HTTPHeaders = [
.authorization(bearerToken: githubToken),
.accept("application/json")
]
let graphQlQuery = buildGraphQlQuery(queryString: "is:open is:pr author:\(githubUsername) archived:false \(githubAdditionalQuery)")
let graphQlQuery = buildGraphQlQuery(queryString: "is:open is:pr author:\(Defaults[.githubUsername]) archived:false \(Defaults[.githubAdditionalQuery])")

let parameters = [
"query": graphQlQuery,
"variables":[]
] as [String: Any]

AF.request(githubApiBaseUrl + "/graphql", method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
AF.request(Defaults[.githubApiBaseUrl] + "/graphql", method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
.validate(statusCode: 200..<300)
.responseDecodable(of: GraphQlSearchResp.self, decoder: GithubDecoder()) { response in
switch response.result {
Expand All @@ -83,22 +78,22 @@ public class GitHubClient {
}

func getReviewRequestedPulls(completion:@escaping (([Edge]) -> Void)) -> Void {
if (githubUsername == "" || githubToken == "") {
if (Defaults[.githubUsername] == "" || githubToken == "") {
completion([Edge]())
}

let headers: HTTPHeaders = [
.authorization(bearerToken: githubToken),
.accept("application/json")
]
let graphQlQuery = buildGraphQlQuery(queryString: "is:open is:pr review-requested:\(githubUsername) archived:false \(githubAdditionalQuery)")
let graphQlQuery = buildGraphQlQuery(queryString: "is:open is:pr review-requested:\(Defaults[.githubUsername]) archived:false \(Defaults[.githubAdditionalQuery])")

let parameters = [
"query": graphQlQuery,
"variables":[]
] as [String: Any]

AF.request(githubApiBaseUrl + "/graphql", method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
AF.request(Defaults[.githubApiBaseUrl] + "/graphql", method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
.validate(statusCode: 200..<300)
.responseDecodable(of: GraphQlSearchResp.self, decoder: GithubDecoder()) { response in
switch response.result {
Expand All @@ -115,7 +110,7 @@ public class GitHubClient {

var build = ""

switch buildType {
switch Defaults[.buildType] {
case .checks:
build = """
commits(last: 1) {
Expand Down Expand Up @@ -233,7 +228,7 @@ public class GitHubClient {
.accept("application/json")
]

AF.request(githubApiBaseUrl + "/user",
AF.request(Defaults[.githubApiBaseUrl] + "/user",
method: .get,
headers: headers)
.validate(statusCode: 200..<300)
Expand All @@ -251,7 +246,7 @@ public class GitHubClient {

func getLatestRelease(completion:@escaping (((LatestRelease?) -> Void))) -> Void {
let headers: HTTPHeaders = [
.authorization(username: githubUsername, password: githubToken),
.authorization(username: Defaults[.githubUsername], password: githubToken),
.contentType("application/json"),
.accept("application/json")
]
Expand Down
9 changes: 3 additions & 6 deletions pullBar/Views/PreferencesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ struct PreferencesView: View {
@Default(.counterType) var counterType

@State private var showGhAlert = false

@State private var selectedTab: Int = 1

@StateObject private var githubTokenValidator = GithubTokenValidator()
@ObservedObject private var launchAtLogin = LaunchAtLogin.observable
Expand All @@ -39,7 +37,7 @@ struct PreferencesView: View {

var body: some View {

TabView (selection: $selectedTab) {
TabView {
Form {
HStack(alignment: .center) {
Text("Pull Requests:").frame(width: 120, alignment: .trailing)
Expand Down Expand Up @@ -88,14 +86,13 @@ struct PreferencesView: View {
HStack(alignment: .center) {
Text("Launch at login:").frame(width: 120, alignment: .trailing)
Toggle("", isOn: $launchAtLogin.isEnabled)

}

}
.padding(8)
.frame(maxWidth: .infinity)
.tabItem{Text("General")}

Form {
HStack(alignment: .center) {
Text("API Base URL:").frame(width: 120, alignment: .trailing)
Expand Down Expand Up @@ -149,7 +146,6 @@ struct PreferencesView: View {
githubTokenValidator.validate()
}
.tabItem{Text("Authentication")}
.tag(1)

Form {
HStack(alignment: .center) {
Expand Down Expand Up @@ -191,6 +187,7 @@ struct PreferencesView: View {
.tabItem{Text("Advanced")}

}
.frame(width: 600)
.padding()

}
Expand Down

0 comments on commit 0ff4449

Please sign in to comment.