From 0f6107ec5b573323231648401821fa4c6a06079a Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 21 Jul 2021 08:13:36 -0400 Subject: [PATCH] Add ConfigExport file. --- Clocker/Clocker.xcodeproj/project.pbxproj | 8 +-- Clocker/Overall App/ConfigExport.swift | 83 +++++++++++++++++++++++ 2 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 Clocker/Overall App/ConfigExport.swift diff --git a/Clocker/Clocker.xcodeproj/project.pbxproj b/Clocker/Clocker.xcodeproj/project.pbxproj index 50b9109c..15cde59f 100755 --- a/Clocker/Clocker.xcodeproj/project.pbxproj +++ b/Clocker/Clocker.xcodeproj/project.pbxproj @@ -118,10 +118,10 @@ 35C36FA12259ED6D002FA5C6 /* EventCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F9E2259ED6D002FA5C6 /* EventCenter.swift */; }; 35C36FA22259ED6D002FA5C6 /* RemindersHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F9F2259ED6D002FA5C6 /* RemindersHandler.swift */; }; 35C36FA42259EEC2002FA5C6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36FA32259EEC2002FA5C6 /* AppDelegate.swift */; }; + 35DFBCEF26A8468900D6648B /* ConfigExport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35DFBCEE26A8468900D6648B /* ConfigExport.swift */; }; 35E65125268EDD2E00E3E1E3 /* Toasty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35E65124268EDD2E00E3E1E3 /* Toasty.swift */; }; 9A0385BB269E3434003B5E72 /* StandardMenubarHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A0385BA269E3434003B5E72 /* StandardMenubarHandlerTests.swift */; }; 9A0385C0269E8891003B5E72 /* PermissionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A0385BF269E8891003B5E72 /* PermissionsTests.swift */; }; - 9A066A04269A2BF600C3F1FB /* Keys.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9A066A03269A2BF600C3F1FB /* Keys.plist */; }; 9A0A1C8C20903DBD0012003B /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A9E87651C1FEDC500A7A2DF /* CoreLocation.framework */; }; 9A13BAD61CA87F08007C6CBE /* Panel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9A13BAD81CA87F08007C6CBE /* Panel.xib */; }; 9A13BAE01CA882FA007C6CBE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9A13BAE21CA882FA007C6CBE /* InfoPlist.strings */; }; @@ -347,10 +347,10 @@ 35C36F9E2259ED6D002FA5C6 /* EventCenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventCenter.swift; sourceTree = ""; }; 35C36F9F2259ED6D002FA5C6 /* RemindersHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemindersHandler.swift; sourceTree = ""; }; 35C36FA32259EEC2002FA5C6 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = SOURCE_ROOT; }; + 35DFBCEE26A8468900D6648B /* ConfigExport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigExport.swift; sourceTree = ""; }; 35E65124268EDD2E00E3E1E3 /* Toasty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toasty.swift; sourceTree = ""; }; 9A0385BA269E3434003B5E72 /* StandardMenubarHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardMenubarHandlerTests.swift; sourceTree = ""; }; 9A0385BF269E8891003B5E72 /* PermissionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionsTests.swift; sourceTree = ""; }; - 9A066A03269A2BF600C3F1FB /* Keys.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Keys.plist; path = Internal/Keys.plist; sourceTree = ""; }; 9A13BAD71CA87F08007C6CBE /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/Panel.xib; sourceTree = ""; }; 9A13BAE11CA882FA007C6CBE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 9A13BAEB1CA88A76007C6CBE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; @@ -628,6 +628,7 @@ 35C36F3A2259D892002FA5C6 /* Timer.swift */, 3595FACF227F88BC0044A12A /* UserDefaults + KVOExtensions.swift */, 35C11E2024873A550031F18C /* VersionUpdateHandler.swift */, + 35DFBCEE26A8468900D6648B /* ConfigExport.swift */, ); path = "Overall App"; sourceTree = ""; @@ -888,7 +889,6 @@ DD4F7BF913C30F9F00825C6E = { isa = PBXGroup; children = ( - 9A066A03269A2BF600C3F1FB /* Keys.plist */, 35B2FEE4259A2C25005DA84D /* CoreModelKit */, 35B2FED4259A2244005DA84D /* CoreLoggerKit */, 35B2FEB1259A1649005DA84D /* StartupKit */, @@ -1200,7 +1200,6 @@ 3531F7C226936C6E00DF0111 /* GoogleService-Info.plist in Resources */, 35C36F17225961DA002FA5C6 /* DateTools.bundle in Resources */, 35C36EF322595F14002FA5C6 /* WelcomeView.xib in Resources */, - 9A066A04269A2BF600C3F1FB /* Keys.plist in Resources */, 35C36EF822595F14002FA5C6 /* Onboarding.storyboard in Resources */, 35C36F612259DE67002FA5C6 /* NotesPopover.xib in Resources */, 9A3169C11D2CC5AA0079FDF8 /* com.abhishek.ClockerHelper.plist in Resources */, @@ -1312,6 +1311,7 @@ 35C36F2C2259D6FA002FA5C6 /* PanelController.swift in Sources */, 35C36F10225961DA002FA5C6 /* Constants.swift in Sources */, 35C36FA42259EEC2002FA5C6 /* AppDelegate.swift in Sources */, + 35DFBCEF26A8468900D6648B /* ConfigExport.swift in Sources */, 35C36F19225961DA002FA5C6 /* Enums.swift in Sources */, 35C36F5A2259DD8A002FA5C6 /* Panelr.swift in Sources */, 35C36F712259E185002FA5C6 /* NoTimezoneView.swift in Sources */, diff --git a/Clocker/Overall App/ConfigExport.swift b/Clocker/Overall App/ConfigExport.swift new file mode 100644 index 00000000..bffcd351 --- /dev/null +++ b/Clocker/Overall App/ConfigExport.swift @@ -0,0 +1,83 @@ +// Copyright © 2015 Abhishek Banthia + +import Foundation +import CoreModelKit + +struct ConfigExport { + + private func generateJSONFromDefaults() { + let selectedKeys: Set = 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() + var clockerPrefs: [String:Any] = [:] + for (key, value) in dictionaryRep { + if selectedKeys.contains(key) { + print("Key is \(key) and value is \(value)") + clockerPrefs[key] = value + } + } + + 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 + } + + let timezoneDict = ["Timezones": decodeJSON] + 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) + } + + let json = try JSONSerialization.data(withJSONObject: clockerPrefs, options: .prettyPrinted) + print(json) + } catch { + print("Failure Observed \(error.localizedDescription)") + } + + } + +}