Browse Source

Cleanup redundant method.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
884fdc04a9
  1. 8
      Clocker/Overall App/DataStore.swift
  2. 16
      Clocker/Preferences/Menu Bar/StatusItemHandler.swift

8
Clocker/Overall App/DataStore.swift

@ -23,7 +23,7 @@ enum ViewType {
class DataStore: NSObject {
private static var sharedStore = DataStore(with: UserDefaults.standard)
private var userDefaults: UserDefaults!
private var defaultUbiquotousKeyValueStore: NSUbiquitousKeyValueStore!
private var ubiquitousStore: NSUbiquitousKeyValueStore!
// Since these pref can accessed every second, let's cache this
private var shouldDisplayDayInMenubar: Bool = false
@ -41,13 +41,13 @@ class DataStore: NSObject {
init(with defaults: UserDefaults) {
super.init()
userDefaults = defaults
defaultUbiquotousKeyValueStore = NSUbiquitousKeyValueStore.default
ubiquitousStore = NSUbiquitousKeyValueStore.default
shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar)
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar)
}
func timezones() -> [Data] {
if let cloudPreferences = defaultUbiquotousKeyValueStore.object(forKey: CLDefaultPreferenceKey) as? [Data] {
if let cloudPreferences = ubiquitousStore.object(forKey: CLDefaultPreferenceKey) as? [Data] {
Logger.info("Returning preferences from NSUbiquitousKeyValueStore")
return cloudPreferences
}
@ -62,7 +62,7 @@ class DataStore: NSObject {
func setTimezones(_ timezones: [Data]?) {
userDefaults.set(timezones, forKey: CLDefaultPreferenceKey)
// iCloud sync
defaultUbiquotousKeyValueStore.set(timezones, forKey: CLDefaultPreferenceKey)
ubiquitousStore.set(timezones, forKey: CLDefaultPreferenceKey)
}
func menubarTimezones() -> [Data]? {

16
Clocker/Preferences/Menu Bar/StatusItemHandler.swift

@ -137,7 +137,7 @@ class StatusItemHandler: NSObject {
private func constructCompactView() {
parentView = nil
let menubarTimezones = retrieveSyncedMenubarTimezones()
let menubarTimezones = DataStore.shared().menubarTimezones() ?? []
if menubarTimezones.isEmpty {
currentState = .icon
@ -149,18 +149,6 @@ class StatusItemHandler: NSObject {
statusItem.view?.window?.backgroundColor = NSColor.clear
}
private func retrieveSyncedMenubarTimezones() -> [Data] {
let defaultPreferences = DataStore.shared().timezones()
let menubarTimezones = defaultPreferences.filter { data -> Bool in
if let timezoneObj = TimezoneData.customObject(from: data) {
return timezoneObj.isFavourite == 1
}
return false
}
return menubarTimezones
}
// This is called when the Apple interface style pre-Mojave is changed.
// In High Sierra and before, we could have a dark or light menubar and dock
// Our icon is template, so it changes automatically; so is our standard status bar text
@ -210,7 +198,7 @@ class StatusItemHandler: NSObject {
}
private func shouldDisplaySecondsInMenubar() -> Bool {
let syncedTimezones = retrieveSyncedMenubarTimezones()
let syncedTimezones = DataStore.shared().menubarTimezones() ?? []
for timezone in syncedTimezones {
if let timezoneObj = TimezoneData.customObject(from: timezone) {

Loading…
Cancel
Save