diff --git a/Clocker/AppDelegate.swift b/Clocker/AppDelegate.swift index 2a556b4..436913e 100644 --- a/Clocker/AppDelegate.swift +++ b/Clocker/AppDelegate.swift @@ -2,6 +2,7 @@ import Cocoa import CoreLoggerKit +import CoreModelKit open class AppDelegate: NSObject, NSApplicationDelegate { private lazy var floatingWindow: FloatingWindowController = FloatingWindowController.shared() @@ -45,6 +46,9 @@ open class AppDelegate: NSObject, NSApplicationDelegate { // Initializing the event store takes really long EventCenter.sharedCenter() + // Required for migrating our model type to CoreModelKit + NSKeyedUnarchiver.setClass(CoreModelKit.TimezoneData.classForKeyedUnarchiver(), forClassName: "Clocker.TimezoneData") + AppDefaults.initialize() // Check if we can show the onboarding flow! diff --git a/Clocker/Clocker.xcodeproj/project.pbxproj b/Clocker/Clocker.xcodeproj/project.pbxproj index 1d17a7a..e9ebe48 100755 --- a/Clocker/Clocker.xcodeproj/project.pbxproj +++ b/Clocker/Clocker.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 3595FAD0227F88BC0044A12A /* UserDefaults + KVOExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3595FACF227F88BC0044A12A /* UserDefaults + KVOExtensions.swift */; }; 35B2FEC0259A186F005DA84D /* StartupKit in Frameworks */ = {isa = PBXBuildFile; productRef = 35B2FEBF259A186F005DA84D /* StartupKit */; }; 35B2FEDD259A2291005DA84D /* CoreLoggerKit in Frameworks */ = {isa = PBXBuildFile; productRef = 35B2FEDC259A2291005DA84D /* CoreLoggerKit */; }; + 35B2FEF1259A2DB1005DA84D /* CoreModelKit in Frameworks */ = {isa = PBXBuildFile; productRef = 35B2FEF0259A2DB1005DA84D /* CoreModelKit */; }; 35C11E2124873A550031F18C /* VersionUpdateHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C11E2024873A550031F18C /* VersionUpdateHandler.swift */; }; 35C36EF122595F14002FA5C6 /* OnboardingPermissionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36EE822595F13002FA5C6 /* OnboardingPermissionsViewController.swift */; }; 35C36EF222595F14002FA5C6 /* OnboardingWelcomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36EE922595F13002FA5C6 /* OnboardingWelcomeViewController.swift */; }; @@ -62,7 +63,6 @@ 35C36F592259DD8A002FA5C6 /* TimezoneCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F552259DD8A002FA5C6 /* TimezoneCellView.swift */; }; 35C36F5A2259DD8A002FA5C6 /* Panelr.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F562259DD8A002FA5C6 /* Panelr.swift */; }; 35C36F5D2259DD96002FA5C6 /* TimezoneDataOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F5B2259DD96002FA5C6 /* TimezoneDataOperations.swift */; }; - 35C36F5E2259DD96002FA5C6 /* TimezoneData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F5C2259DD96002FA5C6 /* TimezoneData.swift */; }; 35C36F612259DE67002FA5C6 /* NotesPopover.xib in Resources */ = {isa = PBXBuildFile; fileRef = 35C36F5F2259DE67002FA5C6 /* NotesPopover.xib */; }; 35C36F622259DE67002FA5C6 /* NotesPopover.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F602259DE67002FA5C6 /* NotesPopover.swift */; }; 35C36F662259DF4C002FA5C6 /* ReviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C36F642259DF4C002FA5C6 /* ReviewView.swift */; }; @@ -83,7 +83,6 @@ 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 */; }; - 35EB537325310FD200311068 /* TimezoneDataEqualityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3545C52A22612BCC00121E25 /* TimezoneDataEqualityTests.swift */; }; 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 */; }; @@ -122,7 +121,6 @@ 9AB6F1622259D1B000A44663 /* PreferencesDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AB6F1602259D1B000A44663 /* PreferencesDataSource.swift */; }; 9AB6F1642259D1B900A44663 /* ParentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AB6F1632259D1B800A44663 /* ParentViewController.swift */; }; 9AB6F1672259D23200A44663 /* PermissionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AB6F1662259D23200A44663 /* PermissionsViewController.swift */; }; - 9AB6F16A2259D2A600A44663 /* SearchResults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AB6F1692259D2A600A44663 /* SearchResults.swift */; }; 9AB89E031CE97A4900EC8EB1 /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9AB89E021CE97A4900EC8EB1 /* Media.xcassets */; }; 9ABFB3801CA6882000E10745 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9ABFB37F1CA6882000E10745 /* ApplicationServices.framework */; }; 9AC678E41C1ABAB9003B4F6B /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9AC678E31C1ABAB9003B4F6B /* QuartzCore.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; @@ -229,7 +227,6 @@ 3508CCA9259A0027000E3530 /* StatusContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusContainerView.swift; sourceTree = ""; }; 352AF497232E07B400D96FA7 /* hi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hi; path = hi.lproj/InfoPlist.strings; sourceTree = ""; }; 352AF499232E07B400D96FA7 /* hi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hi; path = hi.lproj/Localizable.strings; sourceTree = ""; }; - 3545C52A22612BCC00121E25 /* TimezoneDataEqualityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimezoneDataEqualityTests.swift; sourceTree = ""; }; 354BB0842574810500097121 /* Keys.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Keys.plist; path = ../Internal/Keys.plist; sourceTree = ""; }; 3569A44E25441F320087E254 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = ""; }; 357391852507277500D30819 /* HourMarkerViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HourMarkerViewItem.swift; sourceTree = ""; }; @@ -237,6 +234,7 @@ 3595FACF227F88BC0044A12A /* UserDefaults + KVOExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefaults + KVOExtensions.swift"; sourceTree = ""; }; 35B2FEB1259A1649005DA84D /* StartupKit */ = {isa = PBXFileReference; lastKnownFileType = folder; path = StartupKit; sourceTree = ""; }; 35B2FED4259A2244005DA84D /* CoreLoggerKit */ = {isa = PBXFileReference; lastKnownFileType = folder; path = CoreLoggerKit; sourceTree = ""; }; + 35B2FEE4259A2C25005DA84D /* CoreModelKit */ = {isa = PBXFileReference; lastKnownFileType = folder; path = CoreModelKit; sourceTree = ""; }; 35C11E2024873A550031F18C /* VersionUpdateHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionUpdateHandler.swift; sourceTree = ""; }; 35C36EE822595F13002FA5C6 /* OnboardingPermissionsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OnboardingPermissionsViewController.swift; sourceTree = ""; }; 35C36EE922595F13002FA5C6 /* OnboardingWelcomeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OnboardingWelcomeViewController.swift; sourceTree = ""; }; @@ -283,7 +281,6 @@ 35C36F552259DD8A002FA5C6 /* TimezoneCellView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimezoneCellView.swift; sourceTree = ""; }; 35C36F562259DD8A002FA5C6 /* Panelr.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Panelr.swift; sourceTree = ""; }; 35C36F5B2259DD96002FA5C6 /* TimezoneDataOperations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimezoneDataOperations.swift; sourceTree = ""; }; - 35C36F5C2259DD96002FA5C6 /* TimezoneData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimezoneData.swift; sourceTree = ""; }; 35C36F5F2259DE67002FA5C6 /* NotesPopover.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NotesPopover.xib; sourceTree = ""; }; 35C36F602259DE67002FA5C6 /* NotesPopover.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotesPopover.swift; sourceTree = ""; }; 35C36F642259DF4C002FA5C6 /* ReviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReviewView.swift; sourceTree = ""; }; @@ -380,7 +377,6 @@ 9AB6F1602259D1B000A44663 /* PreferencesDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreferencesDataSource.swift; sourceTree = ""; }; 9AB6F1632259D1B800A44663 /* ParentViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ParentViewController.swift; sourceTree = ""; }; 9AB6F1662259D23200A44663 /* PermissionsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PermissionsViewController.swift; sourceTree = ""; }; - 9AB6F1692259D2A600A44663 /* SearchResults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchResults.swift; sourceTree = ""; }; 9AB89E021CE97A4900EC8EB1 /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Media.xcassets; sourceTree = ""; }; 9ABFB37F1CA6882000E10745 /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = System/Library/Frameworks/ApplicationServices.framework; sourceTree = SDKROOT; }; 9AC678E31C1ABAB9003B4F6B /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; @@ -447,6 +443,7 @@ 9ACF469D1DCBD45200C49B51 /* Quartz.framework in Frameworks */, 9AC678E41C1ABAB9003B4F6B /* QuartzCore.framework in Frameworks */, 9A5E75E4204CC39700119939 /* ShortcutRecorder.framework in Frameworks */, + 35B2FEF1259A2DB1005DA84D /* CoreModelKit in Frameworks */, 35B2FEDD259A2291005DA84D /* CoreLoggerKit in Frameworks */, 35B2FEC0259A186F005DA84D /* StartupKit in Frameworks */, 9A6D93371CF3E82F005A8690 /* CoreImage.framework in Frameworks */, @@ -585,7 +582,6 @@ 35C36F512259DC85002FA5C6 /* Data Layer */ = { isa = PBXGroup; children = ( - 35C36F5C2259DD96002FA5C6 /* TimezoneData.swift */, 35C36F5B2259DD96002FA5C6 /* TimezoneDataOperations.swift */, ); path = "Data Layer"; @@ -758,7 +754,6 @@ 9AB6F1682259D26400A44663 /* Models */ = { isa = PBXGroup; children = ( - 9AB6F1692259D2A600A44663 /* SearchResults.swift */, ); path = Models; sourceTree = ""; @@ -796,7 +791,6 @@ children = ( C20839C921515C1E00C86589 /* ClockerUnitTests.swift */, C20839CB21515C1F00C86589 /* Info.plist */, - 3545C52A22612BCC00121E25 /* TimezoneDataEqualityTests.swift */, ); path = ClockerUnitTests; sourceTree = ""; @@ -824,6 +818,7 @@ DD4F7BF913C30F9F00825C6E = { isa = PBXGroup; children = ( + 35B2FEE4259A2C25005DA84D /* CoreModelKit */, 35B2FED4259A2244005DA84D /* CoreLoggerKit */, 35B2FEB1259A1649005DA84D /* StartupKit */, 354BB0842574810500097121 /* Keys.plist */, @@ -966,6 +961,7 @@ packageProductDependencies = ( 35B2FEBF259A186F005DA84D /* StartupKit */, 35B2FEDC259A2291005DA84D /* CoreLoggerKit */, + 35B2FEF0259A2DB1005DA84D /* CoreModelKit */, ); productName = Popup; productReference = DD4F7C0413C30F9F00825C6E /* Clocker.app */; @@ -1180,7 +1176,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 35EB537325310FD200311068 /* TimezoneDataEqualityTests.swift in Sources */, C20839CA21515C1E00C86589 /* ClockerUnitTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1246,7 +1241,6 @@ 35C36F2C2259D6FA002FA5C6 /* PanelController.swift in Sources */, 35C36F10225961DA002FA5C6 /* Constants.swift in Sources */, 35C36FA42259EEC2002FA5C6 /* AppDelegate.swift in Sources */, - 35C36F5E2259DD96002FA5C6 /* TimezoneData.swift in Sources */, 35C36F19225961DA002FA5C6 /* Enums.swift in Sources */, 35C36F5A2259DD8A002FA5C6 /* Panelr.swift in Sources */, 35C36F712259E185002FA5C6 /* NoTimezoneView.swift in Sources */, @@ -1275,7 +1269,6 @@ 35C36EF922595F14002FA5C6 /* OnboardingParentViewController.swift in Sources */, 35C36F4E2259D981002FA5C6 /* DateFormatterManager.swift in Sources */, 35C36F0D225961DA002FA5C6 /* TimePeriod.swift in Sources */, - 9AB6F16A2259D2A600A44663 /* SearchResults.swift in Sources */, 35C36EFB2259616B002FA5C6 /* Solar.swift in Sources */, 35C36F662259DF4C002FA5C6 /* ReviewView.swift in Sources */, 35C36EF522595F14002FA5C6 /* OnboardingSearchController.swift in Sources */, @@ -2176,6 +2169,10 @@ isa = XCSwiftPackageProductDependency; productName = CoreLoggerKit; }; + 35B2FEF0259A2DB1005DA84D /* CoreModelKit */ = { + isa = XCSwiftPackageProductDependency; + productName = CoreModelKit; + }; /* End XCSwiftPackageProductDependency section */ }; rootObject = DD4F7BFB13C30F9F00825C6E /* Project object */; diff --git a/Clocker/Clocker/LocationController.swift b/Clocker/Clocker/LocationController.swift index f25b844..5b9dba3 100644 --- a/Clocker/Clocker/LocationController.swift +++ b/Clocker/Clocker/LocationController.swift @@ -3,6 +3,7 @@ import Cocoa import CoreLocation import CoreLoggerKit +import CoreModelKit class LocationController: NSObject { public static let sharedInstance = LocationController() diff --git a/Clocker/ClockerUnitTests/ClockerUnitTests.swift b/Clocker/ClockerUnitTests/ClockerUnitTests.swift index b3d021d..7844565 100644 --- a/Clocker/ClockerUnitTests/ClockerUnitTests.swift +++ b/Clocker/ClockerUnitTests/ClockerUnitTests.swift @@ -1,5 +1,7 @@ // Copyright © 2015 Abhishek Banthia +import CoreModelKit + @testable import Clocker import XCTest @@ -164,34 +166,34 @@ class ClockerUnitTests: XCTestCase { UserDefaults.standard.set(NSNumber(value: 0), forKey: CLSelectedTimeZoneFormatKey) // Set to 12 hour format dataObject.setShouldOverrideGlobalTimeFormat(0) // Respect Global Preference - XCTAssertTrue(dataObject.timezoneFormat() == "h:mm a") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "h:mm a") dataObject.setShouldOverrideGlobalTimeFormat(1) // 12-Hour Format - XCTAssertTrue(dataObject.timezoneFormat() == "h:mm a") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "h:mm a") dataObject.setShouldOverrideGlobalTimeFormat(2) // 24-Hour format - XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "HH:mm") // Skip 3 since it's a placeholder dataObject.setShouldOverrideGlobalTimeFormat(4) // 12-Hour with seconds - XCTAssertTrue(dataObject.timezoneFormat() == "h:mm:ss a") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "h:mm:ss a") dataObject.setShouldOverrideGlobalTimeFormat(5) // 24-Hour format with seconds - XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm:ss") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "HH:mm:ss") // Skip 6 since it's a placeholder dataObject.setShouldOverrideGlobalTimeFormat(7) // 12-hour with preceding zero and no seconds - XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm a") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "hh:mm a") dataObject.setShouldOverrideGlobalTimeFormat(8) // 12-hour with preceding zero and seconds - XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm:ss a") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "hh:mm:ss a") // Skip 9 since it's a placeholder dataObject.setShouldOverrideGlobalTimeFormat(10) // 12-hour without am/pm and seconds - XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "hh:mm") dataObject.setShouldOverrideGlobalTimeFormat(11) // 12-hour with preceding zero and seconds - XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm:ss") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "hh:mm:ss") } func testTimezoneFormatWithDefaultSetAs24HourFormat() { @@ -199,34 +201,34 @@ class ClockerUnitTests: XCTestCase { UserDefaults.standard.set(NSNumber(value: 1), forKey: CLSelectedTimeZoneFormatKey) // Set to 24-Hour Format dataObject.setShouldOverrideGlobalTimeFormat(0) - XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "HH:mm") dataObject.setShouldOverrideGlobalTimeFormat(1) // 12-Hour Format - XCTAssertTrue(dataObject.timezoneFormat() == "h:mm a") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "h:mm a") dataObject.setShouldOverrideGlobalTimeFormat(2) // 24-Hour format - XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "HH:mm") // Skip 3 since it's a placeholder dataObject.setShouldOverrideGlobalTimeFormat(4) // 12-Hour with seconds - XCTAssertTrue(dataObject.timezoneFormat() == "h:mm:ss a") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "h:mm:ss a") dataObject.setShouldOverrideGlobalTimeFormat(5) // 24-Hour format with seconds - XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm:ss") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "HH:mm:ss") // Skip 6 since it's a placeholder dataObject.setShouldOverrideGlobalTimeFormat(7) // 12-hour with preceding zero and no seconds - XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm a") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "hh:mm a") dataObject.setShouldOverrideGlobalTimeFormat(8) // 12-hour with preceding zero and seconds - XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm:ss a") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "hh:mm:ss a") // Skip 9 since it's a placeholder dataObject.setShouldOverrideGlobalTimeFormat(10) // 12-hour without am/pm and seconds - XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "hh:mm") dataObject.setShouldOverrideGlobalTimeFormat(11) // 12-hour with preceding zero and seconds - XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm:ss") + XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "hh:mm:ss") } func testFormattedLabel() { @@ -281,7 +283,7 @@ class ClockerUnitTests: XCTestCase { for locale in Locale.availableIdentifiers { let currentLocale = Locale(identifier: locale) let dateFormatter = DateFormatterManager.dateFormatterWithFormat(with: .none, - format: dataObject.timezoneFormat(), + format: dataObject.timezoneFormat(DataStore.shared().timezoneFormat()), timezoneIdentifier: dataObject.timezone(), locale: currentLocale) let convertedDate = dateFormatter.string(from: newDate) diff --git a/Clocker/CoreModelKit/.gitignore b/Clocker/CoreModelKit/.gitignore new file mode 100644 index 0000000..95c4320 --- /dev/null +++ b/Clocker/CoreModelKit/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ diff --git a/Clocker/CoreModelKit/Package.swift b/Clocker/CoreModelKit/Package.swift new file mode 100644 index 0000000..fe1bb6d --- /dev/null +++ b/Clocker/CoreModelKit/Package.swift @@ -0,0 +1,35 @@ +// swift-tools-version:5.3 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "CoreModelKit", + platforms: [ + .macOS(.v10_12), + ], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "CoreModelKit", + targets: ["CoreModelKit"] + ), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + .package(path: "../CoreLoggerKit/"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "CoreModelKit", + dependencies: ["CoreLoggerKit"] + ), + .testTarget( + name: "CoreModelKitTests", + dependencies: ["CoreModelKit", "CoreLoggerKit"] + ), + ] +) diff --git a/Clocker/CoreModelKit/README.md b/Clocker/CoreModelKit/README.md new file mode 100644 index 0000000..c963321 --- /dev/null +++ b/Clocker/CoreModelKit/README.md @@ -0,0 +1,3 @@ +# CoreModelKit + +A description of this package. diff --git a/Clocker/Preferences/General/Models/SearchResults.swift b/Clocker/CoreModelKit/Sources/CoreModelKit/SearchResults.swift similarity index 100% rename from Clocker/Preferences/General/Models/SearchResults.swift rename to Clocker/CoreModelKit/Sources/CoreModelKit/SearchResults.swift diff --git a/Clocker/Panel/Data Layer/TimezoneData.swift b/Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift similarity index 91% rename from Clocker/Panel/Data Layer/TimezoneData.swift rename to Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift index 65bac35..8259629 100644 --- a/Clocker/Panel/Data Layer/TimezoneData.swift +++ b/Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift @@ -3,6 +3,14 @@ import Cocoa import CoreLoggerKit +struct ModelConstants { + static let customLabel = "customLabel" + static let timezoneName = "formattedAddress" + static let placeIdentifier = "place_id" + static let timezoneID = "timezoneID" + static let emptyString = "" +} + public struct DateFormat { public static let twelveHour = "h:mm a" public static let twelveHourWithSeconds = "h:mm:ss a" @@ -15,7 +23,7 @@ public struct DateFormat { } // Non-class type cannot conform to NSCoding! -class TimezoneData: NSObject, NSCoding { +public class TimezoneData: NSObject, NSCoding { public enum SelectionType: Int { case city case timezone @@ -26,7 +34,7 @@ class TimezoneData: NSObject, NSCoding { case menu } - enum TimezoneOverride: Int { + public enum TimezoneOverride: Int { case globalFormat = 0 case twelveHourFormat = 1 case twentyFourFormat = 2 @@ -58,10 +66,10 @@ class TimezoneData: NSObject, NSCoding { public var customLabel: String? public var formattedAddress: String? public var placeID: String? - public var timezoneID: String? = CLEmptyString + public var timezoneID: String? = ModelConstants.emptyString public var latitude: Double? public var longitude: Double? - public var note: String? = CLEmptyString + public var note: String? = ModelConstants.emptyString public var nextUpdate: Date? = Date() public var sunriseTime: Date? public var sunsetTime: Date? @@ -74,20 +82,20 @@ class TimezoneData: NSObject, NSCoding { public override init() { selectionType = .timezone isFavourite = 0 - note = CLEmptyString + note = ModelConstants.emptyString isSystemTimezone = false overrideFormat = .globalFormat placeID = UUID().uuidString } public init(with dictionary: [String: Any]) { - if let label = dictionary[CLCustomLabel] as? String { + if let label = dictionary[ModelConstants.customLabel] as? String { customLabel = label } else { customLabel = nil } - if let timezone = dictionary[CLTimezoneID] as? String { + if let timezone = dictionary[ModelConstants.timezoneID] as? String { timezoneID = timezone } else { timezoneID = "Error" @@ -105,13 +113,13 @@ class TimezoneData: NSObject, NSCoding { longitude = -0.0 } - if let placeIdentifier = dictionary[CLPlaceIdentifier] as? String { + if let placeIdentifier = dictionary[ModelConstants.placeIdentifier] as? String { placeID = placeIdentifier } else { placeID = "Error" } - if let address = dictionary[CLTimezoneName] as? String { + if let address = dictionary[ModelConstants.timezoneName] as? String { formattedAddress = address } else { formattedAddress = "Error" @@ -124,7 +132,7 @@ class TimezoneData: NSObject, NSCoding { if let noteString = dictionary["note"] as? String { note = noteString } else { - note = CLEmptyString + note = ModelConstants.emptyString } isSystemTimezone = false @@ -132,7 +140,7 @@ class TimezoneData: NSObject, NSCoding { overrideFormat = .globalFormat } - required init?(coder aDecoder: NSCoder) { + public required init?(coder aDecoder: NSCoder) { customLabel = aDecoder.decodeObject(forKey: "customLabel") as? String formattedAddress = aDecoder.decodeObject(forKey: "formattedAddress") as? String @@ -176,7 +184,7 @@ class TimezoneData: NSObject, NSCoding { return nil } - func encode(with aCoder: NSCoder) { + public func encode(with aCoder: NSCoder) { aCoder.encode(placeID, forKey: "place_id") aCoder.encode(formattedAddress, forKey: "formattedAddress") @@ -235,7 +243,7 @@ class TimezoneData: NSObject, NSCoding { } public func setLabel(_ label: String) { - customLabel = !label.isEmpty ? label : CLEmptyString + customLabel = !label.isEmpty ? label : ModelConstants.emptyString } public func setShouldOverrideGlobalTimeFormat(_ shouldOverride: Int) { @@ -354,21 +362,11 @@ class TimezoneData: NSObject, NSCoding { } extension TimezoneData { - private func adjustStatusBarAppearance() { - guard let statusItem = (NSApplication.shared.delegate as? AppDelegate)?.statusItemForPanel() else { - return - } - - statusItem.setupStatusItem() - } -} - -extension TimezoneData { - override var description: String { + public override var description: String { return objectDescription() } - override var debugDescription: String { + public override var debugDescription: String { return objectDescription() } diff --git a/Clocker/ClockerUnitTests/TimezoneDataEqualityTests.swift b/Clocker/CoreModelKit/Tests/CoreModelKitTests/TimezoneDataEqualityTests.swift similarity index 98% rename from Clocker/ClockerUnitTests/TimezoneDataEqualityTests.swift rename to Clocker/CoreModelKit/Tests/CoreModelKitTests/TimezoneDataEqualityTests.swift index ee0a5c5..a143140 100644 --- a/Clocker/ClockerUnitTests/TimezoneDataEqualityTests.swift +++ b/Clocker/CoreModelKit/Tests/CoreModelKitTests/TimezoneDataEqualityTests.swift @@ -1,8 +1,7 @@ // Copyright © 2015 Abhishek Banthia +import CoreModelKit import Foundation - -@testable import Clocker import XCTest class TimezoneDataEqualityTests: XCTestCase { diff --git a/Clocker/CoreModelKit/Tests/CoreModelKitTests/XCTestManifests.swift b/Clocker/CoreModelKit/Tests/CoreModelKitTests/XCTestManifests.swift new file mode 100644 index 0000000..0f55ba6 --- /dev/null +++ b/Clocker/CoreModelKit/Tests/CoreModelKitTests/XCTestManifests.swift @@ -0,0 +1,9 @@ +import XCTest + +#if !canImport(ObjectiveC) + public func allTests() -> [XCTestCaseEntry] { + return [ + testCase(CoreModelKitTests.allTests), + ] + } +#endif diff --git a/Clocker/CoreModelKit/Tests/LinuxMain.swift b/Clocker/CoreModelKit/Tests/LinuxMain.swift new file mode 100644 index 0000000..0aa1edf --- /dev/null +++ b/Clocker/CoreModelKit/Tests/LinuxMain.swift @@ -0,0 +1,7 @@ +import XCTest + +import CoreModelKitTests + +var tests = [XCTestCaseEntry]() +tests += CoreModelKitTests.allTests() +XCTMain(tests) diff --git a/Clocker/Onboarding/OnboardingSearchController.swift b/Clocker/Onboarding/OnboardingSearchController.swift index bf4d943..e6d645f 100644 --- a/Clocker/Onboarding/OnboardingSearchController.swift +++ b/Clocker/Onboarding/OnboardingSearchController.swift @@ -2,6 +2,7 @@ import Cocoa import CoreLoggerKit +import CoreModelKit class OnboardingSearchController: NSViewController { @IBOutlet private var appName: NSTextField! diff --git a/Clocker/Overall App/DataStore.swift b/Clocker/Overall App/DataStore.swift index f91885e..fc81610 100644 --- a/Clocker/Overall App/DataStore.swift +++ b/Clocker/Overall App/DataStore.swift @@ -2,6 +2,7 @@ import Cocoa import CoreLoggerKit +import CoreModelKit enum ViewType { case futureSlider diff --git a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift index 2b5f6f1..d2f14e3 100644 --- a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift +++ b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift @@ -3,6 +3,7 @@ import Cocoa import CoreLocation import CoreLoggerKit +import CoreModelKit class TimezoneDataOperations: NSObject { private var dataObject: TimezoneData! diff --git a/Clocker/Panel/Notes Popover/NotesPopover.swift b/Clocker/Panel/Notes Popover/NotesPopover.swift index 0a4d22f..31762c8 100644 --- a/Clocker/Panel/Notes Popover/NotesPopover.swift +++ b/Clocker/Panel/Notes Popover/NotesPopover.swift @@ -2,6 +2,7 @@ import Cocoa import CoreLoggerKit +import CoreModelKit class NotesPopover: NSViewController { private enum OverrideType { diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index 05f183e..6ac2db4 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -2,6 +2,7 @@ import Cocoa import CoreLoggerKit +import CoreModelKit import EventKit struct PanelConstants { diff --git a/Clocker/Panel/UI/TimezoneDataSource.swift b/Clocker/Panel/UI/TimezoneDataSource.swift index 4eb7a60..06dbb73 100644 --- a/Clocker/Panel/UI/TimezoneDataSource.swift +++ b/Clocker/Panel/UI/TimezoneDataSource.swift @@ -1,6 +1,7 @@ // Copyright © 2015 Abhishek Banthia import Cocoa +import CoreModelKit class TimezoneDataSource: NSObject { var timezones: [TimezoneData] = [] diff --git a/Clocker/Preferences/Appearance/AppearanceViewController.swift b/Clocker/Preferences/Appearance/AppearanceViewController.swift index 7f1ea02..921ed42 100644 --- a/Clocker/Preferences/Appearance/AppearanceViewController.swift +++ b/Clocker/Preferences/Appearance/AppearanceViewController.swift @@ -2,6 +2,7 @@ import Cocoa import CoreLoggerKit +import CoreModelKit class AppearanceViewController: ParentViewController { @IBOutlet var timeFormat: NSPopUpButton! diff --git a/Clocker/Preferences/General/PreferencesDataSource.swift b/Clocker/Preferences/General/PreferencesDataSource.swift index ef97212..f6a728b 100644 --- a/Clocker/Preferences/General/PreferencesDataSource.swift +++ b/Clocker/Preferences/General/PreferencesDataSource.swift @@ -2,6 +2,7 @@ import Cocoa import CoreLoggerKit +import CoreModelKit struct PreferencesDataSourceConstants { static let timezoneNameIdentifier = "formattedAddress" diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index 5b67239..d8c9326 100644 --- a/Clocker/Preferences/General/PreferencesViewController.swift +++ b/Clocker/Preferences/General/PreferencesViewController.swift @@ -2,6 +2,7 @@ import Cocoa import CoreLoggerKit +import CoreModelKit import StartupKit struct PreferencesConstants { diff --git a/Clocker/Preferences/General/SearchDataSource.swift b/Clocker/Preferences/General/SearchDataSource.swift index 2034fe9..52bf17a 100644 --- a/Clocker/Preferences/General/SearchDataSource.swift +++ b/Clocker/Preferences/General/SearchDataSource.swift @@ -1,6 +1,7 @@ // Copyright © 2015 Abhishek Banthia import Cocoa +import CoreModelKit enum RowType { case timezoneHeader diff --git a/Clocker/Preferences/Menu Bar/MenubarHandler.swift b/Clocker/Preferences/Menu Bar/MenubarHandler.swift index 3cc2523..e2c0cf7 100644 --- a/Clocker/Preferences/Menu Bar/MenubarHandler.swift +++ b/Clocker/Preferences/Menu Bar/MenubarHandler.swift @@ -2,6 +2,7 @@ import Cocoa import CoreLoggerKit +import CoreModelKit import EventKit class MenubarHandler: NSObject { diff --git a/Clocker/Preferences/Menu Bar/StatusContainerView.swift b/Clocker/Preferences/Menu Bar/StatusContainerView.swift index 1e991cc..c20dd81 100644 --- a/Clocker/Preferences/Menu Bar/StatusContainerView.swift +++ b/Clocker/Preferences/Menu Bar/StatusContainerView.swift @@ -2,6 +2,7 @@ import Cocoa import CoreLoggerKit +import CoreModelKit func bufferCalculatedWidth() -> Int { var totalWidth = 55 diff --git a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift index 88e9379..989b173 100644 --- a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift +++ b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift @@ -2,6 +2,7 @@ import Cocoa import CoreLoggerKit +import CoreModelKit private enum MenubarState { case compactText diff --git a/Clocker/Preferences/Menu Bar/StatusItemView.swift b/Clocker/Preferences/Menu Bar/StatusItemView.swift index 0b3f5bb..13d92de 100644 --- a/Clocker/Preferences/Menu Bar/StatusItemView.swift +++ b/Clocker/Preferences/Menu Bar/StatusItemView.swift @@ -1,6 +1,7 @@ // Copyright © 2015 Abhishek Banthia import Cocoa +import CoreModelKit var defaultParagraphStyle: NSMutableParagraphStyle { let paragraphStyle = NSMutableParagraphStyle()