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

16
Clocker/Preferences/Menu Bar/StatusItemHandler.swift

@ -137,7 +137,7 @@ class StatusItemHandler: NSObject {
private func constructCompactView() { private func constructCompactView() {
parentView = nil parentView = nil
let menubarTimezones = retrieveSyncedMenubarTimezones() let menubarTimezones = DataStore.shared().menubarTimezones() ?? []
if menubarTimezones.isEmpty { if menubarTimezones.isEmpty {
currentState = .icon currentState = .icon
@ -149,18 +149,6 @@ class StatusItemHandler: NSObject {
statusItem.view?.window?.backgroundColor = NSColor.clear 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. // 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 // 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 // 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 { private func shouldDisplaySecondsInMenubar() -> Bool {
let syncedTimezones = retrieveSyncedMenubarTimezones() let syncedTimezones = DataStore.shared().menubarTimezones() ?? []
for timezone in syncedTimezones { for timezone in syncedTimezones {
if let timezoneObj = TimezoneData.customObject(from: timezone) { if let timezoneObj = TimezoneData.customObject(from: timezone) {

Loading…
Cancel
Save