Browse Source

Update VersionUpdateHandler.swift

master
Abhishek Banthia 9 months ago
parent
commit
2938e5c300
  1. 31
      Clocker/Overall App/VersionUpdateHandler.swift

31
Clocker/Overall App/VersionUpdateHandler.swift

@ -4,7 +4,7 @@ import Cocoa
import CoreLoggerKit import CoreLoggerKit
class VersionUpdateHandler: NSObject { class VersionUpdateHandler: NSObject {
enum VersionUpdateHandlerPriority { enum VersionUpdateHandlerPriority: Comparable {
case defaultPri case defaultPri
case low case low
case medium case medium
@ -37,6 +37,8 @@ class VersionUpdateHandler: NSObject {
private var remoteVersionsDict: [String: Any] = [:] private var remoteVersionsDict: [String: Any] = [:]
private var downloadError: Error? private var downloadError: Error?
private var dataTask: URLSessionDataTask? = .none private var dataTask: URLSessionDataTask? = .none
private var visibleLocalAlert: NSAlert?
private var visibleRemoteAlert: NSAlert?
private var showOnFirstLaunch: Bool = false private var showOnFirstLaunch: Bool = false
public var previewMode: Bool = false public var previewMode: Bool = false
@ -358,7 +360,11 @@ class VersionUpdateHandler: NSObject {
return dict.keys.sorted().last ?? "" return dict.keys.sorted().last ?? ""
} }
private func showAlertWithTitle(_ title: String, _ details: String, _ defaultButton: String, _ ignoreButton: String, _ remindButton: String) -> NSAlert { private func showAlertWithTitle(_ title: String,
_ details: String,
_ defaultButton: String,
_ ignoreButton: String?,
_ remindButton: String?) -> NSAlert {
let floatMax = CGFloat.greatestFiniteMagnitude let floatMax = CGFloat.greatestFiniteMagnitude
let alert = NSAlert() let alert = NSAlert()
@ -396,12 +402,12 @@ class VersionUpdateHandler: NSObject {
scrollView.frame = NSRect(x: 0.0, y: 0.0, width: scrollView.frame.size.width, height: height) scrollView.frame = NSRect(x: 0.0, y: 0.0, width: scrollView.frame.size.width, height: height)
alert.accessoryView = scrollView alert.accessoryView = scrollView
if ignoreButton.isEmpty == false { if let ignoreButtonTitle = ignoreButton {
alert.addButton(withTitle: ignoreButton) alert.addButton(withTitle: ignoreButtonTitle)
} }
if remindButton.isEmpty == false { if let remindButtonTitle = remindButton {
alert.addButton(withTitle: remindButton) alert.addButton(withTitle: remindButtonTitle)
let modalResponse = alert.runModal() let modalResponse = alert.runModal()
if modalResponse == .alertFirstButtonReturn { if modalResponse == .alertFirstButtonReturn {
@ -418,11 +424,11 @@ class VersionUpdateHandler: NSObject {
} }
private func showIgnoreButton() -> Bool { private func showIgnoreButton() -> Bool {
return false return ignoreButtonLabel().isEmpty == false && updatePriority < VersionUpdateHandlerPriority.medium
} }
private func showRemindButtton() -> Bool { private func showRemindButtton() -> Bool {
return false return remindButtonLabel().isEmpty == false && updatePriority < VersionUpdateHandlerPriority.high
} }
private func didDismissAlert(_: NSAlert, _: Int) { private func didDismissAlert(_: NSAlert, _: Int) {
@ -475,7 +481,7 @@ class VersionUpdateHandler: NSObject {
return return
} }
_ = Repeater(interval: .seconds(5), mode: .infinite) { _ in _ = Repeater(interval: .seconds(0.5), mode: .infinite) { _ in
OperationQueue.main.addOperation { [weak self] in OperationQueue.main.addOperation { [weak self] in
guard let self = self else { guard let self = self else {
return return
@ -490,7 +496,14 @@ class VersionUpdateHandler: NSObject {
if applicationVersion.compareVersion(lastVersionString) == ComparisonResult.orderedDescending || previewMode { if applicationVersion.compareVersion(lastVersionString) == ComparisonResult.orderedDescending || previewMode {
// Clear Reminder // Clear Reminder
setLastReminded(nil) setLastReminded(nil)
if (self.versionDetails != nil && visibleLocalAlert == nil && visibleRemoteAlert == nil) {
visibleLocalAlert = showAlertWithTitle(inThisVersionTitle(), self.versionDetailsString(), okayButtonLabel(), nil, nil)
}
} }
} else {
//record this as last viewed release
setViewedVersionDetails(true)
} }
} }
} }

Loading…
Cancel
Save