From 2a654eb0a894a36529dde07991e6cb8c8b86644d Mon Sep 17 00:00:00 2001 From: streetturtle Date: Sun, 12 Dec 2021 21:20:32 -0500 Subject: [PATCH] more improvements --- pullBar/AppDelegate.swift | 31 ++++++++++++++++++++++++++----- pullBar/GitHub/GitHubClient.swift | 3 +++ pullBar/Views/AboutView.swift | 2 +- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/pullBar/AppDelegate.swift b/pullBar/AppDelegate.swift index b319550..2872304 100644 --- a/pullBar/AppDelegate.swift +++ b/pullBar/AppDelegate.swift @@ -21,6 +21,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { @Default(.refreshRate) var refreshRate + @Default(.githubUsername) var githubUsername + @Default(.githubToken) var githubToken + let ghClient = GitHubClient() var statusBarItem: NSStatusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) let menu: NSMenu = NSMenu() @@ -78,10 +81,20 @@ extension AppDelegate { func refreshMenu() { NSLog("Refreshing menu") self.menu.removeAllItems() + + if (githubUsername == "" || githubToken == "") { + addMenuFooterItems() + return + } + + var assignedPulls: [Edge]? = [] var createdPulls: [Edge]? = [] var reviewRequestedPulls: [Edge]? = [] + + + let group = DispatchGroup() if showAssigned { @@ -143,11 +156,7 @@ extension AppDelegate { self.menu.addItem(.separator()) } - self.menu.addItem(withTitle: "Refresh", action: #selector(self.refreshMenu), keyEquivalent: "R") - self.menu.addItem(.separator()) - self.menu.addItem(withTitle: "Preferences...", action: #selector(self.openPrefecencesWindow), keyEquivalent: ",") - self.menu.addItem(withTitle: "About PullBar", action: #selector(self.openAboutWindow), keyEquivalent: "") - self.menu.addItem(withTitle: "Quit", action: #selector(self.quit), keyEquivalent: "q") + self.addMenuFooterItems() } } @@ -195,6 +204,14 @@ extension AppDelegate { return issueItem } + func addMenuFooterItems() { + self.menu.addItem(withTitle: "Refresh", action: #selector(self.refreshMenu), keyEquivalent: "R") + self.menu.addItem(.separator()) + self.menu.addItem(withTitle: "Preferences...", action: #selector(self.openPrefecencesWindow), keyEquivalent: ",") + self.menu.addItem(withTitle: "About PullBar", action: #selector(self.openAboutWindow), keyEquivalent: "") + self.menu.addItem(withTitle: "Quit", action: #selector(self.quit), keyEquivalent: "q") + } + @objc func openPrefecencesWindow(_: NSStatusBarButton?) { NSLog("Open preferences window") @@ -212,6 +229,8 @@ extension AppDelegate { preferencesWindow.title = "Preferences" preferencesWindow.contentView = NSHostingView(rootView: contentView) preferencesWindow.makeKeyAndOrderFront(nil) + preferencesWindow.styleMask.remove(.resizable) + // allow the preference window can be focused automatically when opened NSApplication.shared.activate(ignoringOtherApps: true) @@ -239,6 +258,8 @@ extension AppDelegate { aboutWindow.title = "About" aboutWindow.contentView = NSHostingView(rootView: contentView) aboutWindow.makeKeyAndOrderFront(nil) + aboutWindow.styleMask.remove(.resizable) + // allow the preference window can be focused automatically when opened NSApplication.shared.activate(ignoringOtherApps: true) diff --git a/pullBar/GitHub/GitHubClient.swift b/pullBar/GitHub/GitHubClient.swift index 80d920f..d75feb8 100644 --- a/pullBar/GitHub/GitHubClient.swift +++ b/pullBar/GitHub/GitHubClient.swift @@ -76,6 +76,9 @@ public class GitHubClient { } func getReviewRequestedPulls(completion:@escaping (([Edge]) -> Void)) -> Void { + if (githubUsername == "" || githubToken == "") { + completion([Edge]()) + } let headers: HTTPHeaders = [ .authorization(username: githubUsername, password: githubToken), diff --git a/pullBar/Views/AboutView.swift b/pullBar/Views/AboutView.swift index b721ec6..734fc87 100644 --- a/pullBar/Views/AboutView.swift +++ b/pullBar/Views/AboutView.swift @@ -16,7 +16,7 @@ struct AboutView: View { VStack { Image(nsImage: NSImage(named: "AppIcon")!) Text("PullBar").font(.title) - Text("By Pavel Makhov").font(.caption) + Text("by Pavel Makhov").font(.caption) Text("Version " + currentVersion).font(.footnote) Divider() Link("PullBar on GitHub", destination: URL(string: "https://github.com/menubar-apps-for-devs/PullBar")!)