Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to copy OpenRadar link to clipboard on successful submission #143

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Brisk/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
private func registerDefaults() {
let defaults: [String: Any] = [
Defaults.showDockIcon: false,
Defaults.copyOpenRadarLinkToClipboard: false
]

UserDefaults.standard.register(defaults: defaults)
Expand Down
1 change: 1 addition & 0 deletions Brisk/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
struct Defaults {
static let showDockIcon = "showDockIcon"
static let copyOpenRadarLinkToClipboard = "copyOpenRadarLinkToClipboard"
}
27 changes: 23 additions & 4 deletions Brisk/Controllers/RadarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ final class RadarViewController: ViewController {
guard self?.postToOpenRadarButton.state == .on,
let (_, token) = Keychain.get(.openRadar) else
{
self?.submitRadarCompletion(success: true)
self?.submitRadarCompletion(success: true, code: radarID)
return
}

Expand All @@ -163,7 +163,7 @@ final class RadarViewController: ViewController {
}, closure: { [weak self] result in
switch result {
case .success:
self?.submitRadarCompletion(success: true)
self?.submitRadarCompletion(success: true, code: radarID)
case .failure(let error):
self?.showError(message: error.message)
self?.submitRadarCompletion(success: false)
Expand Down Expand Up @@ -214,15 +214,28 @@ final class RadarViewController: ViewController {
}
}

private func submitRadarCompletion(success: Bool) {
private func submitRadarCompletion(success: Bool, code: Int = -1) {
self.progressIndicator.stopAnimation(self)
self.submitButton.isEnabled = true

if success {
if success && code != -1 {
if self.document?.fileURL != nil {
self.document?.save(self)
}

let notification = NSUserNotification()
notification.title = "Radar submitted"

if UserDefaults.standard.bool(forKey: Defaults.copyOpenRadarLinkToClipboard) {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString("http://www.openradar.me/\(code)", forType: .string)
notification.informativeText = "The OpenRadar link has been copied to your clipboard."
} else {
notification.informativeText = "Your report identifier is: rdar://\(code)"
}
NSUserNotificationCenter.default.delegate = self
NSUserNotificationCenter.default.deliver(notification)

self.document?.close()
}
}
Expand Down Expand Up @@ -335,3 +348,9 @@ extension RadarViewController: NSWindowDelegate {
self.updateOpenRadarButton()
}
}

extension RadarViewController: NSUserNotificationCenterDelegate {
func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool {
return true
}
}
Loading