Browse Source

Removing CLMenubarFavorites.

pull/92/head
Abhishek 5 years ago
parent
commit
70dc952f0a
  1. 1
      Clocker/Clocker/Utilities/CommonStrings.h
  2. 1
      Clocker/Clocker/Utilities/CommonStrings.m
  3. 8
      Clocker/Menu Bar/StatusItemHandler.swift
  4. 6
      Clocker/Overall App/AppDefaults.swift
  5. 5
      Clocker/Overall App/DataStore.swift
  6. 1
      Clocker/Overall App/Strings.swift
  7. 14
      Clocker/Panel/Data Layer/TimezoneData.swift
  8. 48
      Clocker/Panel/Notes Popover/NotesPopover.swift
  9. 4
      Clocker/Panel/PanelController.swift
  10. 35
      Clocker/Panel/ParentPanelController.swift
  11. 2
      Clocker/Preferences/Appearance/AppearanceViewController.swift
  12. 17
      Clocker/Preferences/General/PreferencesDataSource.swift
  13. 77
      Clocker/Preferences/General/PreferencesViewController.swift

1
Clocker/Clocker/Utilities/CommonStrings.h

@ -25,7 +25,6 @@ extern NSString *const CLLocationSearchURL;
extern NSString *const CLShowSecondsInMenubar; extern NSString *const CLShowSecondsInMenubar;
extern NSString *const CLUserFontSizePreference; extern NSString *const CLUserFontSizePreference;
extern NSString *const CLShowUpcomingEventView; extern NSString *const CLShowUpcomingEventView;
extern NSString *const CLMenubarFavorites;
extern NSString *const CLShowAllDayEventsInUpcomingView; extern NSString *const CLShowAllDayEventsInUpcomingView;
extern NSString *const CLShowMeetingInMenubar; extern NSString *const CLShowMeetingInMenubar;
extern NSString *const CLTruncateTextLength; extern NSString *const CLTruncateTextLength;

1
Clocker/Clocker/Utilities/CommonStrings.m

@ -24,7 +24,6 @@ NSString *const CLSunriseSunsetTime = @"showSunriseSetTime";
NSString *const CLShowSecondsInMenubar = @"showSeconds"; NSString *const CLShowSecondsInMenubar = @"showSeconds";
NSString *const CLUserFontSizePreference = @"userFontSize"; NSString *const CLUserFontSizePreference = @"userFontSize";
NSString *const CLShowUpcomingEventView = @"ShowUpcomingEventView"; NSString *const CLShowUpcomingEventView = @"ShowUpcomingEventView";
NSString *const CLMenubarFavorites = @"menubarFavourites";
NSString *const CLFutureSliderRange = @"sliderDayRange"; NSString *const CLFutureSliderRange = @"sliderDayRange";
NSString *const CLShowAllDayEventsInUpcomingView = @"showAllDayEventsInUpcomingView"; NSString *const CLShowAllDayEventsInUpcomingView = @"showAllDayEventsInUpcomingView";
NSString *const CLShowMeetingInMenubar = @"showMeetingInfoInMenubar"; NSString *const CLShowMeetingInMenubar = @"showMeetingInfoInMenubar";

8
Clocker/Menu Bar/StatusItemHandler.swift

@ -74,7 +74,7 @@ class StatusItemHandler: NSObject {
// Let's figure out the initial menubar state // Let's figure out the initial menubar state
var menubarState = MenubarState.icon var menubarState = MenubarState.icon
let shouldTextBeDisplayed = (DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data])?.isEmpty ?? true let shouldTextBeDisplayed = DataStore.shared().menubarTimezones()?.isEmpty ?? true
if !shouldTextBeDisplayed || DataStore.shared().shouldDisplay(.showMeetingInMenubar) { if !shouldTextBeDisplayed || DataStore.shared().shouldDisplay(.showMeetingInMenubar) {
if DataStore.shared().shouldDisplay(.menubarCompactMode) { if DataStore.shared().shouldDisplay(.menubarCompactMode) {
@ -219,7 +219,7 @@ class StatusItemHandler: NSObject {
private func calculateFireDate() -> Date? { private func calculateFireDate() -> Date? {
let shouldDisplaySeconds = shouldDisplaySecondsInMenubar() let shouldDisplaySeconds = shouldDisplaySecondsInMenubar()
let menubarFavourites = DataStore.shared().retrieve(key: CLMenubarFavorites) let menubarFavourites = DataStore.shared().menubarTimezones()
if !units.contains(.second), shouldDisplaySeconds { if !units.contains(.second), shouldDisplaySeconds {
units.insert(.second) units.insert(.second)
@ -228,7 +228,7 @@ class StatusItemHandler: NSObject {
var components = nsCalendar.dateComponents(units, from: Date()) var components = nsCalendar.dateComponents(units, from: Date())
// We want to update every second only when there's a timezone present! // We want to update every second only when there's a timezone present!
if shouldDisplaySeconds, let seconds = components.second, let favourites = menubarFavourites as? [Data], !favourites.isEmpty { if shouldDisplaySeconds, let seconds = components.second, let favourites = menubarFavourites, !favourites.isEmpty {
components.second = seconds + 1 components.second = seconds + 1
} else if let minutes = components.minute { } else if let minutes = components.minute {
components.minute = minutes + 1 components.minute = minutes + 1
@ -281,7 +281,7 @@ class StatusItemHandler: NSObject {
// 1. Timezones // 1. Timezones
// 2. Upcoming Event // 2. Upcoming Event
let menubarFavourites = (DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data]) ?? [] let menubarFavourites = DataStore.shared().menubarTimezones() ?? []
if menubarFavourites.isEmpty, DataStore.shared().shouldDisplay(.showMeetingInMenubar) == false { if menubarFavourites.isEmpty, DataStore.shared().shouldDisplay(.showMeetingInMenubar) == false {
print("Invalidating menubar timer!") print("Invalidating menubar timer!")

6
Clocker/Overall App/AppDefaults.swift

@ -20,7 +20,6 @@ class AppDefaults {
private class func initializeDefaults() { private class func initializeDefaults() {
let userDefaults = UserDefaults.standard let userDefaults = UserDefaults.standard
let menubarFavourites = userDefaults.object(forKey: CLMenubarFavorites)
let timezones = userDefaults.object(forKey: CLDefaultPreferenceKey) let timezones = userDefaults.object(forKey: CLDefaultPreferenceKey)
let selectedCalendars = userDefaults.object(forKey: CLSelectedCalendars) let selectedCalendars = userDefaults.object(forKey: CLSelectedCalendars)
@ -30,8 +29,6 @@ class AppDefaults {
// Register the usual suspects // Register the usual suspects
userDefaults.register(defaults: defaultsDictionary()) userDefaults.register(defaults: defaultsDictionary())
// Set arrays and our custom objects
userDefaults.set(menubarFavourites, forKey: CLMenubarFavorites)
userDefaults.set(timezones, forKey: CLDefaultPreferenceKey) userDefaults.set(timezones, forKey: CLDefaultPreferenceKey)
userDefaults.set(selectedCalendars, forKey: CLSelectedCalendars) userDefaults.set(selectedCalendars, forKey: CLSelectedCalendars)
@ -53,7 +50,7 @@ class AppDefaults {
if userDefaults.bool(forKey: CLSwitchToCompactModeAlert) == false { if userDefaults.bool(forKey: CLSwitchToCompactModeAlert) == false {
userDefaults.set(true, forKey: CLSwitchToCompactModeAlert) userDefaults.set(true, forKey: CLSwitchToCompactModeAlert)
if let menubarFavourites = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data], menubarFavourites.count > 1 { if let menubarFavourites = DataStore.shared().menubarTimezones(), menubarFavourites.count > 1 {
// If the user is already using the compact mode, abort. // If the user is already using the compact mode, abort.
if DataStore.shared().shouldDisplay(.menubarCompactMode) { if DataStore.shared().shouldDisplay(.menubarCompactMode) {
return return
@ -124,7 +121,6 @@ class AppDefaults {
CLUserFontSizePreference: 4, CLUserFontSizePreference: 4,
CLShowUpcomingEventView: "YES", CLShowUpcomingEventView: "YES",
CLShowAppInForeground: 0, CLShowAppInForeground: 0,
CLMenubarFavorites: [],
CLFutureSliderRange: 0, CLFutureSliderRange: 0,
CLShowAllDayEventsInUpcomingView: 1, CLShowAllDayEventsInUpcomingView: 1,
CLShowMeetingInMenubar: 1, CLShowMeetingInMenubar: 1,

5
Clocker/Overall App/DataStore.swift

@ -45,7 +45,10 @@ class DataStore: NSObject {
} }
func menubarTimezones() -> [Data]? { func menubarTimezones() -> [Data]? {
return DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data] return timezones().filter {
let customTimezone = TimezoneData.customObject(from: $0)
return customTimezone?.isFavourite == 1
}
} }
func updateDayPreference() { func updateDayPreference() {

1
Clocker/Overall App/Strings.swift

@ -22,7 +22,6 @@ let CLSunriseSunsetTime = "showSunriseSetTime"
let CLShowSecondsInMenubar = "showSeconds" let CLShowSecondsInMenubar = "showSeconds"
let CLUserFontSizePreference = "userFontSize" let CLUserFontSizePreference = "userFontSize"
let CLShowUpcomingEventView = "ShowUpcomingEventView" let CLShowUpcomingEventView = "ShowUpcomingEventView"
let CLMenubarFavorites = "menubarFavourites"
let CLShowAllDayEventsInUpcomingView = "showAllDayEventsInUpcomingView" let CLShowAllDayEventsInUpcomingView = "showAllDayEventsInUpcomingView"
let CLShowMeetingInMenubar = "showMeetingInfoInMenubar" let CLShowMeetingInMenubar = "showMeetingInfoInMenubar"
let CLTruncateTextLength = "truncateTextLength" let CLTruncateTextLength = "truncateTextLength"

14
Clocker/Panel/Data Layer/TimezoneData.swift

@ -220,20 +220,6 @@ class TimezoneData: NSObject, NSCoding {
DataStore.shared().setTimezones(newModels) DataStore.shared().setTimezones(newModels)
} }
} }
if let menubarTimezones = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data], !menubarTimezones.isEmpty {
let newMenubarModels = converter(menubarTimezones)
if newMenubarModels.count == menubarTimezones.count {
// Now point preferences to empty
UserDefaults.standard.set(nil, forKey: CLMenubarFavorites)
// Now point it to new models
UserDefaults.standard.set(newMenubarModels, forKey: CLMenubarFavorites)
print("Successfully converted: \(newMenubarModels.count) menubar objects.")
}
}
} }
private class func converter(_ timezones: [Data]) -> [Data] { private class func converter(_ timezones: [Data]) -> [Data] {

48
Clocker/Panel/Notes Popover/NotesPopover.swift

@ -265,7 +265,6 @@ class NotesPopover: NSViewController {
@IBAction func customizeTimeFormat(_ sender: NSSegmentedControl) { @IBAction func customizeTimeFormat(_ sender: NSSegmentedControl) {
updateTimezoneInDefaultPreferences(with: sender.selectedSegment, .timezoneFormat) updateTimezoneInDefaultPreferences(with: sender.selectedSegment, .timezoneFormat)
updateMenubarTimezoneInDefaultPreferences(with: sender.selectedSegment, .timezoneFormat)
refreshMainTableView() refreshMainTableView()
// Update the display if the chosen menubar mode is compact! // Update the display if the chosen menubar mode is compact!
@ -282,22 +281,6 @@ class NotesPopover: NSViewController {
DataStore.shared().setTimezones(timezones) DataStore.shared().setTimezones(timezones)
} }
private func updateMenubarTitles() {
guard let model = dataObject, model.isFavourite == 1, var timezones = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data] else { return }
let menubarIndex = timezones.firstIndex { (menubarLocation) -> Bool in
if let convertedObject = TimezoneData.customObject(from: menubarLocation) {
return convertedObject.isEqual(dataObject)
}
return false
}
if let index = menubarIndex {
let encodedObject = NSKeyedArchiver.archivedData(withRootObject: model)
timezones[index] = encodedObject
UserDefaults.standard.set(timezones, forKey: CLMenubarFavorites)
}
}
private func updateTimezoneInDefaultPreferences(with override: Int, _ overrideType: OverrideType) { private func updateTimezoneInDefaultPreferences(with override: Int, _ overrideType: OverrideType) {
let timezones = DataStore.shared().timezones() let timezones = DataStore.shared().timezones()
@ -325,35 +308,6 @@ class NotesPopover: NSViewController {
DataStore.shared().setTimezones(datas) DataStore.shared().setTimezones(datas)
} }
private func updateMenubarTimezoneInDefaultPreferences(with override: Int, _ overrideType: OverrideType) {
guard let timezones = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data] else {
return
}
var timezoneObjects: [TimezoneData] = []
for timezone in timezones {
if let model = TimezoneData.customObject(from: timezone) {
timezoneObjects.append(model)
}
}
for timezoneObject in timezoneObjects where timezoneObject.isEqual(dataObject) {
overrideType == .timezoneFormat ?
timezoneObject.setShouldOverrideGlobalTimeFormat(override) :
timezoneObject.setShouldOverrideSecondsFormat(override)
}
var datas: [Data] = []
for updatedObject in timezoneObjects {
let dataObject = NSKeyedArchiver.archivedData(withRootObject: updatedObject)
datas.append(dataObject)
}
UserDefaults.standard.set(datas, forKey: CLMenubarFavorites)
}
private func setReminderAlarm() { private func setReminderAlarm() {
let eventCenter = EventCenter.sharedCenter() let eventCenter = EventCenter.sharedCenter()
@ -438,7 +392,6 @@ class NotesPopover: NSViewController {
@IBAction func customizeSecondsFormat(_ sender: NSSegmentedControl) { @IBAction func customizeSecondsFormat(_ sender: NSSegmentedControl) {
updateTimezoneInDefaultPreferences(with: sender.selectedSegment, .seconds) updateTimezoneInDefaultPreferences(with: sender.selectedSegment, .seconds)
updateMenubarTimezoneInDefaultPreferences(with: sender.selectedSegment, .seconds)
refreshMainTableView() refreshMainTableView()
// Update the display if the chosen menubar mode is compact! // Update the display if the chosen menubar mode is compact!
@ -529,7 +482,6 @@ extension NotesPopover: NSTextFieldDelegate {
model.setLabel(customLabel.stringValue) model.setLabel(customLabel.stringValue)
insertTimezoneInDefaultPreferences() insertTimezoneInDefaultPreferences()
updateMenubarTitles()
NotificationCenter.default.post(name: NSNotification.Name.customLabelChanged, NotificationCenter.default.post(name: NSNotification.Name.customLabelChanged,
object: nil) object: nil)

4
Clocker/Panel/PanelController.swift

@ -249,7 +249,7 @@ class PanelController: ParentPanelController {
} }
private func stopMenubarTimerIfNeccesary() { private func stopMenubarTimerIfNeccesary() {
let count = (DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data])?.count ?? 0 let count = DataStore.shared().menubarTimezones()?.count ?? 0
if count >= 1 || DataStore.shared().shouldDisplay(.showMeetingInMenubar) { if count >= 1 || DataStore.shared().shouldDisplay(.showMeetingInMenubar) {
if let delegate = NSApplication.shared.delegate as? AppDelegate { if let delegate = NSApplication.shared.delegate as? AppDelegate {
@ -271,7 +271,7 @@ class PanelController: ParentPanelController {
func minimize() { func minimize() {
let delegate = NSApplication.shared.delegate as? AppDelegate let delegate = NSApplication.shared.delegate as? AppDelegate
let count = (DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data])?.count ?? 0 let count = DataStore.shared().menubarTimezones()?.count ?? 0
if count >= 1 || DataStore.shared().shouldDisplay(.showMeetingInMenubar) == true { if count >= 1 || DataStore.shared().shouldDisplay(.showMeetingInMenubar) == true {
if let handler = delegate?.statusItemForPanel(), let timer = handler.menubarTimer, !timer.isValid { if let handler = delegate?.statusItemForPanel(), let timer = handler.menubarTimer, !timer.isValid {

35
Clocker/Panel/ParentPanelController.swift

@ -222,7 +222,6 @@ class ParentPanelController: NSWindowController {
DataStore.shared().setTimezones(datas) DataStore.shared().setTimezones(datas)
// 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()
} }
@ -487,20 +486,11 @@ class ParentPanelController: NSWindowController {
func deleteTimezone(at row: Int) { func deleteTimezone(at row: Int) {
var defaults = defaultPreferences var defaults = defaultPreferences
// Remove object from menubar favourites if present
if let dataObject = TimezoneData.customObject(from: defaults[row]) {
removeFromMenubarFavourites(timezone: dataObject)
}
// Remove from panel // Remove from panel
defaults.remove(at: row) defaults.remove(at: row)
DataStore.shared().setTimezones(defaults) DataStore.shared().setTimezones(defaults)
updateDefaultPreferences() updateDefaultPreferences()
if defaults.isEmpty {
UserDefaults.standard.set([], forKey: CLMenubarFavorites)
}
NotificationCenter.default.post(name: Notification.Name.customLabelChanged, NotificationCenter.default.post(name: Notification.Name.customLabelChanged,
object: nil) object: nil)
@ -508,35 +498,12 @@ class ParentPanelController: NSWindowController {
Logger.log(object: [:], for: "Deleted Timezone Through Swipe") Logger.log(object: [:], for: "Deleted Timezone Through Swipe")
} }
private func removeFromMenubarFavourites(timezone: TimezoneData) {
if timezone.isFavourite == 1, let menubarTitles = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data] {
let filtered = menubarTitles.filter {
let dataObject = TimezoneData.customObject(from: $0)
// Special check for home indicator objects!
if timezone.isSystemTimezone, let isSystem = dataObject?.isSystemTimezone, isSystem {
return false
}
return dataObject?.placeID != timezone.placeID
}
UserDefaults.standard.set(filtered, forKey: CLMenubarFavorites)
// Update the status bar's appearance if it is in custom mode.
if let delegate = NSApplication.shared.delegate as? AppDelegate {
let statusItemPanel = delegate.statusItemForPanel()
statusItemPanel.setupStatusItem()
}
}
}
private lazy var menubarTitleHandler = MenubarHandler() private lazy var menubarTitleHandler = MenubarHandler()
@objc func updateTime() { @objc func updateTime() {
let store = DataStore.shared() let store = DataStore.shared()
let menubarCount = (store.retrieve(key: CLMenubarFavorites) as? [Data])?.count ?? 0 let menubarCount = store.menubarTimezones()?.count ?? 0
if menubarCount >= 1 || store.shouldDisplay(.showMeetingInMenubar) == true { if menubarCount >= 1 || store.shouldDisplay(.showMeetingInMenubar) == true {
if let status = (NSApplication.shared.delegate as? AppDelegate)?.statusItemForPanel() { if let status = (NSApplication.shared.delegate as? AppDelegate)?.statusItemForPanel() {

2
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -60,7 +60,7 @@ class AppearanceViewController: ParentViewController {
override func viewWillAppear() { override func viewWillAppear() {
super.viewWillAppear() super.viewWillAppear()
if let menubarFavourites = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data] { if let menubarFavourites = DataStore.shared().menubarTimezones() {
visualEffectView.isHidden = menubarFavourites.isEmpty ? false : true visualEffectView.isHidden = menubarFavourites.isEmpty ? false : true
informationLabel.isHidden = menubarFavourites.isEmpty ? false : true informationLabel.isHidden = menubarFavourites.isEmpty ? false : true
} }

17
Clocker/Preferences/General/PreferencesDataSource.swift

@ -186,23 +186,6 @@ extension PreferencesDataSource: NSTableViewDataSource {
} }
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()
} }

77
Clocker/Preferences/General/PreferencesViewController.swift

@ -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

Loading…
Cancel
Save