Browse Source

Merge branch 'master' of https://github.com/n0shake/Clocker

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
5c9f914140
  1. 6
      Clocker/AppDelegate.swift
  2. 16
      Clocker/Clocker.xcodeproj/project.pbxproj
  3. 73
      Clocker/ClockerUnitTests/AppDelegateTests.swift
  4. 11
      Clocker/ClockerUnitTests/ClockerUnitTests.swift
  5. 36
      Clocker/ClockerUnitTests/DateFormatterManagerTests.swift
  6. 4
      Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift
  7. 12
      Clocker/ClockerUnitTests/ThemerTests.swift
  8. 6
      Clocker/CoreLoggerKit/Package.swift
  9. 2
      Clocker/CoreLoggerKit/Tests/CoreLoggerKitTests/CoreLoggerKitTests.swift
  10. 2
      Clocker/CoreLoggerKit/Tests/CoreLoggerKitTests/XCTestManifests.swift
  11. 8
      Clocker/CoreModelKit/Package.swift
  12. 6
      Clocker/CoreModelKit/Sources/CoreModelKit/SearchResults.swift
  13. 8
      Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift
  14. 2
      Clocker/CoreModelKit/Tests/CoreModelKitTests/XCTestManifests.swift
  15. 6
      Clocker/Dependencies/Date Additions/TimePeriodChain.swift
  16. 4
      Clocker/Events and Reminders/CalendarHandler.swift
  17. 4
      Clocker/Menu Bar/StatusContainerView.swift
  18. 8
      Clocker/Menu Bar/StatusItemView.swift
  19. 6
      Clocker/Onboarding/OnboardingSearchController.swift
  20. 4
      Clocker/Overall App/ConfigExport.swift
  21. 4
      Clocker/Overall App/DataStore.swift
  22. 25
      Clocker/Overall App/DateFormatterManager.swift
  23. 12
      Clocker/Overall App/Themer.swift
  24. 2
      Clocker/Overall App/Timer.swift
  25. 10
      Clocker/Overall App/VersionUpdateHandler.swift
  26. 28
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  27. 4
      Clocker/Panel/Notes Popover/NotesPopover.swift
  28. 2
      Clocker/Panel/Notes Popover/TextViewWithPlaceholder.swift
  29. 2
      Clocker/Panel/PanelController.swift
  30. 19
      Clocker/Panel/ParentPanelController.swift
  31. 2
      Clocker/Panel/UI/PanelTableView.swift
  32. 4
      Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift
  33. 2
      Clocker/Preferences/Appearance/AppearanceViewController.swift
  34. 3
      Clocker/Preferences/Calendar/CalendarViewController.swift
  35. 4
      Clocker/Preferences/General/PreferencesDataSource.swift
  36. 15
      Clocker/Preferences/General/PreferencesViewController.swift
  37. 5
      Clocker/Preferences/Menu Bar/MenubarTitleProvider.swift
  38. 68
      Clocker/Preferences/Menu Bar/StatusContainerView.swift
  39. 46
      Clocker/Preferences/Menu Bar/StatusItemHandler.swift
  40. 26
      Clocker/Preferences/Menu Bar/StatusItemView.swift
  41. 28
      Clocker/Preferences/Menu Bar/UpcomingEventStatusItemView.swift
  42. 6
      Clocker/StartupKit/Package.swift

6
Clocker/AppDelegate.swift

@ -16,7 +16,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
panelObserver?.invalidate() panelObserver?.invalidate()
} }
open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change _: [NSKeyValueChangeKey: Any]?, context _: UnsafeMutableRawPointer?) { override open func observeValue(forKeyPath keyPath: String?, of object: Any?, change _: [NSKeyValueChangeKey: Any]?, context _: UnsafeMutableRawPointer?) {
if let path = keyPath, path == PreferencesConstants.hotKeyPathIdentifier { if let path = keyPath, path == PreferencesConstants.hotKeyPathIdentifier {
let hotKeyCenter = PTHotKeyCenter.shared() let hotKeyCenter = PTHotKeyCenter.shared()
@ -262,10 +262,6 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
return statusBarHandler return statusBarHandler
} }
open func setPanelDefaults() {
panelController.updateDefaultPreferences()
}
open func setupMenubarTimer() { open func setupMenubarTimer() {
statusBarHandler.setupStatusItem() statusBarHandler.setupStatusItem()
} }

16
Clocker/Clocker.xcodeproj/project.pbxproj

@ -7,7 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
3508CC942599FFEC000E3530 /* MenubarHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3508CC932599FFEC000E3530 /* MenubarHandler.swift */; }; 3508CC942599FFEC000E3530 /* MenubarTitleProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3508CC932599FFEC000E3530 /* MenubarTitleProvider.swift */; };
3508CC9A259A0001000E3530 /* StatusItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3508CC99259A0001000E3530 /* StatusItemView.swift */; }; 3508CC9A259A0001000E3530 /* StatusItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3508CC99259A0001000E3530 /* StatusItemView.swift */; };
3508CC9F259A000E000E3530 /* StatusItemHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3508CC9E259A000E000E3530 /* StatusItemHandler.swift */; }; 3508CC9F259A000E000E3530 /* StatusItemHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3508CC9E259A000E000E3530 /* StatusItemHandler.swift */; };
3508CCAA259A0027000E3530 /* StatusContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3508CCA9259A0027000E3530 /* StatusContainerView.swift */; }; 3508CCAA259A0027000E3530 /* StatusContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3508CCA9259A0027000E3530 /* StatusContainerView.swift */; };
@ -51,6 +51,8 @@
3548C45F26BEEFB400AFB533 /* UpcomingEventsDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3548C45E26BEEFB400AFB533 /* UpcomingEventsDataSource.swift */; }; 3548C45F26BEEFB400AFB533 /* UpcomingEventsDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3548C45E26BEEFB400AFB533 /* UpcomingEventsDataSource.swift */; };
3548C46126BEEFE400AFB533 /* UpcomingEventViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3548C46026BEEFE400AFB533 /* UpcomingEventViewItem.swift */; }; 3548C46126BEEFE400AFB533 /* UpcomingEventViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3548C46026BEEFE400AFB533 /* UpcomingEventViewItem.swift */; };
35584D1427EF8EB5006E3EAD /* ThemerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35584D1327EF8EB5006E3EAD /* ThemerTests.swift */; }; 35584D1427EF8EB5006E3EAD /* ThemerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35584D1327EF8EB5006E3EAD /* ThemerTests.swift */; };
35584D1827F0B019006E3EAD /* DateFormatterManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35584D1727F0B019006E3EAD /* DateFormatterManagerTests.swift */; };
35584D1A27F0B64E006E3EAD /* AppDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35584D1927F0B64E006E3EAD /* AppDelegateTests.swift */; };
357391872507277500D30819 /* TimeMarkerViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 357391852507277500D30819 /* TimeMarkerViewItem.swift */; }; 357391872507277500D30819 /* TimeMarkerViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 357391852507277500D30819 /* TimeMarkerViewItem.swift */; };
357391882507277500D30819 /* HourMarkerViewItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = 357391862507277500D30819 /* HourMarkerViewItem.xib */; }; 357391882507277500D30819 /* HourMarkerViewItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = 357391862507277500D30819 /* HourMarkerViewItem.xib */; };
3579765E2680208C009DDA6E /* ParentPanelController+ModernSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3579765D2680208C009DDA6E /* ParentPanelController+ModernSlider.swift */; }; 3579765E2680208C009DDA6E /* ParentPanelController+ModernSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3579765D2680208C009DDA6E /* ParentPanelController+ModernSlider.swift */; };
@ -255,7 +257,7 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
3508CC932599FFEC000E3530 /* MenubarHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenubarHandler.swift; sourceTree = "<group>"; }; 3508CC932599FFEC000E3530 /* MenubarTitleProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenubarTitleProvider.swift; sourceTree = "<group>"; };
3508CC99259A0001000E3530 /* StatusItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusItemView.swift; sourceTree = "<group>"; }; 3508CC99259A0001000E3530 /* StatusItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusItemView.swift; sourceTree = "<group>"; };
3508CC9E259A000E000E3530 /* StatusItemHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusItemHandler.swift; sourceTree = "<group>"; }; 3508CC9E259A000E000E3530 /* StatusItemHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusItemHandler.swift; sourceTree = "<group>"; };
3508CCA9259A0027000E3530 /* StatusContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusContainerView.swift; sourceTree = "<group>"; }; 3508CCA9259A0027000E3530 /* StatusContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusContainerView.swift; sourceTree = "<group>"; };
@ -286,6 +288,8 @@
3552066427AF6488000EF08F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/InfoPlist.strings; sourceTree = "<group>"; }; 3552066427AF6488000EF08F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/InfoPlist.strings; sourceTree = "<group>"; };
3552066527AF6489000EF08F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = "<group>"; }; 3552066527AF6489000EF08F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = "<group>"; };
35584D1327EF8EB5006E3EAD /* ThemerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemerTests.swift; sourceTree = "<group>"; }; 35584D1327EF8EB5006E3EAD /* ThemerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemerTests.swift; sourceTree = "<group>"; };
35584D1727F0B019006E3EAD /* DateFormatterManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateFormatterManagerTests.swift; sourceTree = "<group>"; };
35584D1927F0B64E006E3EAD /* AppDelegateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegateTests.swift; sourceTree = "<group>"; };
3569A44E25441F320087E254 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; }; 3569A44E25441F320087E254 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; };
357391852507277500D30819 /* TimeMarkerViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeMarkerViewItem.swift; sourceTree = "<group>"; }; 357391852507277500D30819 /* TimeMarkerViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeMarkerViewItem.swift; sourceTree = "<group>"; };
357391862507277500D30819 /* HourMarkerViewItem.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HourMarkerViewItem.xib; sourceTree = "<group>"; }; 357391862507277500D30819 /* HourMarkerViewItem.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HourMarkerViewItem.xib; sourceTree = "<group>"; };
@ -568,7 +572,7 @@
35C36EDF22595D9C002FA5C6 /* Menu Bar */ = { 35C36EDF22595D9C002FA5C6 /* Menu Bar */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
3508CC932599FFEC000E3530 /* MenubarHandler.swift */, 3508CC932599FFEC000E3530 /* MenubarTitleProvider.swift */,
3508CC99259A0001000E3530 /* StatusItemView.swift */, 3508CC99259A0001000E3530 /* StatusItemView.swift */,
3508CC9E259A000E000E3530 /* StatusItemHandler.swift */, 3508CC9E259A000E000E3530 /* StatusItemHandler.swift */,
3508CCA9259A0027000E3530 /* StatusContainerView.swift */, 3508CCA9259A0027000E3530 /* StatusContainerView.swift */,
@ -881,6 +885,8 @@
C20839CB21515C1F00C86589 /* Info.plist */, C20839CB21515C1F00C86589 /* Info.plist */,
9A0385BA269E3434003B5E72 /* StandardMenubarHandlerTests.swift */, 9A0385BA269E3434003B5E72 /* StandardMenubarHandlerTests.swift */,
35584D1327EF8EB5006E3EAD /* ThemerTests.swift */, 35584D1327EF8EB5006E3EAD /* ThemerTests.swift */,
35584D1727F0B019006E3EAD /* DateFormatterManagerTests.swift */,
35584D1927F0B64E006E3EAD /* AppDelegateTests.swift */,
); );
path = ClockerUnitTests; path = ClockerUnitTests;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1267,7 +1273,9 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
35584D1427EF8EB5006E3EAD /* ThemerTests.swift in Sources */, 35584D1427EF8EB5006E3EAD /* ThemerTests.swift in Sources */,
35584D1A27F0B64E006E3EAD /* AppDelegateTests.swift in Sources */,
9A0385BB269E3434003B5E72 /* StandardMenubarHandlerTests.swift in Sources */, 9A0385BB269E3434003B5E72 /* StandardMenubarHandlerTests.swift in Sources */,
35584D1827F0B019006E3EAD /* DateFormatterManagerTests.swift in Sources */,
C20839CA21515C1E00C86589 /* ClockerUnitTests.swift in Sources */, C20839CA21515C1E00C86589 /* ClockerUnitTests.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
@ -1317,7 +1325,7 @@
35C36F4F2259D981002FA5C6 /* AppDefaults.swift in Sources */, 35C36F4F2259D981002FA5C6 /* AppDefaults.swift in Sources */,
35C36F5D2259DD96002FA5C6 /* TimezoneDataOperations.swift in Sources */, 35C36F5D2259DD96002FA5C6 /* TimezoneDataOperations.swift in Sources */,
3548C45D26BEEF4C00AFB533 /* ParentPanelController+UpcomingEvents.swift in Sources */, 3548C45D26BEEF4C00AFB533 /* ParentPanelController+UpcomingEvents.swift in Sources */,
3508CC942599FFEC000E3530 /* MenubarHandler.swift in Sources */, 3508CC942599FFEC000E3530 /* MenubarTitleProvider.swift in Sources */,
35C36F14225961DA002FA5C6 /* Integer+DateTools.swift in Sources */, 35C36F14225961DA002FA5C6 /* Integer+DateTools.swift in Sources */,
35C36FA22259ED6D002FA5C6 /* RemindersHandler.swift in Sources */, 35C36FA22259ED6D002FA5C6 /* RemindersHandler.swift in Sources */,
35C36F622259DE67002FA5C6 /* NotesPopover.swift in Sources */, 35C36F622259DE67002FA5C6 /* NotesPopover.swift in Sources */,

73
Clocker/ClockerUnitTests/AppDelegateTests.swift

@ -0,0 +1,73 @@
// Copyright © 2015 Abhishek Banthia
import XCTest
@testable import Clocker
class AppDelegateTests: XCTestCase {
func testStatusItemIsInitialized() throws {
let subject = NSApplication.shared.delegate as? AppDelegate
let statusHandler = subject?.statusItemForPanel()
XCTAssertNotNil(EventCenter.sharedCenter)
XCTAssertNotNil(statusHandler)
}
func testDockMenu() throws {
let subject = NSApplication.shared.delegate as? AppDelegate
let dockMenu = subject?.applicationDockMenu(NSApplication.shared)
let items = dockMenu?.items ?? []
XCTAssertEqual(dockMenu?.title, "Quick Access")
XCTAssertEqual(items.first?.title, "Toggle Panel")
XCTAssertEqual(items[1].title, "Preferences")
XCTAssertEqual(items[1].keyEquivalent, ",")
XCTAssertEqual(items[2].title, "Hide from Dock")
// Test selections
XCTAssertEqual(items.first?.action, #selector(AppDelegate.togglePanel(_:)))
XCTAssertEqual(items[2].action, #selector(AppDelegate.hideFromDock))
items.forEach { menuItem in
XCTAssertTrue(menuItem.isEnabled)
}
}
func testSetupMenubarTimer() {
let subject = NSApplication.shared.delegate as? AppDelegate
let statusItemHandler = subject?.statusItemForPanel()
XCTAssertEqual(statusItemHandler?.statusItem.autosaveName, NSStatusItem.AutosaveName("ClockerStatusItem"))
}
func testFloatingWindow() {
let subject = NSApplication.shared.delegate as? AppDelegate
let previousWindows = NSApplication.shared.windows
XCTAssertEqual(previousWindows.count, 1) // Only the status bar window should be present
subject?.setupFloatingWindow(true)
let floatingWindow = NSApplication.shared.windows.first { window in
if ((window.windowController as? FloatingWindowController) != nil) {
return true
}
return false
}
XCTAssertNotNil(floatingWindow)
XCTAssertEqual(floatingWindow?.windowController?.windowFrameAutosaveName, NSWindow.FrameAutosaveName("FloatingWindowAutoSave"))
subject?.setupFloatingWindow(false)
let closedFloatingWindow = NSApplication.shared.windows.first { window in
if ((window.windowController as? FloatingWindowController) != nil) {
return true
}
return false
}
XCTAssertNotNil(closedFloatingWindow)
}
}

11
Clocker/ClockerUnitTests/ClockerUnitTests.swift

@ -392,4 +392,15 @@ class ClockerUnitTests: XCTestCase {
XCTAssertNotNil(convertedDate) XCTAssertNotNil(convertedDate)
} }
} }
func testStringFiltering() {
let stringWithComma = "Mumbai, Maharashtra"
let stringWithoutComma = "Mumbai"
let emptyString = ""
XCTAssertEqual(stringWithComma.filteredName(), "Mumbai")
XCTAssertEqual(stringWithoutComma.filteredName(), "Mumbai")
XCTAssertEqual(emptyString.filteredName(), "")
}
} }

36
Clocker/ClockerUnitTests/DateFormatterManagerTests.swift

@ -0,0 +1,36 @@
// Copyright © 2015 Abhishek Banthia
import XCTest
@testable import Clocker
class DateFormatterManagerTests: XCTestCase {
func testRegularDateFormatter() throws {
let subject = DateFormatterManager.dateFormatter(with: .medium, for: "UTC")
XCTAssertEqual(subject.dateStyle, .medium)
XCTAssertEqual(subject.timeStyle, .medium)
XCTAssertEqual(subject.locale.identifier, "en_US")
XCTAssertEqual(subject.timeZone.identifier, "GMT")
}
func testDateFormatterWithFormat() throws {
let subject = DateFormatterManager.dateFormatterWithFormat(with: .none, format: "hh:mm a", timezoneIdentifier: "Asia/Calcutta")
XCTAssertEqual(subject.dateStyle, .none)
XCTAssertEqual(subject.timeStyle, .none)
XCTAssertEqual(subject.locale.identifier, "en_US")
XCTAssertEqual(subject.timeZone.identifier, "Asia/Calcutta")
XCTAssertEqual(subject.locale.identifier, "en_US")
XCTAssertEqual(subject.dateFormat, "hh:mm a")
}
func testLocalizedDateFormatter() throws {
let subject = DateFormatterManager.localizedFormatter(with: "hh:mm:ss", for: "America/Los_Angeles")
XCTAssertEqual(subject.dateStyle, .none)
XCTAssertEqual(subject.timeStyle, .none)
XCTAssertEqual(subject.locale.identifier, Locale.autoupdatingCurrent.identifier)
XCTAssertEqual(subject.timeZone.identifier, "America/Los_Angeles")
XCTAssertEqual(subject.dateFormat, "hh:mm:ss")
}
}

4
Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift

@ -30,7 +30,7 @@ class StandardMenubarHandlerTests: XCTestCase {
// Set standard menubar in Prefs // Set standard menubar in Prefs
UserDefaults.standard.set(1, forKey: CLMenubarCompactMode) UserDefaults.standard.set(1, forKey: CLMenubarCompactMode)
let menubarHandler = MenubarHandler() let menubarHandler = MenubarTitleProvider()
let menubarString = menubarHandler.titleForMenubar() ?? "" let menubarString = menubarHandler.titleForMenubar() ?? ""
// Test menubar string is present // Test menubar string is present
@ -58,7 +58,7 @@ class StandardMenubarHandlerTests: XCTestCase {
func testUnfavouritedTimezone_returnNilMenubarString() { func testUnfavouritedTimezone_returnNilMenubarString() {
// Wipe all timezones from UserDefaults // Wipe all timezones from UserDefaults
DataStore.shared().setTimezones(nil) DataStore.shared().setTimezones(nil)
let menubarHandler = MenubarHandler() let menubarHandler = MenubarTitleProvider()
let emptyMenubarString = menubarHandler.titleForMenubar() let emptyMenubarString = menubarHandler.titleForMenubar()
// Returns early because DataStore.menubarTimezones is nil // Returns early because DataStore.menubarTimezones is nil
XCTAssertNil(emptyMenubarString) XCTAssertNil(emptyMenubarString)

12
Clocker/ClockerUnitTests/ThemerTests.swift

@ -5,7 +5,6 @@ import XCTest
@testable import Clocker @testable import Clocker
class ThemerTests: XCTestCase { class ThemerTests: XCTestCase {
@available(macOS 10.14, *) @available(macOS 10.14, *)
func testSettingTheme() { func testSettingTheme() {
// Set to some random number should set to 0 // Set to some random number should set to 0
@ -29,7 +28,6 @@ class ThemerTests: XCTestCase {
let expectedTextColor = NSColor.black let expectedTextColor = NSColor.black
let expectedTextBackgroundColor = NSColor(deviceRed: 241.0 / 255.0, green: 241.0 / 255.0, blue: 241.0 / 255.0, alpha: 1.0) let expectedTextBackgroundColor = NSColor(deviceRed: 241.0 / 255.0, green: 241.0 / 255.0, blue: 241.0 / 255.0, alpha: 1.0)
let expectedShutdownImageName = "ellipsis.circle" let expectedShutdownImageName = "ellipsis.circle"
let expectedPreferenceImageName = "plus" let expectedPreferenceImageName = "plus"
let expectedPinImageName = "macwindow.on.rectangle" let expectedPinImageName = "macwindow.on.rectangle"
@ -55,7 +53,6 @@ class ThemerTests: XCTestCase {
let expectedForwardsImage = "goforward.15" let expectedForwardsImage = "goforward.15"
let expectedResetSliderImage = "xmark.circle.fill" let expectedResetSliderImage = "xmark.circle.fill"
XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor) XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor)
XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor) XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor)
XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor) XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor)
@ -97,7 +94,6 @@ class ThemerTests: XCTestCase {
let expectedTextColor = NSColor.white let expectedTextColor = NSColor.white
let expectedTextBackgroundColor = NSColor(deviceRed: 42.0 / 255.0, green: 55.0 / 255.0, blue: 62.0 / 255.0, alpha: 1.0) let expectedTextBackgroundColor = NSColor(deviceRed: 42.0 / 255.0, green: 55.0 / 255.0, blue: 62.0 / 255.0, alpha: 1.0)
let expectedShutdownImageName = "ellipsis.circle" let expectedShutdownImageName = "ellipsis.circle"
let expectedPreferenceImageName = "plus" let expectedPreferenceImageName = "plus"
let expectedPinImageName = "macwindow.on.rectangle" let expectedPinImageName = "macwindow.on.rectangle"
@ -123,7 +119,6 @@ class ThemerTests: XCTestCase {
let expectedForwardsImage = "goforward.15" let expectedForwardsImage = "goforward.15"
let expectedResetSliderImage = "xmark.circle.fill" let expectedResetSliderImage = "xmark.circle.fill"
XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor) XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor)
XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor) XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor)
XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor) XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor)
@ -166,7 +161,6 @@ class ThemerTests: XCTestCase {
let expectedTextColor = NSColor.textColor let expectedTextColor = NSColor.textColor
let expectedTextBackgroundColor = currentSystemTheme == .dark ? NSColor(deviceRed: 42.0 / 255.0, green: 55.0 / 255.0, blue: 62.0 / 255.0, alpha: 1.0) : NSColor(deviceRed: 241.0 / 255.0, green: 241.0 / 255.0, blue: 241.0 / 255.0, alpha: 1.0) let expectedTextBackgroundColor = currentSystemTheme == .dark ? NSColor(deviceRed: 42.0 / 255.0, green: 55.0 / 255.0, blue: 62.0 / 255.0, alpha: 1.0) : NSColor(deviceRed: 241.0 / 255.0, green: 241.0 / 255.0, blue: 241.0 / 255.0, alpha: 1.0)
let expectedShutdownImageName = "ellipsis.circle" let expectedShutdownImageName = "ellipsis.circle"
let expectedPreferenceImageName = "plus" let expectedPreferenceImageName = "plus"
let expectedPinImageName = "macwindow.on.rectangle" let expectedPinImageName = "macwindow.on.rectangle"
@ -192,7 +186,6 @@ class ThemerTests: XCTestCase {
let expectedForwardsImage = "goforward.15" let expectedForwardsImage = "goforward.15"
let expectedResetSliderImage = "xmark.circle.fill" let expectedResetSliderImage = "xmark.circle.fill"
XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor) XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor)
XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor) XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor)
XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor) XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor)
@ -233,7 +226,6 @@ class ThemerTests: XCTestCase {
let expectedTextColor = NSColor.black let expectedTextColor = NSColor.black
let expectedTextBackgroundColor = NSColor(deviceRed: 238.0 / 255.0, green: 232.0 / 255.0, blue: 213.0 / 255.0, alpha: 1.0) let expectedTextBackgroundColor = NSColor(deviceRed: 238.0 / 255.0, green: 232.0 / 255.0, blue: 213.0 / 255.0, alpha: 1.0)
let expectedShutdownImageName = "ellipsis.circle" let expectedShutdownImageName = "ellipsis.circle"
let expectedPreferenceImageName = "plus" let expectedPreferenceImageName = "plus"
let expectedPinImageName = "macwindow.on.rectangle" let expectedPinImageName = "macwindow.on.rectangle"
@ -259,7 +251,6 @@ class ThemerTests: XCTestCase {
let expectedForwardsImage = "goforward.15" let expectedForwardsImage = "goforward.15"
let expectedResetSliderImage = "xmark.circle.fill" let expectedResetSliderImage = "xmark.circle.fill"
XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor) XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor)
XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor) XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor)
XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor) XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor)
@ -301,7 +292,6 @@ class ThemerTests: XCTestCase {
let expectedTextColor = NSColor.white let expectedTextColor = NSColor.white
let expectedTextBackgroundColor = NSColor(deviceRed: 88.0 / 255.0, green: 110.0 / 255.0, blue: 117.0 / 255.0, alpha: 1.0) let expectedTextBackgroundColor = NSColor(deviceRed: 88.0 / 255.0, green: 110.0 / 255.0, blue: 117.0 / 255.0, alpha: 1.0)
let expectedShutdownImageName = "ellipsis.circle" let expectedShutdownImageName = "ellipsis.circle"
let expectedPreferenceImageName = "plus" let expectedPreferenceImageName = "plus"
let expectedPinImageName = "macwindow.on.rectangle" let expectedPinImageName = "macwindow.on.rectangle"
@ -327,7 +317,6 @@ class ThemerTests: XCTestCase {
let expectedForwardsImage = "goforward.15" let expectedForwardsImage = "goforward.15"
let expectedResetSliderImage = "xmark.circle.fill" let expectedResetSliderImage = "xmark.circle.fill"
XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor) XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor)
XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor) XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor)
XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor) XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor)
@ -358,5 +347,4 @@ class ThemerTests: XCTestCase {
XCTAssertEqual(subject.goForwardsImage()?.accessibilityDescription, expectedForwardsImage) XCTAssertEqual(subject.goForwardsImage()?.accessibilityDescription, expectedForwardsImage)
XCTAssertEqual(subject.resetModernSliderImage()?.accessibilityDescription, expectedResetSliderImage) XCTAssertEqual(subject.resetModernSliderImage()?.accessibilityDescription, expectedResetSliderImage)
} }
} }

6
Clocker/CoreLoggerKit/Package.swift

@ -6,13 +6,13 @@ import PackageDescription
let package = Package( let package = Package(
name: "CoreLoggerKit", name: "CoreLoggerKit",
platforms: [ platforms: [
.macOS(.v10_12), .macOS(.v10_12)
], ],
products: [ products: [
.library( .library(
name: "CoreLoggerKit", name: "CoreLoggerKit",
targets: ["CoreLoggerKit"] targets: ["CoreLoggerKit"]
), )
], ],
dependencies: [], dependencies: [],
targets: [ targets: [
@ -23,6 +23,6 @@ let package = Package(
.testTarget( .testTarget(
name: "CoreLoggerKitTests", name: "CoreLoggerKitTests",
dependencies: ["CoreLoggerKit"] dependencies: ["CoreLoggerKit"]
), )
] ]
) )

2
Clocker/CoreLoggerKit/Tests/CoreLoggerKitTests/CoreLoggerKitTests.swift

@ -3,6 +3,6 @@ import XCTest
final class CoreLoggerKitTests: XCTestCase { final class CoreLoggerKitTests: XCTestCase {
static var allTests = [ static var allTests = [
("testExample", testExample), ("testExample", testExample)
] ]
} }

2
Clocker/CoreLoggerKit/Tests/CoreLoggerKitTests/XCTestManifests.swift

@ -3,7 +3,7 @@ import XCTest
#if !canImport(ObjectiveC) #if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] { public func allTests() -> [XCTestCaseEntry] {
return [ return [
testCase(CoreLoggerKitTests.allTests), testCase(CoreLoggerKitTests.allTests)
] ]
} }
#endif #endif

8
Clocker/CoreModelKit/Package.swift

@ -6,19 +6,19 @@ import PackageDescription
let package = Package( let package = Package(
name: "CoreModelKit", name: "CoreModelKit",
platforms: [ platforms: [
.macOS(.v10_12), .macOS(.v10_12)
], ],
products: [ products: [
// Products define the executables and libraries a package produces, and make them visible to other packages. // Products define the executables and libraries a package produces, and make them visible to other packages.
.library( .library(
name: "CoreModelKit", name: "CoreModelKit",
targets: ["CoreModelKit"] targets: ["CoreModelKit"]
), )
], ],
dependencies: [ dependencies: [
// Dependencies declare other packages that this package depends on. // Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"), // .package(url: /* package url */, from: "1.0.0"),
.package(path: "../CoreLoggerKit/"), .package(path: "../CoreLoggerKit/")
], ],
targets: [ targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets are the basic building blocks of a package. A target can define a module or a test suite.
@ -30,6 +30,6 @@ let package = Package(
.testTarget( .testTarget(
name: "CoreModelKitTests", name: "CoreModelKitTests",
dependencies: ["CoreModelKit", "CoreLoggerKit"] dependencies: ["CoreModelKit", "CoreLoggerKit"]
), )
] ]
) )

6
Clocker/CoreModelKit/Sources/CoreModelKit/SearchResults.swift

@ -2,7 +2,7 @@
import Cocoa import Cocoa
public struct ResultStatus { public enum ResultStatus {
public static let okay = "OK" public static let okay = "OK"
public static let zeroResults = "ZERO_RESULTS" public static let zeroResults = "ZERO_RESULTS"
public static let requestDenied = "REQUEST_DENIED" public static let requestDenied = "REQUEST_DENIED"
@ -57,8 +57,8 @@ public struct SearchResult: Codable {
} }
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case results = "results" case results
case status = "status" case status
case errorMessage = "error_message" case errorMessage = "error_message"
} }
} }

8
Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift

@ -66,7 +66,7 @@ public class TimezoneData: NSObject, NSCoding {
// Suffix // Suffix
NSNumber(integerLiteral: 9): DateFormat.twelveHourWithoutSuffix, NSNumber(integerLiteral: 9): DateFormat.twelveHourWithoutSuffix,
NSNumber(integerLiteral: 10): DateFormat.twelveHourWithoutSuffixAndSeconds, NSNumber(integerLiteral: 10): DateFormat.twelveHourWithoutSuffixAndSeconds,
NSNumber(integerLiteral: 11): DateFormat.epochTime, NSNumber(integerLiteral: 11): DateFormat.epochTime
] ]
public var customLabel: String? public var customLabel: String?
@ -85,7 +85,7 @@ public class TimezoneData: NSObject, NSCoding {
public var isSystemTimezone = false public var isSystemTimezone = false
public var overrideFormat: TimezoneOverride = .globalFormat public var overrideFormat: TimezoneOverride = .globalFormat
public override init() { override public init() {
selectionType = .timezone selectionType = .timezone
isFavourite = 0 isFavourite = 0
note = ModelConstants.emptyString note = ModelConstants.emptyString
@ -268,7 +268,7 @@ public class TimezoneData: NSObject, NSCoding {
return formatInString.contains("ss") return formatInString.contains("ss")
} }
public override var hash: Int { override public var hash: Int {
guard let placeIdentifier = placeID, let timezone = timezoneID else { guard let placeIdentifier = placeID, let timezone = timezoneID else {
return -1 return -1
} }
@ -276,7 +276,7 @@ public class TimezoneData: NSObject, NSCoding {
return placeIdentifier.hashValue ^ timezone.hashValue return placeIdentifier.hashValue ^ timezone.hashValue
} }
public override func isEqual(_ object: Any?) -> Bool { override public func isEqual(_ object: Any?) -> Bool {
guard let compared = object as? TimezoneData else { guard let compared = object as? TimezoneData else {
return false return false
} }

2
Clocker/CoreModelKit/Tests/CoreModelKitTests/XCTestManifests.swift

@ -3,7 +3,7 @@ import XCTest
#if !canImport(ObjectiveC) #if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] { public func allTests() -> [XCTestCaseEntry] {
return [ return [
testCase(CoreModelKitTests.allTests), testCase(CoreModelKitTests.allTests)
] ]
} }
#endif #endif

6
Clocker/Dependencies/Date Additions/TimePeriodChain.swift

@ -138,15 +138,15 @@ open class TimePeriodChain: TimePeriodGroup {
_end = _end?.addingTimeInterval(duration) _end = _end?.addingTimeInterval(duration)
} }
public override func map<T>(_ transform: (TimePeriodProtocol) throws -> T) rethrows -> [T] { override public func map<T>(_ transform: (TimePeriodProtocol) throws -> T) rethrows -> [T] {
return try periods.map(transform) return try periods.map(transform)
} }
public override func filter(_ isIncluded: (TimePeriodProtocol) throws -> Bool) rethrows -> [TimePeriodProtocol] { override public func filter(_ isIncluded: (TimePeriodProtocol) throws -> Bool) rethrows -> [TimePeriodProtocol] {
return try periods.filter(isIncluded) return try periods.filter(isIncluded)
} }
internal override func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, TimePeriodProtocol) throws -> Result) rethrows -> Result { override internal func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, TimePeriodProtocol) throws -> Result) rethrows -> Result {
return try periods.reduce(initialResult, nextPartialResult) return try periods.reduce(initialResult, nextPartialResult)
} }

4
Clocker/Events and Reminders/CalendarHandler.swift

@ -163,7 +163,7 @@ extension EventCenter {
if filteredEvents.count == 1 { return filteredEvents.first } if filteredEvents.count == 1 { return filteredEvents.first }
// If there are multipl events coming up, prefer the ones the currentUser has accepted // If there are multiple events coming up, prefer the ones the currentUser has accepted
let acceptedEvents = filteredEvents.filter { let acceptedEvents = filteredEvents.filter {
$0.attendeStatus == .accepted $0.attendeStatus == .accepted
} }
@ -383,7 +383,7 @@ extension EventCenter {
// Borrowing logic from Ityscal // Borrowing logic from Ityscal
@discardableResult @discardableResult
private func findAppropriateURLs(_ description: String) -> URL? { private func findAppropriateURLs(_ description: String) -> URL? {
guard let results = EventCenter.dataDetector?.matches(in: description, options: .reportCompletion, range: NSMakeRange(0, description.count)) else { guard let results = EventCenter.dataDetector?.matches(in: description, options: .reportCompletion, range: NSRange(location: 0, length: description.count)) else {
return nil return nil
} }
for result in results { for result in results {

4
Clocker/Menu Bar/StatusContainerView.swift

@ -75,7 +75,7 @@ class StatusContainerView: NSView {
let timeBasedAttributes = [ let timeBasedAttributes = [
NSAttributedString.Key.font: compactModeTimeFont, NSAttributedString.Key.font: compactModeTimeFont,
NSAttributedString.Key.backgroundColor: NSColor.clear, NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, NSAttributedString.Key.paragraphStyle: defaultParagraphStyle
] ]
func containerWidth(for timezones: [Data]) -> CGFloat { func containerWidth(for timezones: [Data]) -> CGFloat {
@ -134,7 +134,7 @@ class StatusContainerView: NSView {
NSAttributedString.Key.font: compactModeTimeFont, NSAttributedString.Key.font: compactModeTimeFont,
NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear, NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, NSAttributedString.Key.paragraphStyle: defaultParagraphStyle
] ]
let operation = TimezoneDataOperations(with: timezone) let operation = TimezoneDataOperations(with: timezone)

8
Clocker/Menu Bar/StatusItemView.swift

@ -49,7 +49,7 @@ class StatusItemView: NSView {
NSAttributedString.Key.font: compactModeTimeFont, NSAttributedString.Key.font: compactModeTimeFont,
NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear, NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, NSAttributedString.Key.paragraphStyle: defaultParagraphStyle
] ]
return attributes return attributes
} }
@ -61,7 +61,7 @@ class StatusItemView: NSView {
NSAttributedString.Key.font: NSFont.boldSystemFont(ofSize: 10), NSAttributedString.Key.font: NSFont.boldSystemFont(ofSize: 10),
NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear, NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, NSAttributedString.Key.paragraphStyle: defaultParagraphStyle
] ]
return textFontAttributes return textFontAttributes
} }
@ -90,14 +90,14 @@ class StatusItemView: NSView {
locationView.leadingAnchor.constraint(equalTo: leadingAnchor), locationView.leadingAnchor.constraint(equalTo: leadingAnchor),
locationView.trailingAnchor.constraint(equalTo: trailingAnchor), locationView.trailingAnchor.constraint(equalTo: trailingAnchor),
locationView.topAnchor.constraint(equalTo: topAnchor, constant: 7), locationView.topAnchor.constraint(equalTo: topAnchor, constant: 7),
locationView.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 0.35), locationView.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 0.35)
]) ])
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
timeView.leadingAnchor.constraint(equalTo: leadingAnchor), timeView.leadingAnchor.constraint(equalTo: leadingAnchor),
timeView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0), timeView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0),
timeView.topAnchor.constraint(equalTo: locationView.bottomAnchor), timeView.topAnchor.constraint(equalTo: locationView.bottomAnchor),
timeView.bottomAnchor.constraint(equalTo: bottomAnchor), timeView.bottomAnchor.constraint(equalTo: bottomAnchor)
]) ])
} }

6
Clocker/Onboarding/OnboardingSearchController.swift

@ -227,7 +227,7 @@ class OnboardingSearchController: NSViewController {
"latitude": latitude, "latitude": latitude,
"longitude": longitude, "longitude": longitude,
"nextUpdate": CLEmptyString, "nextUpdate": CLEmptyString,
CLCustomLabel: filteredAddress, CLCustomLabel: filteredAddress
] as [String: Any] ] as [String: Any]
DataStore.shared().addTimezone(TimezoneData(with: newTimeZone)) DataStore.shared().addTimezone(TimezoneData(with: newTimeZone))
@ -412,7 +412,7 @@ class OnboardingSearchController: NSViewController {
CLTimezoneName: formattedAddress, CLTimezoneName: formattedAddress,
CLCustomLabel: formattedAddress, CLCustomLabel: formattedAddress,
CLTimezoneID: CLEmptyString, CLTimezoneID: CLEmptyString,
CLPlaceIdentifier: result.placeId, CLPlaceIdentifier: result.placeId
] as [String: Any] ] as [String: Any]
return TimezoneData(with: totalPackage) return TimezoneData(with: totalPackage)
@ -483,7 +483,7 @@ class ResultSectionHeaderTableViewCell: NSTableCellView {
class OnboardingSelectionTableRowView: NSTableRowView { class OnboardingSelectionTableRowView: NSTableRowView {
override func drawSelection(in _: NSRect) { override func drawSelection(in _: NSRect) {
if selectionHighlightStyle != .none { if selectionHighlightStyle != .none {
let selectionRect = NSInsetRect(bounds, 1, 1) let selectionRect = bounds.insetBy(dx: 1, dy: 1)
NSColor(calibratedWhite: 0.4, alpha: 1).setStroke() NSColor(calibratedWhite: 0.4, alpha: 1).setStroke()
NSColor(calibratedWhite: 0.4, alpha: 1).setFill() NSColor(calibratedWhite: 0.4, alpha: 1).setFill()
let selectionPath = NSBezierPath(roundedRect: selectionRect, xRadius: 6, yRadius: 6) let selectionPath = NSBezierPath(roundedRect: selectionRect, xRadius: 6, yRadius: 6)

4
Clocker/Overall App/ConfigExport.swift

@ -29,7 +29,7 @@ struct ConfigExport {
CLDefaultMenubarMode, CLDefaultMenubarMode,
CLInstallHomeIndicatorObject, CLInstallHomeIndicatorObject,
CLSwitchToCompactModeAlert, CLSwitchToCompactModeAlert,
CLDisplayDSTTransitionInfo, CLDisplayDSTTransitionInfo
]) ])
let dictionaryRep = UserDefaults.standard.dictionaryRepresentation() let dictionaryRep = UserDefaults.standard.dictionaryRepresentation()
var clockerPrefs: [String: Any] = [:] var clockerPrefs: [String: Any] = [:]
@ -53,7 +53,7 @@ struct ConfigExport {
"Latitude": customObject.latitude ?? 0.0, "Latitude": customObject.latitude ?? 0.0,
"Longitude": customObject.longitude ?? 0.0, "Longitude": customObject.longitude ?? 0.0,
"Place Identifier": customObject.placeID ?? "0.0", "Place Identifier": customObject.placeID ?? "0.0",
"Selection Type": "\(customObject.selectionType)", "Selection Type": "\(customObject.selectionType)"
] ]
return timezoneDictionary return timezoneDictionary
} }

4
Clocker/Overall App/DataStore.swift

@ -47,10 +47,6 @@ class DataStore: NSObject {
} }
func timezones() -> [Data] { func timezones() -> [Data] {
if let cloudPreferences = ubiquitousStore.object(forKey: CLDefaultPreferenceKey) as? [Data] {
return cloudPreferences
}
guard let preferences = userDefaults.object(forKey: CLDefaultPreferenceKey) as? [Data] else { guard let preferences = userDefaults.object(forKey: CLDefaultPreferenceKey) as? [Data] else {
return [] return []
} }

25
Clocker/Overall App/DateFormatterManager.swift

@ -3,7 +3,6 @@
import Cocoa import Cocoa
class DateFormatterManager: NSObject { class DateFormatterManager: NSObject {
public static let sharedInstance = DateFormatterManager()
private static var dateFormatter = DateFormatter() private static var dateFormatter = DateFormatter()
private static var calendarDateFormatter = DateFormatter() private static var calendarDateFormatter = DateFormatter()
@ -22,21 +21,6 @@ class DateFormatterManager: NSObject {
return dateFormatter return dateFormatter
} }
class func dateFormatterWithCalendar(with style: DateFormatter.Style) -> DateFormatter {
calendarDateFormatter.dateStyle = style
calendarDateFormatter.timeStyle = style
calendarDateFormatter.locale = USLocale
calendarDateFormatter.calendar = gregorianCalendar
return calendarDateFormatter
}
class func simpleFormatter(with style: DateFormatter.Style) -> DateFormatter {
simpleFormatter.dateStyle = style
simpleFormatter.timeStyle = style
simpleFormatter.locale = USLocale
return simpleFormatter
}
class func dateFormatterWithFormat(with style: DateFormatter.Style, format: String, timezoneIdentifier: String, locale: Locale = Locale(identifier: "en_US")) -> DateFormatter { class func dateFormatterWithFormat(with style: DateFormatter.Style, format: String, timezoneIdentifier: String, locale: Locale = Locale(identifier: "en_US")) -> DateFormatter {
specializedFormatter.dateStyle = style specializedFormatter.dateStyle = style
specializedFormatter.timeStyle = style specializedFormatter.timeStyle = style
@ -55,15 +39,6 @@ class DateFormatterManager: NSObject {
return dateFormatter return dateFormatter
} }
class func localizedCalendaricalDateFormatter(with format: String) -> DateFormatter {
calendarDateFormatter.dateStyle = .none
calendarDateFormatter.timeStyle = .none
calendarDateFormatter.locale = Locale.autoupdatingCurrent
calendarDateFormatter.dateFormat = format
calendarDateFormatter.calendar = gregorianCalendar
return calendarDateFormatter
}
class func localizedSimpleFormatter(_ format: String) -> DateFormatter { class func localizedSimpleFormatter(_ format: String) -> DateFormatter {
localizedSimpleFormatter.dateStyle = .none localizedSimpleFormatter.dateStyle = .none
localizedSimpleFormatter.timeStyle = .none localizedSimpleFormatter.timeStyle = .none

12
Clocker/Overall App/Themer.swift

@ -15,6 +15,7 @@ class Themer: NSObject {
case solarizedLight case solarizedLight
case solarizedDark case solarizedDark
} }
private static var sharedInstance = Themer(index: UserDefaults.standard.integer(forKey: CLThemeKey)) private static var sharedInstance = Themer(index: UserDefaults.standard.integer(forKey: CLThemeKey))
private var effectiveApperanceObserver: NSKeyValueObservation? private var effectiveApperanceObserver: NSKeyValueObservation?
private var themeIndex: Theme { private var themeIndex: Theme {
@ -49,15 +50,12 @@ class Themer: NSObject {
object: nil) object: nil)
if #available(macOS 10.14, *) { if #available(macOS 10.14, *) {
effectiveApperanceObserver = NSApp.observe(\.effectiveAppearance) { [weak self] (app, _) in effectiveApperanceObserver = NSApp.observe(\.effectiveAppearance) { _, _ in
if let sSelf = self {
sSelf.setAppAppearance()
NotificationCenter.default.post(name: .themeDidChangeNotification, object: nil) NotificationCenter.default.post(name: .themeDidChangeNotification, object: nil)
} }
} }
} }
} }
}
extension Themer { extension Themer {
class func shared() -> Themer { class func shared() -> Themer {
@ -94,6 +92,7 @@ extension Themer {
} }
// MARK: Color // MARK: Color
func sliderKnobColor() -> NSColor { func sliderKnobColor() -> NSColor {
switch themeIndex { switch themeIndex {
case .light: case .light:
@ -174,6 +173,7 @@ extension Themer {
} }
// MARK: Images // MARK: Images
func shutdownImage() -> NSImage { func shutdownImage() -> NSImage {
if let symbolImageForShutdown = symbolImage(for: "ellipsis.circle") { if let symbolImageForShutdown = symbolImage(for: "ellipsis.circle") {
return symbolImageForShutdown return symbolImageForShutdown
@ -449,9 +449,11 @@ extension Themer {
} else if themeIndex == .system { } else if themeIndex == .system {
appAppearance = retrieveCurrentSystem() == .dark ? NSAppearance(named: .darkAqua) : NSAppearance(named: .aqua) appAppearance = retrieveCurrentSystem() == .dark ? NSAppearance(named: .darkAqua) : NSAppearance(named: .aqua)
} }
if NSApp.appearance != appAppearance {
NSApp.appearance = appAppearance NSApp.appearance = appAppearance
} }
} }
}
private func fallbackImageProvider(_ lightImage: NSImage, private func fallbackImageProvider(_ lightImage: NSImage,
_ darkImage: NSImage, _ darkImage: NSImage,
@ -474,7 +476,5 @@ extension Themer {
} }
return themeIndex == .light ? lightImage : darkImage return themeIndex == .light ? lightImage : darkImage
} }
} }

2
Clocker/Overall App/Timer.swift

@ -118,7 +118,7 @@ open class Repeater: Equatable {
} }
/// Handler typealias /// Handler typealias
public typealias Observer = ((Repeater) -> Void) public typealias Observer = (Repeater) -> Void
/// Token assigned to the observer /// Token assigned to the observer
public typealias ObserverToken = UInt64 public typealias ObserverToken = UInt64

10
Clocker/Overall App/VersionUpdateHandler.swift

@ -172,7 +172,7 @@ class VersionUpdateHandler: NSObject {
lastVersionCopy = "0" lastVersionCopy = "0"
} }
var newVersionFound = false var newVersionFound = false
var details: String = "" var details = ""
let versions = dict.keys.sorted() let versions = dict.keys.sorted()
@ -242,20 +242,20 @@ class VersionUpdateHandler: NSObject {
y: 0.0, y: 0.0,
width: contentSize.width, width: contentSize.width,
height: contentSize.height)) height: contentSize.height))
textView.minSize = NSMakeSize(0.0, contentSize.height) textView.minSize = NSSize(width: 0.0, height: contentSize.height)
textView.maxSize = NSMakeSize(floatMax, floatMax) textView.maxSize = NSSize(width: floatMax, height: floatMax)
textView.isVerticallyResizable = true textView.isVerticallyResizable = true
textView.isHorizontallyResizable = false textView.isHorizontallyResizable = false
textView.isEditable = false textView.isEditable = false
textView.autoresizingMask = .width textView.autoresizingMask = .width
textView.textContainer?.containerSize = NSMakeSize(contentSize.width, floatMax) textView.textContainer?.containerSize = NSSize(width: contentSize.width, height: floatMax)
textView.textContainer?.widthTracksTextView = true textView.textContainer?.widthTracksTextView = true
textView.string = details textView.string = details
scrollView.documentView = textView scrollView.documentView = textView
textView.sizeToFit() textView.sizeToFit()
let height = min(200.0, scrollView.documentView?.frame.size.height ?? 200.0) + 3.0 let height = min(200.0, scrollView.documentView?.frame.size.height ?? 200.0) + 3.0
scrollView.frame = NSMakeRect(0.0, 0.0, scrollView.frame.size.width, height) scrollView.frame = NSRect(x: 0.0, y: 0.0, width: scrollView.frame.size.width, height: height)
alert.accessoryView = scrollView alert.accessoryView = scrollView
if ignoreButton.isEmpty == false { if ignoreButton.isEmpty == false {

28
Clocker/Panel/Data Layer/TimezoneDataOperations.swift

@ -77,32 +77,6 @@ extension TimezoneDataOperations {
return "Heads up! DST transition will occur in \(numberOfDays) \(suffix)." return "Heads up! DST transition will occur in \(numberOfDays) \(suffix)."
} }
private func checkForUpcomingEvents() -> (String, String)? {
if DataStore.shared().shouldDisplay(.showMeetingInMenubar) {
let filteredDates = EventCenter.sharedCenter().eventsForDate
let autoupdatingCal = EventCenter.sharedCenter().autoupdatingCalendar
guard let events = filteredDates[autoupdatingCal.startOfDay(for: Date())] else {
return nil
}
for event in events {
if event.event.startDate.timeIntervalSinceNow > 0, !event.isAllDay {
let timeForEventToStart = event.event.startDate.timeIntervalSinceNow / 60
if timeForEventToStart > 30 {
Logger.info("Our next event: \(event.event.title ?? "Error") starts in \(timeForEventToStart) mins")
continue
}
return EventCenter.sharedCenter().separateFormat(event: event.event)
}
}
}
return nil
}
func compactMenuTitle() -> String { func compactMenuTitle() -> String {
var subtitle = CLEmptyString var subtitle = CLEmptyString
@ -309,7 +283,7 @@ extension TimezoneDataOperations {
let unableToConvertDateParameters = [ let unableToConvertDateParameters = [
"New Date": newDate, "New Date": newDate,
"Timezone": dataObject.timezone(), "Timezone": dataObject.timezone(),
"Locale": dateFormatter.locale.identifier, "Locale": dateFormatter.locale.identifier
] as [String: Any] ] as [String: Any]
Logger.log(object: unableToConvertDateParameters, for: "Date conversion failure - New Date is nil") Logger.log(object: unableToConvertDateParameters, for: "Date conversion failure - New Date is nil")
return CLEmptyString return CLEmptyString

4
Clocker/Panel/Notes Popover/NotesPopover.swift

@ -73,7 +73,7 @@ class NotesPopover: NSViewController {
"1 hour before", "1 hour before",
"2 hour before", "2 hour before",
"1 day before", "1 day before",
"2 days before", "2 days before"
] ]
alertPopupButton.removeAllItems() alertPopupButton.removeAllItems()
@ -240,7 +240,7 @@ class NotesPopover: NSViewController {
let attributesDictionary = [ let attributesDictionary = [
NSAttributedString.Key.font: font, NSAttributedString.Key.font: font,
NSAttributedString.Key.foregroundColor: Themer.shared().mainTextColor(), NSAttributedString.Key.foregroundColor: Themer.shared().mainTextColor(),
NSAttributedString.Key.paragraphStyle: style, NSAttributedString.Key.paragraphStyle: style
] ]
button.attributedTitle = NSAttributedString(string: title, button.attributedTitle = NSAttributedString(string: title,

2
Clocker/Panel/Notes Popover/TextViewWithPlaceholder.swift

@ -18,7 +18,7 @@ class TextViewWithPlaceholder: NSTextView {
if let placeHolderFont = NSFont(name: "Avenir", size: 14) { if let placeHolderFont = NSFont(name: "Avenir", size: 14) {
let textDict = [ let textDict = [
NSAttributedString.Key.foregroundColor: NSColor.gray, NSAttributedString.Key.foregroundColor: NSColor.gray,
NSAttributedString.Key.font: placeHolderFont, NSAttributedString.Key.font: placeHolderFont
] ]
return NSAttributedString(string: " Add your notes here.", attributes: textDict) return NSAttributedString(string: " Add your notes here.", attributes: textDict)
} }

2
Clocker/Panel/PanelController.swift

@ -221,7 +221,7 @@ class PanelController: ParentPanelController {
"Show Upcoming Event View": showUpcomingEventView == "YES" ? "Yes" : "No", "Show Upcoming Event View": showUpcomingEventView == "YES" ? "Yes" : "No",
"Country": country, "Country": country,
"Calendar Access Provided": EventCenter.sharedCenter().calendarAccessGranted() ? "Yes" : "No", "Calendar Access Provided": EventCenter.sharedCenter().calendarAccessGranted() ? "Yes" : "No",
"Number of Timezones": preferences.count, "Number of Timezones": preferences.count
] ]
Logger.log(object: panelEvent, for: "openedPanel") Logger.log(object: panelEvent, for: "openedPanel")

19
Clocker/Panel/ParentPanelController.swift

@ -173,6 +173,15 @@ class ParentPanelController: NSWindowController {
updateReviewViewFontColor() updateReviewViewFontColor()
// Set the background color of the bottom buttons view to something different to indicate we're not in a release candidate
#if DEBUG
stackView.arrangedSubviews.last?.layer?.backgroundColor = NSColor(deviceRed: 255.0/255.0,
green: 150.0/255.0,
blue: 122.0/255.0,
alpha: 0.5).cgColor
stackView.arrangedSubviews.last?.toolTip = "Clocker is running in Debug Mode"
#endif
// Setup layers // Setup layers
futureSliderView.wantsLayer = true futureSliderView.wantsLayer = true
reviewView.wantsLayer = true reviewView.wantsLayer = true
@ -340,7 +349,7 @@ class ParentPanelController: NSWindowController {
let styleAttributes = [ let styleAttributes = [
NSAttributedString.Key.paragraphStyle: paragraphStyle, NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.font: NSFont(name: "Avenir-Light", size: 13) ?? NSFont.systemFont(ofSize: 13), NSAttributedString.Key.font: NSFont(name: "Avenir-Light", size: 13) ?? NSFont.systemFont(ofSize: 13)
] ]
let leftButtonAttributedTitle = NSAttributedString(string: leftButton.title, attributes: styleAttributes) let leftButtonAttributedTitle = NSAttributedString(string: leftButton.title, attributes: styleAttributes)
@ -573,7 +582,7 @@ class ParentPanelController: NSWindowController {
Logger.log(object: nil, for: "Deleted Timezone Through Swipe") Logger.log(object: nil, for: "Deleted Timezone Through Swipe")
} }
private lazy var menubarTitleHandler = MenubarHandler() private lazy var menubarTitleHandler = MenubarTitleProvider()
@objc func updateTime() { @objc func updateTime() {
let store = DataStore.shared() let store = DataStore.shared()
@ -785,7 +794,7 @@ class ParentPanelController: NSWindowController {
sharedDelegate.setupFloatingWindow(false) sharedDelegate.setupFloatingWindow(false)
} else { } else {
sharedDelegate.setupFloatingWindow(true) sharedDelegate.setupFloatingWindow(true)
sharedDelegate.setPanelDefaults() updateDefaultPreferences()
} }
let mode = inverseSelection.isEqual(to: NSNumber(value: 1)) ? "Floating Mode" : "Menubar Mode" let mode = inverseSelection.isEqual(to: NSNumber(value: 1)) ? "Floating Mode" : "Menubar Mode"
@ -895,7 +904,7 @@ class ParentPanelController: NSWindowController {
let styleAttributes = [ let styleAttributes = [
NSAttributedString.Key.paragraphStyle: paragraphStyle, NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.font: NSFont(name: "Avenir-Light", size: 13)!, NSAttributedString.Key.font: NSFont(name: "Avenir-Light", size: 13)!
] ]
leftButton.attributedTitle = NSAttributedString(string: "Not Really", attributes: styleAttributes) leftButton.attributedTitle = NSAttributedString(string: "Not Really", attributes: styleAttributes)
rightButton.attributedTitle = NSAttributedString(string: "Yes!", attributes: styleAttributes) rightButton.attributedTitle = NSAttributedString(string: "Yes!", attributes: styleAttributes)
@ -931,7 +940,7 @@ class ParentPanelController: NSWindowController {
let styleAttributes = [ let styleAttributes = [
NSAttributedString.Key.paragraphStyle: paragraphStyle, NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.font: NSFont(name: "Avenir-Light", size: 13)!, NSAttributedString.Key.font: NSFont(name: "Avenir-Light", size: 13)!
] ]
if leftButton.attributedTitle.string == "Not Really" { if leftButton.attributedTitle.string == "Not Really" {

2
Clocker/Panel/UI/PanelTableView.swift

@ -32,7 +32,7 @@ class PanelTableView: NSTableView {
let options: NSTrackingArea.Options = [ let options: NSTrackingArea.Options = [
.mouseMoved, .mouseMoved,
.mouseEnteredAndExited, .mouseEnteredAndExited,
.activeAlways, .activeAlways
] ]
let clipRect = enclosingScrollView?.contentView.bounds ?? .zero let clipRect = enclosingScrollView?.contentView.bounds ?? .zero

4
Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift

@ -201,7 +201,7 @@ class AppFeedbackWindowController: NSWindowController {
AppFeedbackConstants.CLOperatingSystemVersion: osVersion, AppFeedbackConstants.CLOperatingSystemVersion: osVersion,
AppFeedbackConstants.CLClockerVersion: versionInfo, AppFeedbackConstants.CLClockerVersion: versionInfo,
AppFeedbackConstants.CLAppFeedbackDateProperty: todaysDate(), AppFeedbackConstants.CLAppFeedbackDateProperty: todaysDate(),
AppFeedbackConstants.CLAppFeedbackUserPreferences: generateUserPreferences(), AppFeedbackConstants.CLAppFeedbackUserPreferences: generateUserPreferences()
] ]
} }
@ -311,7 +311,7 @@ extension AppFeedbackWindowController: NSWindowDelegate {
func bringPreferencesWindowToFront() { func bringPreferencesWindowToFront() {
let windows = NSApplication.shared.windows let windows = NSApplication.shared.windows
let prefWindow = windows.first(where: { window in let prefWindow = windows.first(where: { window in
return window.identifier == NSUserInterfaceItemIdentifier("Preferences") window.identifier == NSUserInterfaceItemIdentifier("Preferences")
}) })
if let prefW = prefWindow { if let prefW = prefWindow {
prefW.makeKeyAndOrderFront(self) prefW.makeKeyAndOrderFront(self)

2
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -60,7 +60,7 @@ class AppearanceViewController: ParentViewController {
"4 days", "4 days",
"5 days", "5 days",
"6 days", "6 days",
"7 days", "7 days"
]) ])
if #available(macOS 11.0, *) {} else { if #available(macOS 11.0, *) {} else {

3
Clocker/Preferences/Calendar/CalendarViewController.swift

@ -84,7 +84,6 @@ class CalendarViewController: ParentViewController {
verifyCalendarAccess() verifyCalendarAccess()
showSegmentedControl.selectedSegment = DataStore.shared().shouldDisplay(ViewType.upcomingEventView) ? 0 : 1 showSegmentedControl.selectedSegment = DataStore.shared().shouldDisplay(ViewType.upcomingEventView) ? 0 : 1
showNextMeetingInMenubarControl.isEnabled = DataStore.shared().shouldDisplay(.menubarCompactMode) ? false : true
} }
private func verifyCalendarAccess() { private func verifyCalendarAccess() {
@ -114,7 +113,7 @@ class CalendarViewController: ParentViewController {
let attributesDictionary: [NSAttributedString.Key: Any] = [ let attributesDictionary: [NSAttributedString.Key: Any] = [
NSAttributedString.Key.paragraphStyle: style, NSAttributedString.Key.paragraphStyle: style,
NSAttributedString.Key.font: boldFont, NSAttributedString.Key.font: boldFont,
NSAttributedString.Key.foregroundColor: Themer.shared().mainTextColor(), NSAttributedString.Key.foregroundColor: Themer.shared().mainTextColor()
] ]
let attributedString = NSAttributedString(string: title, let attributedString = NSAttributedString(string: title,
attributes: attributesDictionary) attributes: attributesDictionary)

4
Clocker/Preferences/General/PreferencesDataSource.swift

@ -161,7 +161,7 @@ extension PreferencesDataSource: NSTableViewDataSource {
if selectedTimezones.count > row { if selectedTimezones.count > row {
Logger.log(object: [ Logger.log(object: [
"Old Label": dataObject.customLabel ?? "Error", "Old Label": dataObject.customLabel ?? "Error",
"New Label": formattedValue, "New Label": formattedValue
], ],
for: "Custom Label Changed") for: "Custom Label Changed")
@ -174,7 +174,7 @@ extension PreferencesDataSource: NSTableViewDataSource {
Logger.log(object: [ Logger.log(object: [
"MethodName": "SetObjectValue", "MethodName": "SetObjectValue",
"Selected Timezone Count": selectedTimezones.count, "Selected Timezone Count": selectedTimezones.count,
"Current Row": row, "Current Row": row
], ],
for: "Error in selected row count") for: "Error in selected row count")
} }

15
Clocker/Preferences/General/PreferencesViewController.swift

@ -19,7 +19,6 @@ struct PreferencesConstants {
} }
class PreferencesViewController: ParentViewController { class PreferencesViewController: ParentViewController {
@IBOutlet private var placeholderLabel: NSTextField! @IBOutlet private var placeholderLabel: NSTextField!
@IBOutlet private var timezoneTableView: NSTableView! @IBOutlet private var timezoneTableView: NSTableView!
@IBOutlet private var availableTimezoneTableView: NSTableView! @IBOutlet private var availableTimezoneTableView: NSTableView!
@ -73,23 +72,19 @@ class PreferencesViewController: ParentViewController {
private lazy var startupManager = StartupManager() private lazy var startupManager = StartupManager()
private var dataTask: URLSessionDataTask? = .none private var dataTask: URLSessionDataTask? = .none
private lazy var notimezoneView: NoTimezoneView? = { private lazy var notimezoneView: NoTimezoneView? = NoTimezoneView(frame: tableview.frame)
NoTimezoneView(frame: tableview.frame)
}()
private var geocodingKey: String = { private var geocodingKey: String = {
guard let path = Bundle.main.path(forResource: "Keys", ofType: "plist"), guard let path = Bundle.main.path(forResource: "Keys", ofType: "plist"),
let dictionary = NSDictionary(contentsOfFile: path), let dictionary = NSDictionary(contentsOfFile: path),
let apiKey = dictionary["GeocodingKey"] as? String let apiKey = dictionary["GeocodingKey"] as? String
else { else {
assertionFailure("Unable to find the API key") // assertionFailure("Unable to find the API key")
return "" return ""
} }
return apiKey return apiKey
}() }()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
@ -253,7 +248,7 @@ class PreferencesViewController: ParentViewController {
[timezoneNameSortButton, labelSortButton, timezoneSortButton].forEach { [timezoneNameSortButton, labelSortButton, timezoneSortButton].forEach {
$0?.attributedTitle = NSAttributedString(string: $0?.title ?? CLEmptyString, attributes: [ $0?.attributedTitle = NSAttributedString(string: $0?.title ?? CLEmptyString, attributes: [
NSAttributedString.Key.foregroundColor: Themer.shared().mainTextColor(), NSAttributedString.Key.foregroundColor: Themer.shared().mainTextColor(),
NSAttributedString.Key.font: NSFont(name: "Avenir-Light", size: 13)!, NSAttributedString.Key.font: NSFont(name: "Avenir-Light", size: 13)!
]) ])
} }
@ -515,7 +510,7 @@ extension PreferencesViewController {
CLTimezoneName: formattedAddress, CLTimezoneName: formattedAddress,
CLCustomLabel: formattedAddress, CLCustomLabel: formattedAddress,
CLTimezoneID: CLEmptyString, CLTimezoneID: CLEmptyString,
CLPlaceIdentifier: $0.placeId, CLPlaceIdentifier: $0.placeId
] as [String: Any] ] as [String: Any]
finalResults.append(TimezoneData(with: totalPackage)) finalResults.append(TimezoneData(with: totalPackage))
@ -607,7 +602,7 @@ extension PreferencesViewController {
"latitude": dataObject.latitude!, "latitude": dataObject.latitude!,
"longitude": dataObject.longitude!, "longitude": dataObject.longitude!,
"nextUpdate": CLEmptyString, "nextUpdate": CLEmptyString,
CLCustomLabel: filteredAddress, CLCustomLabel: filteredAddress
] as [String: Any] ] as [String: Any]
// Mark if the timezone is same as local timezone // Mark if the timezone is same as local timezone

5
Clocker/Preferences/Menu Bar/MenubarHandler.swift → Clocker/Preferences/Menu Bar/MenubarTitleProvider.swift

@ -5,7 +5,7 @@ import CoreLoggerKit
import CoreModelKit import CoreModelKit
import EventKit import EventKit
class MenubarHandler: NSObject { class MenubarTitleProvider: NSObject {
func titleForMenubar() -> String? { func titleForMenubar() -> String? {
if let nextEvent = checkForUpcomingEvents() { if let nextEvent = checkForUpcomingEvents() {
return nextEvent return nextEvent
@ -34,7 +34,7 @@ class MenubarHandler: NSObject {
return nil return nil
} }
private func checkForUpcomingEvents() -> String? { func checkForUpcomingEvents() -> String? {
if DataStore.shared().shouldDisplay(.showMeetingInMenubar) { if DataStore.shared().shouldDisplay(.showMeetingInMenubar) {
let filteredDates = EventCenter.sharedCenter().eventsForDate let filteredDates = EventCenter.sharedCenter().eventsForDate
let autoupdatingCal = EventCenter.sharedCenter().autoupdatingCalendar let autoupdatingCal = EventCenter.sharedCenter().autoupdatingCalendar
@ -48,7 +48,6 @@ class MenubarHandler: NSObject {
if timeForEventToStart > 30 { if timeForEventToStart > 30 {
Logger.info("Our next event: \(event.event.title ?? "Error") starts in \(timeForEventToStart) mins") Logger.info("Our next event: \(event.event.title ?? "Error") starts in \(timeForEventToStart) mins")
continue continue
} }

68
Clocker/Preferences/Menu Bar/StatusContainerView.swift

@ -19,6 +19,10 @@ func bufferCalculatedWidth() -> Int {
totalWidth += 20 totalWidth += 20
} }
if DataStore.shared().shouldDisplay(.showMeetingInMenubar) {
totalWidth += 100
}
return totalWidth return totalWidth
} }
@ -55,6 +59,14 @@ func compactWidth(for timezone: TimezoneData) -> Int {
// Test with Sat 12:46 AM // Test with Sat 12:46 AM
let bufferWidth: CGFloat = 9.5 let bufferWidth: CGFloat = 9.5
protocol StatusItemViewConforming {
/// Mark that we need to refresh the text we're showing in the menubar
func statusItemViewSetNeedsDisplay()
/// Status Item Views can be used to represent different information (like time in location, or an upcoming meeting). Distinguish between different status items view through this identifier
func statusItemViewIdentifier() -> String
}
class StatusContainerView: NSView { class StatusContainerView: NSView {
private var previousX: Int = 0 private var previousX: Int = 0
@ -64,8 +76,20 @@ class StatusContainerView: NSView {
layer?.backgroundColor = NSColor.clear.cgColor layer?.backgroundColor = NSColor.clear.cgColor
} }
init(with timezones: [Data]) { init(with timezones: [Data], showUpcomingEventView: Bool) {
func addSubviews() { func addSubviews() {
if showUpcomingEventView,
let events = EventCenter.sharedCenter().eventsForDate[NSCalendar.autoupdatingCurrent.startOfDay(for: Date())],
events.isEmpty == false,
let upcomingEvent = EventCenter.sharedCenter().nextOccuring(events) {
let calculatedWidth = bestWidth(for: upcomingEvent)
let frame = NSRect(x: previousX, y: 0, width: calculatedWidth, height: 30)
let calendarItemView = UpcomingEventStatusItemView(frame: frame)
calendarItemView.dataObject = upcomingEvent
addSubview(calendarItemView)
previousX += calculatedWidth
}
timezones.forEach { timezones.forEach {
if let timezoneObject = TimezoneData.customObject(from: $0) { if let timezoneObject = TimezoneData.customObject(from: $0) {
addTimezone(timezoneObject) addTimezone(timezoneObject)
@ -76,11 +100,11 @@ class StatusContainerView: NSView {
let timeBasedAttributes = [ let timeBasedAttributes = [
NSAttributedString.Key.font: compactModeTimeFont, NSAttributedString.Key.font: compactModeTimeFont,
NSAttributedString.Key.backgroundColor: NSColor.clear, NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, NSAttributedString.Key.paragraphStyle: defaultParagraphStyle
] ]
func containerWidth(for timezones: [Data]) -> CGFloat { func containerWidth(for timezones: [Data]) -> CGFloat {
let compressedWidth = timezones.reduce(0.0) { result, timezone -> CGFloat in var compressedWidth = timezones.reduce(0.0) { result, timezone -> CGFloat in
if let timezoneObject = TimezoneData.customObject(from: timezone) { if let timezoneObject = TimezoneData.customObject(from: timezone) {
let precalculatedWidth = Double(compactWidth(for: timezoneObject)) let precalculatedWidth = Double(compactWidth(for: timezoneObject))
@ -95,6 +119,10 @@ class StatusContainerView: NSView {
return result + CGFloat(bufferCalculatedWidth()) return result + CGFloat(bufferCalculatedWidth())
} }
if showUpcomingEventView {
compressedWidth += 70
}
let calculatedWidth = min(compressedWidth, let calculatedWidth = min(compressedWidth,
CGFloat(timezones.count * bufferCalculatedWidth())) CGFloat(timezones.count * bufferCalculatedWidth()))
return calculatedWidth return calculatedWidth
@ -135,7 +163,7 @@ class StatusContainerView: NSView {
NSAttributedString.Key.font: compactModeTimeFont, NSAttributedString.Key.font: compactModeTimeFont,
NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear, NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, NSAttributedString.Key.paragraphStyle: defaultParagraphStyle
] ]
let operation = TimezoneDataOperations(with: timezone) let operation = TimezoneDataOperations(with: timezone)
@ -146,11 +174,41 @@ class StatusContainerView: NSView {
return Int(max(bestSize.width, bestTitleSize.width) + bufferWidth) return Int(max(bestSize.width, bestTitleSize.width) + bufferWidth)
} }
private func bestWidth(for eventInfo: EventInfo) -> Int {
var textColor = hasDarkAppearance ? NSColor.white : NSColor.black
if #available(OSX 11.0, *) {
textColor = NSColor.white
}
let timeBasedAttributes = [
NSAttributedString.Key.font: compactModeTimeFont,
NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle
]
let bestSize = compactModeTimeFont.size(eventInfo.metadataForMeeting(),
55, // Default for a location based status view
attributes: timeBasedAttributes)
let bestTitleSize = compactModeTimeFont.size(eventInfo.event.title,
70, // Little more buffer since meeting titles tend to be longer
attributes: timeBasedAttributes)
return Int(max(bestSize.width, bestTitleSize.width) + bufferWidth)
}
func updateTime() { func updateTime() {
if subviews.isEmpty { if subviews.isEmpty {
assertionFailure("Subviews count should > 0") assertionFailure("Subviews count should > 0")
} }
for view in subviews {
if let conformingView = view as? StatusItemViewConforming {
conformingView.statusItemViewSetNeedsDisplay()
}
}
// See if frame's width needs any adjustment // See if frame's width needs any adjustment
adjustWidthIfNeccessary() adjustWidthIfNeccessary()
} }
@ -170,8 +228,6 @@ class StatusContainerView: NSView {
y: statusItem.frame.origin.y, y: statusItem.frame.origin.y,
width: newBestWidth, width: newBestWidth,
height: statusItem.frame.size.height) height: statusItem.frame.size.height)
statusItem.updateTimeInMenubar()
} }
} }

46
Clocker/Preferences/Menu Bar/StatusItemHandler.swift

@ -22,9 +22,9 @@ class StatusItemHandler: NSObject {
return statusItem return statusItem
}() }()
private var menubarTitleHandler = MenubarHandler() private var menubarTitleHandler = MenubarTitleProvider()
private var parentView: StatusContainerView? private var statusContainerView: StatusContainerView?
private var nsCalendar = Calendar.autoupdatingCurrent private var nsCalendar = Calendar.autoupdatingCurrent
@ -42,7 +42,7 @@ class StatusItemHandler: NSObject {
switch oldValue { switch oldValue {
case .compactText: case .compactText:
statusItem.view = nil statusItem.view = nil
parentView = nil statusContainerView = nil
case .standardText: case .standardText:
statusItem.button?.title = CLEmptyString statusItem.button?.title = CLEmptyString
case .icon: case .icon:
@ -119,11 +119,11 @@ class StatusItemHandler: NSObject {
self.setupStatusItem() self.setupStatusItem()
} }
NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.willSleepNotification, object: nil, queue: OperationQueue.main) { notification in NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.willSleepNotification, object: nil, queue: OperationQueue.main) { _ in
self.menubarTimer?.invalidate() self.menubarTimer?.invalidate()
} }
NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.didWakeNotification, object: nil, queue: OperationQueue.main) { notification in NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.didWakeNotification, object: nil, queue: OperationQueue.main) { _ in
self.setupStatusItem() self.setupStatusItem()
} }
} }
@ -134,8 +134,8 @@ class StatusItemHandler: NSObject {
} }
} }
private func constructCompactView() { private func constructCompactView(with upcomingEventView: Bool = false) {
parentView = nil statusContainerView = nil
let menubarTimezones = DataStore.shared().menubarTimezones() ?? [] let menubarTimezones = DataStore.shared().menubarTimezones() ?? []
if menubarTimezones.isEmpty { if menubarTimezones.isEmpty {
@ -143,8 +143,9 @@ class StatusItemHandler: NSObject {
return return
} }
parentView = StatusContainerView(with: menubarTimezones) statusContainerView = StatusContainerView(with: menubarTimezones,
statusItem.view = parentView showUpcomingEventView: upcomingEventView)
statusItem.view = statusContainerView
statusItem.view?.window?.backgroundColor = NSColor.clear statusItem.view?.window?.backgroundColor = NSColor.clear
} }
@ -241,7 +242,20 @@ class StatusItemHandler: NSObject {
} }
func updateCompactMenubar() { func updateCompactMenubar() {
parentView?.updateTime() if let upcomingEvent = menubarTitleHandler.checkForUpcomingEvents() {
print("Need to construct upcoming event view \(upcomingEvent)")
// Iterate and see if we're showing the calendar item view
let upcomingEventView = retrieveUpcomingEventStatusView()
// If not, reconstruct Status Container View with another view
if upcomingEventView == nil {
constructCompactView(with: true)
}
} else {
let upcomingEventView = retrieveUpcomingEventStatusView()
upcomingEventView?.removeFromSuperview()
}
// This will internally call `statusItemViewSetNeedsDisplay` on all subviews ensuring all text in the menubar is up-to-date.
statusContainerView?.updateTime()
} }
func refresh() { func refresh() {
@ -347,7 +361,17 @@ class StatusItemHandler: NSObject {
menubarTimer?.invalidate() menubarTimer?.invalidate()
menubarTimer = nil menubarTimer = nil
constructCompactView() constructCompactView(with: menubarTitleHandler.checkForUpcomingEvents() != nil)
updateMenubar() updateMenubar()
} }
private func retrieveUpcomingEventStatusView() -> NSView? {
let upcomingEventView = statusContainerView?.subviews.first(where: { statusItemView in
if let upcomingEventView = statusItemView as? StatusItemViewConforming {
return upcomingEventView.statusItemViewIdentifier() == "upcoming_event_view"
}
return false
})
return upcomingEventView
}
} }

26
Clocker/Preferences/Menu Bar/StatusItemView.swift

@ -50,7 +50,7 @@ class StatusItemView: NSView {
NSAttributedString.Key.font: compactModeTimeFont, NSAttributedString.Key.font: compactModeTimeFont,
NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear, NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, NSAttributedString.Key.paragraphStyle: defaultParagraphStyle
] ]
return attributes return attributes
} }
@ -62,7 +62,7 @@ class StatusItemView: NSView {
NSAttributedString.Key.font: NSFont.boldSystemFont(ofSize: 10), NSAttributedString.Key.font: NSFont.boldSystemFont(ofSize: 10),
NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear, NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, NSAttributedString.Key.paragraphStyle: defaultParagraphStyle
] ]
return textFontAttributes return textFontAttributes
} }
@ -91,26 +91,21 @@ class StatusItemView: NSView {
locationView.leadingAnchor.constraint(equalTo: leadingAnchor), locationView.leadingAnchor.constraint(equalTo: leadingAnchor),
locationView.trailingAnchor.constraint(equalTo: trailingAnchor), locationView.trailingAnchor.constraint(equalTo: trailingAnchor),
locationView.topAnchor.constraint(equalTo: topAnchor, constant: 7), locationView.topAnchor.constraint(equalTo: topAnchor, constant: 7),
locationView.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 0.35), locationView.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 0.35)
]) ])
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
timeView.leadingAnchor.constraint(equalTo: leadingAnchor), timeView.leadingAnchor.constraint(equalTo: leadingAnchor),
timeView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0), timeView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0),
timeView.topAnchor.constraint(equalTo: locationView.bottomAnchor), timeView.topAnchor.constraint(equalTo: locationView.bottomAnchor),
timeView.bottomAnchor.constraint(equalTo: bottomAnchor), timeView.bottomAnchor.constraint(equalTo: bottomAnchor)
]) ])
} }
@available(OSX 10.14, *) @available(OSX 10.14, *)
override func viewDidChangeEffectiveAppearance() { override func viewDidChangeEffectiveAppearance() {
super.viewDidChangeEffectiveAppearance() super.viewDidChangeEffectiveAppearance()
updateTimeInMenubar() statusItemViewSetNeedsDisplay()
}
func updateTimeInMenubar() {
locationView.attributedStringValue = NSAttributedString(string: operationsObject.compactMenuTitle(), attributes: textFontAttributes)
timeView.attributedStringValue = NSAttributedString(string: operationsObject.compactMenuSubtitle(), attributes: timeAttributes)
} }
private func initialSetup() { private func initialSetup() {
@ -132,3 +127,14 @@ class StatusItemView: NSView {
mainDelegate.togglePanel(event) mainDelegate.togglePanel(event)
} }
} }
extension StatusItemView: StatusItemViewConforming {
func statusItemViewSetNeedsDisplay() {
locationView.attributedStringValue = NSAttributedString(string: operationsObject.compactMenuTitle(), attributes: textFontAttributes)
timeView.attributedStringValue = NSAttributedString(string: operationsObject.compactMenuSubtitle(), attributes: timeAttributes)
}
func statusItemViewIdentifier() -> String {
return "location_view"
}
}

28
Clocker/Preferences/Menu Bar/UpcomingEventStatusItemView.swift

@ -21,7 +21,7 @@ class UpcomingEventStatusItemView: NSView {
NSAttributedString.Key.font: compactModeTimeFont, NSAttributedString.Key.font: compactModeTimeFont,
NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear, NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, NSAttributedString.Key.paragraphStyle: defaultParagraphStyle
] ]
return attributes return attributes
} }
@ -33,7 +33,7 @@ class UpcomingEventStatusItemView: NSView {
NSAttributedString.Key.font: NSFont.boldSystemFont(ofSize: 10), NSAttributedString.Key.font: NSFont.boldSystemFont(ofSize: 10),
NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.foregroundColor: textColor,
NSAttributedString.Key.backgroundColor: NSColor.clear, NSAttributedString.Key.backgroundColor: NSColor.clear,
NSAttributedString.Key.paragraphStyle: defaultParagraphStyle, NSAttributedString.Key.paragraphStyle: defaultParagraphStyle
] ]
return textFontAttributes return textFontAttributes
} }
@ -54,26 +54,33 @@ class UpcomingEventStatusItemView: NSView {
nextEventField.leadingAnchor.constraint(equalTo: leadingAnchor), nextEventField.leadingAnchor.constraint(equalTo: leadingAnchor),
nextEventField.trailingAnchor.constraint(equalTo: trailingAnchor), nextEventField.trailingAnchor.constraint(equalTo: trailingAnchor),
nextEventField.topAnchor.constraint(equalTo: topAnchor, constant: 7), nextEventField.topAnchor.constraint(equalTo: topAnchor, constant: 7),
nextEventField.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 0.35), nextEventField.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 0.35)
]) ])
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
etaField.leadingAnchor.constraint(equalTo: leadingAnchor), etaField.leadingAnchor.constraint(equalTo: leadingAnchor),
etaField.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0), etaField.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0),
etaField.topAnchor.constraint(equalTo: nextEventField.bottomAnchor), etaField.topAnchor.constraint(equalTo: nextEventField.bottomAnchor),
etaField.bottomAnchor.constraint(equalTo: bottomAnchor), etaField.bottomAnchor.constraint(equalTo: bottomAnchor)
]) ])
} }
@available(*, unavailable)
required init?(coder _: NSCoder) { required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
private func initialSetup() { private func initialSetup() {
nextEventField.attributedStringValue = NSAttributedString(string: "Next Event", attributes: textFontAttributes) nextEventField.attributedStringValue = NSAttributedString(string: dataObject.event.title, attributes: textFontAttributes)
etaField.attributedStringValue = NSAttributedString(string: dataObject.metadataForMeeting(), attributes: timeAttributes) etaField.attributedStringValue = NSAttributedString(string: dataObject.metadataForMeeting(), attributes: timeAttributes)
} }
@available(OSX 10.14, *)
override func viewDidChangeEffectiveAppearance() {
super.viewDidChangeEffectiveAppearance()
statusItemViewSetNeedsDisplay()
}
func updateWithNextEventInfo(_ metadata: String) { func updateWithNextEventInfo(_ metadata: String) {
nextEventField.attributedStringValue = NSAttributedString(string: "Next Event", attributes: textFontAttributes) nextEventField.attributedStringValue = NSAttributedString(string: "Next Event", attributes: textFontAttributes)
etaField.attributedStringValue = NSAttributedString(string: metadata, attributes: timeAttributes) etaField.attributedStringValue = NSAttributedString(string: metadata, attributes: timeAttributes)
@ -88,3 +95,14 @@ class UpcomingEventStatusItemView: NSView {
mainDelegate.togglePanel(event) mainDelegate.togglePanel(event)
} }
} }
extension UpcomingEventStatusItemView: StatusItemViewConforming {
func statusItemViewSetNeedsDisplay() {
nextEventField.attributedStringValue = NSAttributedString(string: dataObject.event.title, attributes: textFontAttributes)
etaField.attributedStringValue = NSAttributedString(string: dataObject.metadataForMeeting(), attributes: timeAttributes)
}
func statusItemViewIdentifier() -> String {
return "upcoming_event_view"
}
}

6
Clocker/StartupKit/Package.swift

@ -6,13 +6,13 @@ import PackageDescription
let package = Package( let package = Package(
name: "StartupKit", name: "StartupKit",
platforms: [ platforms: [
.macOS(.v10_12), .macOS(.v10_12)
], ],
products: [ products: [
.library( .library(
name: "StartupKit", name: "StartupKit",
targets: ["StartupKit"] targets: ["StartupKit"]
), )
], ],
dependencies: [ dependencies: [
// Dependencies declare other packages that this package depends on. // Dependencies declare other packages that this package depends on.
@ -22,6 +22,6 @@ let package = Package(
.target( .target(
name: "StartupKit", name: "StartupKit",
dependencies: [] dependencies: []
), )
] ]
) )

Loading…
Cancel
Save