From 8b75d12ad647eeef12599e16b2ae022254dd0be0 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Tue, 5 Apr 2022 22:19:53 -0400 Subject: [PATCH] Cleanup app feedback window on close. --- Clocker/Panel/ParentPanelController.swift | 16 ++++++++++++---- .../Preferences/About/AboutViewController.swift | 12 ++++++++++-- .../AppFeedbackWindowController.swift | 6 ++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index 146dade..960aba5 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -37,7 +37,7 @@ class ParentPanelController: NSWindowController { var datasource: TimezoneDataSource? - private lazy var feedbackWindow = AppFeedbackWindowController.shared() + private var feedbackWindow: AppFeedbackWindowController? private var notePopover: NotesPopover? @@ -890,9 +890,9 @@ class ParentPanelController: NSWindowController { } else if sender.title == PanelConstants.yesWithQuestionMark { ReviewController.prompted() updateReviewView() - feedbackWindow = AppFeedbackWindowController.shared() - feedbackWindow.showWindow(nil) + feedbackWindow?.appFeedbackWindowDelegate = self + feedbackWindow?.showWindow(nil) NSApp.activate(ignoringOtherApps: true) } else { updateReviewView() @@ -986,7 +986,9 @@ class ParentPanelController: NSWindowController { } @objc func reportIssue() { - feedbackWindow.showWindow(nil) + feedbackWindow = AppFeedbackWindowController.shared() + feedbackWindow?.appFeedbackWindowDelegate = self + feedbackWindow?.showWindow(nil) NSApp.activate(ignoringOtherApps: true) window?.orderOut(nil) @@ -1147,3 +1149,9 @@ extension ParentPanelController: NSSharingServicePickerDelegate { return clipboardCopy } } + +extension ParentPanelController: AppFeedbackWindowControllerDelegate { + func appFeedbackWindowWillClose() { + feedbackWindow = nil + } +} diff --git a/Clocker/Preferences/About/AboutViewController.swift b/Clocker/Preferences/About/AboutViewController.swift index d36b872..bd2e01f 100644 --- a/Clocker/Preferences/About/AboutViewController.swift +++ b/Clocker/Preferences/About/AboutViewController.swift @@ -22,7 +22,7 @@ class AboutViewController: ParentViewController { @IBOutlet var versionField: NSTextField! private var themeDidChangeNotification: NSObjectProtocol? - private lazy var feedbackWindow = AppFeedbackWindowController.shared() + private var feedbackWindow: AppFeedbackWindowController? override func viewDidLoad() { super.viewDidLoad() @@ -120,7 +120,9 @@ class AboutViewController: ParentViewController { } @IBAction func reportIssue(_: Any) { - feedbackWindow.showWindow(nil) + feedbackWindow = AppFeedbackWindowController.sharedWindow + feedbackWindow?.appFeedbackWindowDelegate = self + feedbackWindow?.showWindow(nil) NSApp.activate(ignoringOtherApps: true) view.window?.orderOut(nil) @@ -150,3 +152,9 @@ class AboutViewController: ParentViewController { underlineTextForActionButton() } } + +extension AboutViewController: AppFeedbackWindowControllerDelegate { + func appFeedbackWindowWillClose() { + feedbackWindow = nil + } +} diff --git a/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift b/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift index 31c72ea..88ddc8b 100644 --- a/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift +++ b/Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift @@ -5,6 +5,10 @@ import CoreLoggerKit import CoreModelKit import FirebaseDatabase +protocol AppFeedbackWindowControllerDelegate: AnyObject { + func appFeedbackWindowWillClose() +} + extension NSNib.Name { static let appFeedbackWindowIdentifier = NSNib.Name("AppFeedbackWindow") static let onboardingWindowIdentifier = NSNib.Name("OnboardingWindow") @@ -36,6 +40,7 @@ class AppFeedbackWindowController: NSWindowController { @IBOutlet var progressIndicator: NSProgressIndicator! @IBOutlet var quickCommentsLabel: PointingHandCursorButton! + public weak var appFeedbackWindowDelegate: AppFeedbackWindowControllerDelegate? private var themeDidChangeNotification: NSObjectProtocol? private var serialNumber: String? { let platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")) @@ -307,6 +312,7 @@ extension AppFeedbackWindowController: NSWindowDelegate { emailField.stringValue = CLEmptyString feedbackTextView.string = CLEmptyString isActivityInProgress = false + appFeedbackWindowDelegate?.appFeedbackWindowWillClose() } func bringPreferencesWindowToFront() {