Browse Source

Refactor

master
Abhishek Banthia 7 months ago
parent
commit
5674076c24
  1. 1
      Clocker/AppDelegate.swift
  2. 4
      Clocker/Events and Reminders/CalendarHandler.swift
  3. 2
      Clocker/Overall App/AppDefaults.swift
  4. 4
      Clocker/Overall App/DataStore.swift
  5. 16
      Clocker/Overall App/VersionUpdateHandler.swift

1
Clocker/AppDelegate.swift

@ -11,6 +11,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
internal lazy var panelController = PanelController(windowNibName: .panel)
private var statusBarHandler: StatusItemHandler!
private var panelObserver: NSKeyValueObservation?
private let store: VersionUpdateHandler = VersionUpdateHandler(with: DataStore.shared())
deinit {
panelObserver?.invalidate()

4
Clocker/Events and Reminders/CalendarHandler.swift

@ -32,7 +32,7 @@ extension EventCenter {
// Fetch the user-selected calendars. Initially, all the calendars will be selected
var setOfCalendars: Set<String> = Set()
if let userCalendars = UserDefaults.standard.array(forKey: CLSelectedCalendars) as? [String], !userCalendars.isEmpty {
if let userCalendars = DataStore.shared().selectedCalendars(), !userCalendars.isEmpty {
setOfCalendars = Set(userCalendars)
}
@ -192,7 +192,7 @@ extension EventCenter {
func filterEvents() {
filteredEvents = [:]
if let selectedCalendars = UserDefaults.standard.array(forKey: CLSelectedCalendars) as? [String] {
if let selectedCalendars = DataStore.shared().selectedCalendars() {
for date in eventsForDate.keys {
if let events = eventsForDate[date] {
for event in events {

2
Clocker/Overall App/AppDefaults.swift

@ -10,7 +10,7 @@ class AppDefaults {
private class func initializeDefaults(with store: DataStore, defaults: UserDefaults) {
let timezones = store.timezones()
let selectedCalendars = defaults.object(forKey: CLSelectedCalendars)
let selectedCalendars = store.selectedCalendars()
// Register the usual suspects
defaults.register(defaults: defaultsDictionary())

4
Clocker/Overall App/DataStore.swift

@ -107,6 +107,10 @@ class DataStore: NSObject {
}
}
func selectedCalendars() -> [String]? {
return userDefaults.array(forKey: CLSelectedCalendars) as? [String]
}
// MARK: Date (May 8th) in Compact Menubar
func shouldShowDateInMenubar() -> Bool {

16
Clocker/Overall App/VersionUpdateHandler.swift

@ -22,8 +22,6 @@ class VersionUpdateHandler: NSObject {
static let kVersionMacAppStoreBundleID = "com.apple.AppStore";
static let kVersionMacAppStoreAppID = 1056643111
static let sharedInstance = VersionUpdateHandler()
private var appStoreCountry: String!
private var applicationVersion: String!
private var applicationBundleID: String = Bundle.main.bundleIdentifier ?? "N/A"
@ -46,9 +44,11 @@ class VersionUpdateHandler: NSObject {
private var showOnFirstLaunch: Bool = false
public var previewMode: Bool = false
private var versionDetails: String?
private let store: DataStore
override init() {
init(with dataStore: DataStore) {
// Setup App Store Country
store = dataStore
appStoreCountry = Locale.current.regionCode
if appStoreCountry == "150" {
appStoreCountry = "eu"
@ -119,7 +119,7 @@ class VersionUpdateHandler: NSObject {
}
private func lastChecked() -> Date? {
return UserDefaults.standard.object(forKey: VersionUpdateHandler.kVersionLastCheckedKey) as? Date
return store.retrieve(key: VersionUpdateHandler.kVersionLastCheckedKey) as? Date
}
private func setLastReminded(_ date: Date?) {
@ -127,11 +127,11 @@ class VersionUpdateHandler: NSObject {
}
private func lastReminded() -> Date? {
return UserDefaults.standard.object(forKey: VersionUpdateHandler.kVersionLastRemindedKey) as? Date
return store.retrieve(key: VersionUpdateHandler.kVersionLastRemindedKey) as? Date
}
private func ignoredVersion() -> String? {
return UserDefaults.standard.object(forKey: VersionUpdateHandler.kVersionIgnoreVersionKey) as? String
return store.retrieve(key: VersionUpdateHandler.kVersionIgnoreVersionKey) as? String
}
private func setIgnoredVersion(_ version: String) {
@ -143,12 +143,12 @@ class VersionUpdateHandler: NSObject {
}
private func viewedVersionDetails() -> Bool {
let lastVersionKey = UserDefaults.standard.object(forKey: VersionUpdateHandler.kVersionCheckLastVersionKey) as? String ?? ""
let lastVersionKey = store.retrieve(key: VersionUpdateHandler.kVersionCheckLastVersionKey) as? String ?? ""
return lastVersionKey == applicationVersion
}
private func lastVersion() -> String {
return UserDefaults.standard.object(forKey: VersionUpdateHandler.kVersionCheckLastVersionKey) as? String ?? ""
return store.retrieve(key: VersionUpdateHandler.kVersionCheckLastVersionKey) as? String ?? ""
}
private func setLastVersion(_ version: String) {

Loading…
Cancel
Save