Browse Source

Merge branch 'MOS-13' into Release_2.1

* MOS-13:
  MOS-13 Add notification property in product before 10.14 and all related refactor.
  MOS-13 Refactor parameter in removeDeliveredNotifications.
  MOS-13 Remove delivered notifications from a single product instead of all products.
  MOS-13 Fix install update in menu. Add notify function for os versions prior to 10.14 where notification object is needed. Add removeDeliveredNotifications function in DownloadNotificationManager.
MACOSINST-23
David Alarcon 2 years ago
parent
commit
0c265752f4
3 changed files with 30 additions and 9 deletions
  1. +19
    -7
      Submodules/pEpNotifications/pEpNotifications/AppDelegate.swift
  2. +9
    -2
      Submodules/pEpNotifications/pEpNotifications/DownloadNotificationManager.swift
  3. +2
    -0
      Submodules/pEpNotifications/pEpNotifications/DownloadStateNotifier.swift

+ 19
- 7
Submodules/pEpNotifications/pEpNotifications/AppDelegate.swift View File

@ -71,12 +71,23 @@ class AppDelegate: NSObject {
}
@IBAction func installNow(_ sender: NSMenuItem) {
guard let product = sender.representedObject as? Product else {
return
}
uninstallMenuExtra()
let product = sender.representedObject as! Dictionary<String, Any>
let un = product["notification"] as! NSUserNotification
nc.removeDeliveredNotification(un)
NSLog("pEpNotifications: installNow clicked for %@", product["name"] as! String)
NSWorkspace.shared.openFile(product["filename"] as! String)
if #available(OSX 10.14, *) {
downloadNotificationManager.removeDeliveredNotifications(of: product)
} else {
guard let notification = product.notification else {
return
}
nc.removeDeliveredNotification(notification)
}
NSLog("pEpNotifications: installNow clicked for %@", product.name)
NSWorkspace.shared.openFile(product.filename)
sender.representedObject = nil
downloadStateNotifier.notify(.Connected)
}
@ -196,7 +207,7 @@ extension AppDelegate: PEPNotificationProtocol {
}
case .downloadArrived:
let product = Product(name: withName as String, filename: withFilename as String);
var product = Product(name: withName as String, filename: withFilename as String);
if #available(OSX 10.14, *) {
downloadNotificationManager.scheduleDownloadNotification(with: product)
@ -218,8 +229,9 @@ extension AppDelegate: PEPNotificationProtocol {
un.setValue(true, forKey: "_showsButtons")
un.userInfo = ["name": withName, "filename": withFilename]
nc.deliver(un)
product.notification = un
}
downloadStateNotifier.notify(.NewVersionAvailable(String(withName)), with: product)
case .noDownloadAvailable:


+ 9
- 2
Submodules/pEpNotifications/pEpNotifications/DownloadNotificationManager.swift View File

@ -37,6 +37,9 @@ public protocol DownloadNotificationManagerProtocol {
/// Add and send a download notification.
/// - Parameter product: the product to be downloaded.
func scheduleDownloadNotification(with product: Product)
/// Delete delivered notifications from the given product in manager.
func removeDeliveredNotifications(of product: Product)
}
@available(OSX 10.14, *)
@ -49,7 +52,7 @@ public class DownloadNotificationManager: NSObject, DownloadNotificationManagerP
override init() {
super.init()
notificationCenter.removeDeliveredNotifications(withIdentifiers: ["p≡p updates"])
notificationCenter.removeAllDeliveredNotifications()
notificationCenter.delegate = self
setupNotificationCategories()
}
@ -75,6 +78,10 @@ public class DownloadNotificationManager: NSObject, DownloadNotificationManagerP
addDownloadNotification(with: product)
scheduleDownloadNotifications()
}
public func removeDeliveredNotifications(of product: Product) {
notificationCenter.removeDeliveredNotifications(withIdentifiers: [product.name])
}
}
// MARK: - Private
@ -131,7 +138,7 @@ extension DownloadNotificationManager {
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: Double.leastNonzeroMagnitude,
repeats: false)
let request = UNNotificationRequest(identifier: "p≡p updates",
let request = UNNotificationRequest(identifier: notification.product.name,
content: notificationContent,
trigger: trigger)


+ 2
- 0
Submodules/pEpNotifications/pEpNotifications/DownloadStateNotifier.swift View File

@ -14,6 +14,8 @@ public struct Product {
public var productInfo: Dictionary<String, String> {
return ["name": name, "filename": filename]
}
@available(macOS, obsoleted: 10.14)
public var notification: NSUserNotification?
}
struct DownloadStateNotifier {


Loading…
Cancel
Save