Skip to content

Commit

Permalink
Add ConfigExport file.
Browse files Browse the repository at this point in the history
  • Loading branch information
n0shake committed Jul 21, 2021
1 parent 7c39ce4 commit 0f6107e
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Clocker/Clocker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -347,10 +347,10 @@
35C36F9E2259ED6D002FA5C6 /* EventCenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventCenter.swift; sourceTree = "<group>"; };
35C36F9F2259ED6D002FA5C6 /* RemindersHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemindersHandler.swift; sourceTree = "<group>"; };
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 = "<group>"; };
35E65124268EDD2E00E3E1E3 /* Toasty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toasty.swift; sourceTree = "<group>"; };
9A0385BA269E3434003B5E72 /* StandardMenubarHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardMenubarHandlerTests.swift; sourceTree = "<group>"; };
9A0385BF269E8891003B5E72 /* PermissionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionsTests.swift; sourceTree = "<group>"; };
9A066A03269A2BF600C3F1FB /* Keys.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Keys.plist; path = Internal/Keys.plist; sourceTree = "<group>"; };
9A13BAD71CA87F08007C6CBE /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/Panel.xib; sourceTree = "<group>"; };
9A13BAE11CA882FA007C6CBE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
9A13BAEB1CA88A76007C6CBE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -628,6 +628,7 @@
35C36F3A2259D892002FA5C6 /* Timer.swift */,
3595FACF227F88BC0044A12A /* UserDefaults + KVOExtensions.swift */,
35C11E2024873A550031F18C /* VersionUpdateHandler.swift */,
35DFBCEE26A8468900D6648B /* ConfigExport.swift */,
);
path = "Overall App";
sourceTree = "<group>";
Expand Down Expand Up @@ -888,7 +889,6 @@
DD4F7BF913C30F9F00825C6E = {
isa = PBXGroup;
children = (
9A066A03269A2BF600C3F1FB /* Keys.plist */,
35B2FEE4259A2C25005DA84D /* CoreModelKit */,
35B2FED4259A2244005DA84D /* CoreLoggerKit */,
35B2FEB1259A1649005DA84D /* StartupKit */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
83 changes: 83 additions & 0 deletions Clocker/Overall App/ConfigExport.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright © 2015 Abhishek Banthia

import Foundation
import CoreModelKit

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()
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)")
}

}

}

0 comments on commit 0f6107e

Please sign in to comment.