Browse Source

Return nil if archiving fails.

master
Abhi 2 years ago
parent
commit
a4cd914b4d
  1. 4
      Clocker/Clocker/LocationController.swift
  2. 4
      Clocker/Overall App/DataStore.swift
  3. 4
      Clocker/Overall App/Foundation + Additions.swift
  4. 4
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  5. 9
      Clocker/Panel/Notes Popover/NotesPopover.swift
  6. 4
      Clocker/Panel/ParentPanelController.swift
  7. 4
      Clocker/Preferences/General/PreferencesDataSource.swift
  8. 4
      Clocker/Preferences/General/PreferencesViewController.swift

4
Clocker/Clocker/LocationController.swift

@ -80,7 +80,9 @@ class LocationController: NSObject {
var datas: [Data] = [] var datas: [Data] = []
for updatedObject in timezoneObjects { for updatedObject in timezoneObjects {
let dataObject = NSKeyedArchiver.clocker_archive(with: updatedObject) guard let dataObject = NSKeyedArchiver.clocker_archive(with: updatedObject) else {
continue
}
datas.append(dataObject) datas.append(dataObject)
} }

4
Clocker/Overall App/DataStore.swift

@ -128,7 +128,9 @@ class DataStore: NSObject {
} }
func addTimezone(_ timezone: TimezoneData) { func addTimezone(_ timezone: TimezoneData) {
let encodedTimezone = NSKeyedArchiver.clocker_archive(with: timezone) guard let encodedTimezone = NSKeyedArchiver.clocker_archive(with: timezone) else {
return
}
var defaults: [Data] = timezones() var defaults: [Data] = timezones()
defaults.append(encodedTimezone) defaults.append(encodedTimezone)

4
Clocker/Overall App/Foundation + Additions.swift

@ -58,7 +58,7 @@ public extension Data {
} }
extension NSKeyedArchiver { extension NSKeyedArchiver {
static func clocker_archive(with object: Any) -> Data { static func clocker_archive(with object: Any) -> Data? {
if #available(macOS 10.14, *) { if #available(macOS 10.14, *) {
return try! NSKeyedArchiver.archivedData(withRootObject: object, requiringSecureCoding: true) return try! NSKeyedArchiver.archivedData(withRootObject: object, requiringSecureCoding: true)
@ -67,5 +67,7 @@ extension NSKeyedArchiver {
if #available(macOS 10.13, *) { if #available(macOS 10.13, *) {
return NSKeyedArchiver.archivedData(withRootObject: object) return NSKeyedArchiver.archivedData(withRootObject: object)
} }
return nil
} }
} }

4
Clocker/Panel/Data Layer/TimezoneDataOperations.swift

@ -421,7 +421,9 @@ extension TimezoneDataOperations {
func saveObject(at index: Int = -1) { func saveObject(at index: Int = -1) {
var defaults = store.timezones() var defaults = store.timezones()
let encodedObject = NSKeyedArchiver.clocker_archive(with:dataObject as Any) guard let encodedObject = NSKeyedArchiver.clocker_archive(with:dataObject as Any) else {
return
}
index == -1 ? defaults.append(encodedObject) : defaults.insert(encodedObject, at: index) index == -1 ? defaults.append(encodedObject) : defaults.insert(encodedObject, at: index)
store.setTimezones(defaults) store.setTimezones(defaults)
} }

9
Clocker/Panel/Notes Popover/NotesPopover.swift

@ -315,8 +315,9 @@ class NotesPopover: NSViewController {
} }
private func insertTimezoneInDefaultPreferences() { private func insertTimezoneInDefaultPreferences() {
guard let model = dataObject, var timezones = timezoneObjects else { return } guard let model = dataObject, var timezones = timezoneObjects,
let encodedObject = NSKeyedArchiver.clocker_archive(with:model) let encodedObject = NSKeyedArchiver.clocker_archive(with:model) else { return }
timezones[currentRow] = encodedObject timezones[currentRow] = encodedObject
DataStore.shared().setTimezones(timezones) DataStore.shared().setTimezones(timezones)
} }
@ -341,7 +342,9 @@ class NotesPopover: NSViewController {
var datas: [Data] = [] var datas: [Data] = []
for updatedObject in timezoneObjects { for updatedObject in timezoneObjects {
let dataObject = NSKeyedArchiver.clocker_archive(with: updatedObject) guard let dataObject = NSKeyedArchiver.clocker_archive(with: updatedObject) else {
continue
}
datas.append(dataObject) datas.append(dataObject)
} }

4
Clocker/Panel/ParentPanelController.swift

@ -285,7 +285,9 @@ class ParentPanelController: NSWindowController {
var datas: [Data] = [] var datas: [Data] = []
for updatedObject in timezoneObjects { for updatedObject in timezoneObjects {
let dataObject = NSKeyedArchiver.clocker_archive(with: updatedObject) guard let dataObject = NSKeyedArchiver.clocker_archive(with: updatedObject) else {
continue
}
datas.append(dataObject) datas.append(dataObject)
} }

4
Clocker/Preferences/General/PreferencesDataSource.swift

@ -184,7 +184,9 @@ extension PreferencesDataSource: NSTableViewDataSource {
} }
private func insert(timezone: TimezoneData, at index: Int) { private func insert(timezone: TimezoneData, at index: Int) {
let encodedObject = NSKeyedArchiver.clocker_archive(with: timezone) guard let encodedObject = NSKeyedArchiver.clocker_archive(with: timezone) else {
return
}
var newDefaults = selectedTimezones var newDefaults = selectedTimezones
newDefaults[index] = encodedObject newDefaults[index] = encodedObject
store.setTimezones(newDefaults) store.setTimezones(newDefaults)

4
Clocker/Preferences/General/PreferencesViewController.swift

@ -977,7 +977,9 @@ extension PreferencesViewController: SRRecorderControlDelegate {}
// Helpers // Helpers
extension PreferencesViewController { extension PreferencesViewController {
private func insert(timezone: TimezoneData, at index: Int) { private func insert(timezone: TimezoneData, at index: Int) {
let encodedObject = NSKeyedArchiver.clocker_archive(with: timezone) guard let encodedObject = NSKeyedArchiver.clocker_archive(with: timezone) else {
return
}
var newDefaults = selectedTimeZones var newDefaults = selectedTimeZones
newDefaults[index] = encodedObject newDefaults[index] = encodedObject
DataStore.shared().setTimezones(newDefaults) DataStore.shared().setTimezones(newDefaults)

Loading…
Cancel
Save