You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
3.2 KiB

// Copyright © 2015 Abhishek Banthia
import CoreModelKit
3 years ago
import Foundation
struct ConfigExport {
private func generateJSONFromDefaults() {
let selectedKeys: Set<String> = Set([
CLShowOnboardingFlow,
CLSelectedTimeZoneFormatKey,
CLThemeKey,
CLShowDayInMenu,
CLShowDateInMenu,
CLShowPlaceInMenu,
CLDisplayFutureSliderKey,
CLStartAtLogin,
CLShowAppInForeground,
CLSunriseSunsetTime,
CLUserFontSizePreference,
CLShowUpcomingEventView,
CLShowAllDayEventsInUpcomingView,
CLShowMeetingInMenubar,
CLTruncateTextLength,
CLFutureSliderRange,
CLSelectedCalendars,
CLAppDisplayOptions,
CLLongStatusBarWarningMessage,
CLMenubarCompactMode,
CLDefaultMenubarMode,
CLInstallHomeIndicatorObject,
CLSwitchToCompactModeAlert,
CLDisplayDSTTransitionInfo,
])
let dictionaryRep = UserDefaults.standard.dictionaryRepresentation()
3 years ago
var clockerPrefs: [String: Any] = [:]
for (key, value) in dictionaryRep {
if selectedKeys.contains(key) {
print("Key is \(key) and value is \(value)")
clockerPrefs[key] = value
}
}
3 years ago
do {
let decodeJSON: [[String: Any]] = DataStore.shared().timezones().compactMap { data -> [String: Any]? in
guard let customObject = TimezoneData.customObject(from: data) else { return nil }
let timezoneDictionary: [String: Any] = [
"Name": customObject.formattedAddress ?? "",
"Custom": customObject.customLabel ?? "",
"TimezoneID": customObject.timezoneID ?? "N/A",
"Is System": customObject.isSystemTimezone ? 1 : 0,
"Is Favorite": customObject.isFavourite == 1 ? 1 : 0,
"Sunrise or Sunset": customObject.isSunriseOrSunset ? 1 : 0,
"Latitude": customObject.latitude ?? 0.0,
"Longitude": customObject.longitude ?? 0.0,
"Place Identifier": customObject.placeID ?? "0.0",
"Selection Type": "\(customObject.selectionType)",
]
return timezoneDictionary
}
3 years ago
let timezoneDict = ["Timezones": decodeJSON]
3 years ago
clockerPrefs.merge(timezoneDict) { current, _ in current }
guard let documentDirectoryUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return }
let fileUrl = documentDirectoryUrl.appendingPathComponent("Persons.json")
// Transform array into data and save it into file
do {
let data = try JSONSerialization.data(withJSONObject: clockerPrefs, options: [])
try data.write(to: fileUrl, options: [])
} catch {
print(error)
}
3 years ago
let json = try JSONSerialization.data(withJSONObject: clockerPrefs, options: .prettyPrinted)
print(json)
} catch {
print("Failure Observed \(error.localizedDescription)")
}
}
}