diff --git a/Calendr.xcodeproj/project.pbxproj b/Calendr.xcodeproj/project.pbxproj index 36e039be..d5443ea0 100644 --- a/Calendr.xcodeproj/project.pbxproj +++ b/Calendr.xcodeproj/project.pbxproj @@ -1314,7 +1314,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.11.6; + MARKETING_VERSION = 1.11.7; PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h"; @@ -1340,7 +1340,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.11.6; + MARKETING_VERSION = 1.11.7; PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h"; diff --git a/Calendr/Main/AppDelegate.swift b/Calendr/Main/AppDelegate.swift index 3af413e7..162553d6 100644 --- a/Calendr/Main/AppDelegate.swift +++ b/Calendr/Main/AppDelegate.swift @@ -26,6 +26,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { let notificationCenter = NotificationCenter.default let workspace = NSWorkspace.shared + registerDefaultPrefs(in: userDefaults) + let dateProvider = DateProvider(notificationCenter: notificationCenter, userDefaults: userDefaults) viewController = MainViewController( @@ -42,3 +44,28 @@ class AppDelegate: NSObject, NSApplicationDelegate { setUpResignFocus() } } + +func registerDefaultPrefs(in userDefaults: UserDefaults, calendar: Calendar = .current) { + + userDefaults.register(defaults: [ + Prefs.statusItemIconEnabled: true, + Prefs.statusItemDateEnabled: true, + Prefs.statusItemBackgroundEnabled: false, + Prefs.statusItemIconStyle: StatusItemIconStyle.calendar.rawValue, + Prefs.statusItemDateStyle: StatusItemDateStyle.short.rawValue, + Prefs.statusItemDateFormat: "E d MMM yyyy", + Prefs.showEventStatusItem: false, + Prefs.eventStatusItemFontSize: 12, + Prefs.eventStatusItemCheckRange: 6, + Prefs.eventStatusItemLength: 18, + Prefs.eventStatusItemDetectNotch: false, + Prefs.calendarScaling: 1, + Prefs.firstWeekday: calendar.firstWeekday, + Prefs.highlightedWeekdays: [0, 6], + Prefs.showWeekNumbers: false, + Prefs.showDeclinedEvents: false, + Prefs.preserveSelectedDate: false, + Prefs.showPastEvents: true, + Prefs.transparencyLevel: 2 + ]) +} diff --git a/Calendr/Main/MockMainViewController.swift b/Calendr/Main/MockMainViewController.swift index 40e4f760..81ec2c63 100644 --- a/Calendr/Main/MockMainViewController.swift +++ b/Calendr/Main/MockMainViewController.swift @@ -19,6 +19,8 @@ class MockMainViewController: MainViewController { userDefaults.setVolatileDomain([:], forName: UserDefaults.registrationDomain) userDefaults.removePersistentDomain(forName: Self.className()) + registerDefaultPrefs(in: userDefaults) + userDefaults.setValuesForKeys([ Prefs.firstWeekday: dateProvider.calendar.firstWeekday, Prefs.statusItemDateStyle: DateFormatter.Style.full.rawValue, diff --git a/Calendr/Settings/Prefs+UserDefaults.swift b/Calendr/Settings/Prefs+UserDefaults.swift index 89e680d4..27d4f8f6 100644 --- a/Calendr/Settings/Prefs+UserDefaults.swift +++ b/Calendr/Settings/Prefs+UserDefaults.swift @@ -139,7 +139,7 @@ extension UserDefaults { } @objc dynamic var highlightedWeekdays: [Int] { - get { array(forKey: Prefs.highlightedWeekdays) as! [Int] } + get { array(forKey: Prefs.highlightedWeekdays) as? [Int] ?? [] } set { set(newValue, forKey: Prefs.highlightedWeekdays) } } } diff --git a/Calendr/Settings/SettingsViewModel.swift b/Calendr/Settings/SettingsViewModel.swift index 66c2ea13..d031b7cf 100644 --- a/Calendr/Settings/SettingsViewModel.swift +++ b/Calendr/Settings/SettingsViewModel.swift @@ -143,29 +143,6 @@ class SettingsViewModel: StatusItemSettings, NextEventSettings, CalendarSettings userDefaults: UserDefaults, notificationCenter: NotificationCenter ) { - - userDefaults.register(defaults: [ - Prefs.statusItemIconEnabled: true, - Prefs.statusItemDateEnabled: true, - Prefs.statusItemBackgroundEnabled: false, - Prefs.statusItemIconStyle: StatusItemIconStyle.calendar.rawValue, - Prefs.statusItemDateStyle: StatusItemDateStyle.short.rawValue, - Prefs.statusItemDateFormat: dateFormatPlaceholder, - Prefs.showEventStatusItem: false, - Prefs.eventStatusItemFontSize: 12, - Prefs.eventStatusItemCheckRange: 6, - Prefs.eventStatusItemLength: 18, - Prefs.eventStatusItemDetectNotch: false, - Prefs.calendarScaling: 1, - Prefs.firstWeekday: dateProvider.calendar.firstWeekday, - Prefs.highlightedWeekdays: [0, 6], - Prefs.showWeekNumbers: false, - Prefs.showDeclinedEvents: false, - Prefs.preserveSelectedDate: false, - Prefs.showPastEvents: true, - Prefs.transparencyLevel: 2 - ]) - // MARK: - Observers toggleAutoLaunch = autoLauncher.rx.observer(for: \.isEnabled) diff --git a/CalendrTests/SettingsViewModelTests.swift b/CalendrTests/SettingsViewModelTests.swift index 8392193b..9af2b02c 100644 --- a/CalendrTests/SettingsViewModelTests.swift +++ b/CalendrTests/SettingsViewModelTests.swift @@ -30,8 +30,8 @@ class SettingsViewModelTests: XCTestCase { var userDefaultsStatusItemBackgroundEnabled: Bool? { userDefaults.object(forKey: Prefs.statusItemBackgroundEnabled) as! Bool? } var userDefaultsStatusItemDateStyle: Int? { userDefaults.object(forKey: Prefs.statusItemDateStyle) as! Int? } var userDefaultsShowEventStatusItem: Bool? { userDefaults.object(forKey: Prefs.showEventStatusItem) as! Bool? } - var userDefaultsEventStatusItemFontSize: Float? { userDefaults.object(forKey: Prefs.eventStatusItemFontSize) as! Float? } var userDefaultsEventStatusItemCheckRange: Int? { userDefaults.object(forKey: Prefs.eventStatusItemCheckRange) as! Int? } + var userDefaultsEventStatusItemFontSize: Float? { userDefaults.object(forKey: Prefs.eventStatusItemFontSize) as! Float? } var userDefaultsEventStatusItemLength: Int? { userDefaults.object(forKey: Prefs.eventStatusItemLength) as! Int? } var userDefaultsEventStatusItemDetectNotch: Bool? { userDefaults.object(forKey: Prefs.eventStatusItemDetectNotch) as! Bool? } var userDefaultsCalendarScaling: Double? { userDefaults.object(forKey: Prefs.calendarScaling) as! Double? } @@ -46,9 +46,6 @@ class SettingsViewModelTests: XCTestCase { override func setUp() { userDefaults.setVolatileDomain([:], forName: UserDefaults.registrationDomain) userDefaults.removePersistentDomain(forName: className) - } - - func testDefaultSettings() { XCTAssertNil(userDefaultsStatusItemIconEnabled) XCTAssertNil(userDefaultsStatusItemDateEnabled) @@ -56,9 +53,9 @@ class SettingsViewModelTests: XCTestCase { XCTAssertNil(userDefaultsStatusItemDateStyle) XCTAssertNil(userDefaultsShowEventStatusItem) XCTAssertNil(userDefaultsEventStatusItemCheckRange) + XCTAssertNil(userDefaultsEventStatusItemFontSize) XCTAssertNil(userDefaultsEventStatusItemLength) XCTAssertNil(userDefaultsEventStatusItemDetectNotch) - XCTAssertNil(userDefaultsEventStatusItemFontSize) XCTAssertNil(userDefaultsCalendarScaling) XCTAssertNil(userDefaultsFirstWeekday) XCTAssertNil(userDefaultsHighlightedWeekdays) @@ -68,7 +65,10 @@ class SettingsViewModelTests: XCTestCase { XCTAssertNil(userDefaultsShowPastEvents) XCTAssertNil(userDefaultsTransparency) - dateProvider.m_calendar.firstWeekday = 3 + registerDefaultPrefs(in: userDefaults, calendar: .gregorian.with(firstWeekday: 3)) + } + + func testDefaultSettings() { var showStatusItemIcon: Bool? var showStatusItemDate: Bool?