Browse Source

MOS-10 Refactor Product from typedef to struct and related changes.

MOS-10 Release_2.1.2
David Alarcon 1 year ago
parent
commit
dec8307adb
3 changed files with 19 additions and 17 deletions
  1. +3
    -6
      Submodules/pEpNotifications/pEpNotifications/AppDelegate.swift
  2. +9
    -10
      Submodules/pEpNotifications/pEpNotifications/DownloadNotificationManager.swift
  3. +7
    -1
      Submodules/pEpNotifications/pEpNotifications/DownloadStateNotifier.swift

+ 3
- 6
Submodules/pEpNotifications/pEpNotifications/AppDelegate.swift View File

@ -196,7 +196,7 @@ extension AppDelegate: PEPNotificationProtocol {
}
case .downloadArrived:
let product = ["name": withName, "filename": withFilename]
let product = Product(name: withName as String, filename: withFilename as String);
if #available(OSX 10.14, *) {
downloadNotificationManager.scheduleDownloadNotification(with: product)
@ -304,12 +304,9 @@ extension AppDelegate: DownloadNotificationManagerDelegate {
defer {
uninstallMenuExtra()
}
guard let filename = product["filename"] as? String else {
return
}
NSLog("pEpNotifications: actionButtonClicked for %@", filename)
NSWorkspace.shared.openFile(filename)
NSLog("pEpNotifications: actionButtonClicked for %@", product.filename)
NSWorkspace.shared.openFile(product.filename)
downloadStateNotifier.notify(.Connected)
}
}

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

@ -122,17 +122,12 @@ extension DownloadNotificationManager {
}
private func sendNotification(with notification: DownloadNotification) {
guard let name = notification.product["name"] as? String else {
return
}
let notificationContent = UNMutableNotificationContent()
notificationContent.title = NSLocalizedString("Update available", comment: "")
notificationContent.body = String(format: NSLocalizedString("A new update for %@ is ready to be installed.", comment: ""), name)
notificationContent.body = String(format: NSLocalizedString("A new update for %@ is ready to be installed.", comment: ""), notification.product.name)
notificationContent.sound = UNNotificationSound.default
notificationContent.categoryIdentifier = "p≡p"
notificationContent.userInfo = notification.product
notificationContent.userInfo = notification.product.productInfo
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: Double.leastNonzeroMagnitude,
repeats: false)
@ -158,14 +153,18 @@ extension DownloadNotificationManager: UNUserNotificationCenterDelegate {
switch response.actionIdentifier {
case "installAction":
if let product = response.notification.request.content.userInfo as? Product {
delegate?.installSelected(with: product)
guard let userInfo = response.notification.request.content.userInfo as? Dictionary<String, String>,
let name = userInfo["name"],
let filename = userInfo["filename"]
else {
break
}
let product = Product(name: name, filename: filename)
delegate?.installSelected(with: product)
case "notNowAction":
delegate?.notNowSelected()
default:
break
}
}
}

+ 7
- 1
Submodules/pEpNotifications/pEpNotifications/DownloadStateNotifier.swift View File

@ -8,7 +8,13 @@
import SwiftUI
public typealias Product = Dictionary<String, Any>
public struct Product {
public var name: String
public var filename: String
public var productInfo: Dictionary<String, String> {
return ["name": name, "filename": filename]
}
}
struct DownloadStateNotifier {
var menuItem: NSMenuItem


Loading…
Cancel
Save