|
|
@ -195,23 +195,6 @@ class PreferencesViewController: ParentViewController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func updateMenubarTitles() { |
|
|
|
private func updateMenubarTitles() { |
|
|
|
let defaultTimezones = DataStore.shared().timezones() |
|
|
|
|
|
|
|
UserDefaults.standard.set([], forKey: CLMenubarFavorites) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let menubarTimes = defaultTimezones.compactMap { (data) -> TimezoneData? in |
|
|
|
|
|
|
|
if let model = TimezoneData.customObject(from: data), model.isFavourite == 1 { |
|
|
|
|
|
|
|
return model |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let archivedObjects = menubarTimes.map { (timezone) -> Data in |
|
|
|
|
|
|
|
NSKeyedArchiver.archivedData(withRootObject: timezone) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserDefaults.standard.set(archivedObjects, forKey: CLMenubarFavorites) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update appereance if in compact menubar mode |
|
|
|
|
|
|
|
if let appDelegate = NSApplication.shared.delegate as? AppDelegate { |
|
|
|
if let appDelegate = NSApplication.shared.delegate as? AppDelegate { |
|
|
|
appDelegate.setupMenubarTimer() |
|
|
|
appDelegate.setupMenubarTimer() |
|
|
|
} |
|
|
|
} |
|
|
@ -316,16 +299,6 @@ class PreferencesViewController: ParentViewController { |
|
|
|
|
|
|
|
|
|
|
|
extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate { |
|
|
|
extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate { |
|
|
|
private func _markAsFavorite(_ dataObject: TimezoneData) { |
|
|
|
private func _markAsFavorite(_ dataObject: TimezoneData) { |
|
|
|
guard let menubarTitles = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data] else { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var mutableArray = menubarTitles |
|
|
|
|
|
|
|
let archivedObject = NSKeyedArchiver.archivedData(withRootObject: dataObject) |
|
|
|
|
|
|
|
mutableArray.append(archivedObject) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserDefaults.standard.set(mutableArray, forKey: CLMenubarFavorites) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if dataObject.customLabel != nil { |
|
|
|
if dataObject.customLabel != nil { |
|
|
|
Logger.log(object: ["label": dataObject.customLabel ?? "Error"], for: "favouriteSelected") |
|
|
|
Logger.log(object: ["label": dataObject.customLabel ?? "Error"], for: "favouriteSelected") |
|
|
|
} |
|
|
|
} |
|
|
@ -334,31 +307,17 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate |
|
|
|
appDelegate.setupMenubarTimer() |
|
|
|
appDelegate.setupMenubarTimer() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if mutableArray.count > 1 { |
|
|
|
if let menubarTimezones = DataStore.shared().menubarTimezones(), menubarTimezones.count > 1 { |
|
|
|
showAlertIfMoreThanOneTimezoneHasBeenAddedToTheMenubar() |
|
|
|
showAlertIfMoreThanOneTimezoneHasBeenAddedToTheMenubar() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func _unfavourite(_ dataObject: TimezoneData) { |
|
|
|
private func _unfavourite(_ dataObject: TimezoneData) { |
|
|
|
guard let menubarTimers = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data] else { |
|
|
|
|
|
|
|
assertionFailure("Menubar timers is unexpectedly nil") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Logger.log(object: ["label": dataObject.customLabel ?? "Error"], |
|
|
|
Logger.log(object: ["label": dataObject.customLabel ?? "Error"], |
|
|
|
for: "favouriteRemoved") |
|
|
|
for: "favouriteRemoved") |
|
|
|
|
|
|
|
|
|
|
|
let filteredMenubars = menubarTimers.filter { |
|
|
|
|
|
|
|
guard let current = NSKeyedUnarchiver.unarchiveObject(with: $0) as? TimezoneData else { |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return current.isEqual(dataObject) == false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserDefaults.standard.set(filteredMenubars, forKey: CLMenubarFavorites) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let appDelegate = NSApplication.shared.delegate as? AppDelegate, |
|
|
|
if let appDelegate = NSApplication.shared.delegate as? AppDelegate, |
|
|
|
let menubarFavourites = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data], |
|
|
|
let menubarFavourites = DataStore.shared().menubarTimezones(), |
|
|
|
menubarFavourites.isEmpty, |
|
|
|
menubarFavourites.isEmpty, |
|
|
|
DataStore.shared().shouldDisplay(.showMeetingInMenubar) == false { |
|
|
|
DataStore.shared().shouldDisplay(.showMeetingInMenubar) == false { |
|
|
|
appDelegate.invalidateMenubarTimer(true) |
|
|
|
appDelegate.invalidateMenubarTimer(true) |
|
|
@ -874,16 +833,6 @@ extension PreferencesViewController { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let currentObject = selectedTimeZones[timezoneTableView.selectedRow] |
|
|
|
|
|
|
|
guard let model = TimezoneData.customObject(from: currentObject) else { |
|
|
|
|
|
|
|
assertionFailure("Data was unexpectedly nil") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if model.isFavourite == 1 { |
|
|
|
|
|
|
|
removeFromMenubarFavourites(object: model) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var newDefaults = selectedTimeZones |
|
|
|
var newDefaults = selectedTimeZones |
|
|
|
|
|
|
|
|
|
|
|
let objectsToRemove = timezoneTableView.selectedRowIndexes.map { (index) -> Data in |
|
|
|
let objectsToRemove = timezoneTableView.selectedRowIndexes.map { (index) -> Data in |
|
|
@ -900,10 +849,6 @@ extension PreferencesViewController { |
|
|
|
|
|
|
|
|
|
|
|
refreshMainTable() |
|
|
|
refreshMainTable() |
|
|
|
|
|
|
|
|
|
|
|
if selectedTimeZones.isEmpty { |
|
|
|
|
|
|
|
UserDefaults.standard.set(nil, forKey: CLMenubarFavorites) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateStatusBarAppearance() |
|
|
|
updateStatusBarAppearance() |
|
|
|
|
|
|
|
|
|
|
|
updateStatusItem() |
|
|
|
updateStatusItem() |
|
|
@ -926,24 +871,6 @@ extension PreferencesViewController { |
|
|
|
statusItem.setupStatusItem() |
|
|
|
statusItem.setupStatusItem() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func removeFromMenubarFavourites(object: TimezoneData?) { |
|
|
|
|
|
|
|
guard let model = object else { |
|
|
|
|
|
|
|
assertionFailure("Data was unexpectedly nil") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if model.isFavourite == 1 { |
|
|
|
|
|
|
|
if let menubarTitles = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data] { |
|
|
|
|
|
|
|
let updated = menubarTitles.filter { (data) -> Bool in |
|
|
|
|
|
|
|
let current = TimezoneData.customObject(from: data) |
|
|
|
|
|
|
|
return current != model |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserDefaults.standard.set(updated, forKey: CLMenubarFavorites) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@IBAction func filterArray(_: Any?) { |
|
|
|
@IBAction func filterArray(_: Any?) { |
|
|
|
messageLabel.stringValue = CLEmptyString |
|
|
|
messageLabel.stringValue = CLEmptyString |
|
|
|
|
|
|
|
|
|
|
|