Skip to content

Commit

Permalink
add counter and improve pref window
Browse files Browse the repository at this point in the history
  • Loading branch information
streetturtle committed Jul 6, 2023
1 parent 08065a3 commit 7b9ea91
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 149 deletions.
56 changes: 25 additions & 31 deletions pullBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

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

@Default(.githubUsername) var githubUsername
@FromKeychain(.githubToken) var githubToken
Expand Down Expand Up @@ -84,19 +85,18 @@ extension AppDelegate {
func refreshMenu() {
NSLog("Refreshing menu")
self.menu.removeAllItems()
self.statusBarItem.button?.title = ""


if (githubUsername == "" || githubToken == "") {
addMenuFooterItems()
return
}


var assignedPulls: [Edge]? = []
var createdPulls: [Edge]? = []
var reviewRequestedPulls: [Edge]? = []


let group = DispatchGroup()

if showAssigned {
Expand All @@ -106,63 +106,62 @@ extension AppDelegate {
group.leave()
}
}

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

if showRequested {
group.enter()
ghClient.getReviewRequestedPulls() { pulls in
reviewRequestedPulls?.append(contentsOf: pulls)
group.leave()
}
}

group.notify(queue: .main) {

let isOneSelected = (self.showAssigned.intValue + self.showCreated.intValue + self.showRequested.intValue) == 1


if let assignedPulls = assignedPulls, let createdPulls = createdPulls, let reviewRequestedPulls = reviewRequestedPulls {

self.statusBarItem.button?.title = ""

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

self.menu.addItem(NSMenuItem(title: "Assigned (\(assignedPulls.count))", action: nil, keyEquivalent: ""))
for pull in assignedPulls {
self.menu.addItem(self.createMenuItem(pull: pull))
}
self.menu.addItem(.separator())
if isOneSelected {
self.statusBarItem.button?.title = String(assignedPulls.count)
}
}

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

self.menu.addItem(NSMenuItem(title: "Created (\(createdPulls.count))", action: nil, keyEquivalent: ""))
for pull in createdPulls {
self.menu.addItem(self.createMenuItem(pull: pull))
}
self.menu.addItem(.separator())
if isOneSelected {
self.statusBarItem.button?.title = String(createdPulls.count)
}

}

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

self.menu.addItem(NSMenuItem(title: "Review Requested (\(reviewRequestedPulls.count))", action: nil, keyEquivalent: ""))
for pull in reviewRequestedPulls {
self.menu.addItem(self.createMenuItem(pull: pull))
}
self.menu.addItem(.separator())
if isOneSelected {
self.statusBarItem.button?.title = String(reviewRequestedPulls.count)
}

}


Expand Down Expand Up @@ -312,14 +311,9 @@ extension AppDelegate {
issueItemTitle.appendIcon(iconName: "dot-fill", color: NSColor.gray)

}

issueItem.submenu?.addItem(buildItem)
}



}

}

issueItem.attributedTitle = issueItemTitle
Expand Down Expand Up @@ -347,7 +341,7 @@ extension AppDelegate {
preferencesWindow.close()
}
preferencesWindow = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 500, height: 500),
contentRect: NSRect(x: 0, y: 0, width: 0, height: 0),
styleMask: [.closable, .titled],
backing: .buffered,
defer: false
Expand Down
24 changes: 24 additions & 0 deletions pullBar/Extensions/DefaultsExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extension Defaults.Keys {

static let refreshRate = Key<Int>("refreshRate", default: 5)
static let buildType = Key<BuildType>("buildType", default: .none)
static let counterType = Key<CounterType>("counterType", default: .reviewRequested)
}

extension KeychainKeys {
Expand All @@ -45,3 +46,26 @@ enum BuildType: String, Defaults.Serializable, CaseIterable, Identifiable {
}
}
}

enum CounterType: String, Defaults.Serializable, CaseIterable, Identifiable {
case assigned
case created
case reviewRequested
case none

var id: Self { self }

var description: String {

switch self {
case .assigned:
return "assigned"
case .created:
return "created"
case .reviewRequested:
return "review requested"
case .none:
return "none"
}
}
}
Loading

0 comments on commit 7b9ea91

Please sign in to comment.