Skip to content

Commit

Permalink
Merge pull request #1 from twocentstudios/fix-start-of-day
Browse files Browse the repository at this point in the history
Fix start of day
  • Loading branch information
twocentstudios committed Sep 2, 2023
2 parents 9000a28 + 8e5a238 commit 7639bfa
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 29 deletions.
31 changes: 28 additions & 3 deletions goalie.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
340B04AB2A6FA04C006882EB /* Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = 340B04AA2A6FA04C006882EB /* Models.swift */; };
346A757F2A5B9CCE00D12521 /* WeekView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346A757E2A5B9CCE00D12521 /* WeekView.swift */; };
34D439CC2AA2DAE500E85DD7 /* DependenciesAdditions in Frameworks */ = {isa = PBXBuildFile; productRef = 34D439CB2AA2DAE500E85DD7 /* DependenciesAdditions */; };
34DF86482A54220B00AD242B /* goalieApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34DF86472A54220B00AD242B /* goalieApp.swift */; };
34DF864A2A54220B00AD242B /* TopicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34DF86492A54220B00AD242B /* TopicView.swift */; };
34DF864C2A54220C00AD242B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 34DF864B2A54220C00AD242B /* Assets.xcassets */; };
Expand Down Expand Up @@ -72,6 +73,7 @@
34DF86792A5438EB00AD242B /* Dependencies in Frameworks */,
34DF867C2A54390800AD242B /* IdentifiedCollections in Frameworks */,
34DF86742A5438CB00AD242B /* SwiftUINavigation in Frameworks */,
34D439CC2AA2DAE500E85DD7 /* DependenciesAdditions in Frameworks */,
34DF86892A56FCA100AD242B /* SystemColors in Frameworks */,
34DF86762A5438CB00AD242B /* SwiftUINavigationCore in Frameworks */,
);
Expand All @@ -94,13 +96,21 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
34D439CA2AA2DAE500E85DD7 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
34DF863B2A54220B00AD242B = {
isa = PBXGroup;
children = (
34DF86462A54220B00AD242B /* goalie */,
34DF86582A54220C00AD242B /* goalieTests */,
34DF86622A54220C00AD242B /* goalieUITests */,
34DF86452A54220B00AD242B /* Products */,
34D439CA2AA2DAE500E85DD7 /* Frameworks */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -179,6 +189,7 @@
34DF86782A5438EB00AD242B /* Dependencies */,
34DF867B2A54390800AD242B /* IdentifiedCollections */,
34DF86882A56FCA100AD242B /* SystemColors */,
34D439CB2AA2DAE500E85DD7 /* DependenciesAdditions */,
);
productName = goalie;
productReference = 34DF86442A54220B00AD242B /* goalie.app */;
Expand Down Expand Up @@ -257,6 +268,7 @@
34DF86772A5438EB00AD242B /* XCRemoteSwiftPackageReference "swift-dependencies" */,
34DF867A2A54390800AD242B /* XCRemoteSwiftPackageReference "swift-identified-collections" */,
34DF86872A56FCA100AD242B /* XCRemoteSwiftPackageReference "swiftui-system-colors" */,
34D439C92AA2D99F00E85DD7 /* XCRemoteSwiftPackageReference "swift-dependencies-additions" */,
);
productRefGroup = 34DF86452A54220B00AD242B /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -667,28 +679,36 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
34D439C92AA2D99F00E85DD7 /* XCRemoteSwiftPackageReference "swift-dependencies-additions" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/tgrapperon/swift-dependencies-additions";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.0.0;
};
};
34DF86722A5438CB00AD242B /* XCRemoteSwiftPackageReference "swiftui-navigation" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pointfreeco/swiftui-navigation.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.8.0;
minimumVersion = 1.0.0;
};
};
34DF86772A5438EB00AD242B /* XCRemoteSwiftPackageReference "swift-dependencies" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pointfreeco/swift-dependencies.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.5.1;
minimumVersion = 1.0.0;
};
};
34DF867A2A54390800AD242B /* XCRemoteSwiftPackageReference "swift-identified-collections" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pointfreeco/swift-identified-collections.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.8.0;
minimumVersion = 1.0.0;
};
};
34DF86872A56FCA100AD242B /* XCRemoteSwiftPackageReference "swiftui-system-colors" */ = {
Expand All @@ -702,6 +722,11 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
34D439CB2AA2DAE500E85DD7 /* DependenciesAdditions */ = {
isa = XCSwiftPackageProductDependency;
package = 34D439C92AA2D99F00E85DD7 /* XCRemoteSwiftPackageReference "swift-dependencies-additions" */;
productName = DependenciesAdditions;
};
34DF86732A5438CB00AD242B /* SwiftUINavigation */ = {
isa = XCSwiftPackageProductDependency;
package = 34DF86722A5438CB00AD242B /* XCRemoteSwiftPackageReference "swiftui-navigation" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/combine-schedulers",
"state" : {
"revision" : "0625932976b3ae23949f6b816d13bd97f3b40b7c",
"version" : "0.10.0"
"revision" : "9dc9cbe4bc45c65164fa653a563d8d8db61b09bb",
"version" : "1.0.0"
}
},
{
"identity" : "swift-case-paths",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "fc45e7b2cfece9dd80b5a45e6469ffe67fe67984",
"version" : "0.14.1"
"revision" : "5da6989aae464f324eef5c5b52bdb7974725ab81",
"version" : "1.0.0"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-clocks",
"state" : {
"revision" : "f9acfa1a45f4483fe0f2c434a74e6f68f865d12d",
"version" : "0.3.0"
"revision" : "d1fd837326aa719bee979bdde1f53cd5797443eb",
"version" : "1.0.0"
}
},
{
Expand All @@ -36,40 +36,58 @@
"version" : "1.0.4"
}
},
{
"identity" : "swift-concurrency-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-concurrency-extras",
"state" : {
"revision" : "ea631ce892687f5432a833312292b80db238186a",
"version" : "1.0.0"
}
},
{
"identity" : "swift-custom-dump",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "3a35f7892e7cf6ba28a78cd46a703c0be4e0c6dc",
"version" : "0.11.0"
"revision" : "edd66cace818e1b1c6f1b3349bb1d8e00d6f8b01",
"version" : "1.0.0"
}
},
{
"identity" : "swift-dependencies",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies.git",
"state" : {
"revision" : "de1a984a71e51f6e488e98ce3652035563eb8acb",
"version" : "0.5.1"
"revision" : "4e1eb6e28afe723286d8cc60611237ffbddba7c5",
"version" : "1.0.0"
}
},
{
"identity" : "swift-dependencies-additions",
"kind" : "remoteSourceControl",
"location" : "https://github.com/tgrapperon/swift-dependencies-additions",
"state" : {
"revision" : "3223855b5ad1e049bc89330496a09ff7a69c5a48",
"version" : "1.0.0"
}
},
{
"identity" : "swift-identified-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-identified-collections.git",
"state" : {
"revision" : "d01446a78fb768adc9a78cbb6df07767c8ccfc29",
"version" : "0.8.0"
"revision" : "d1e45f3e1eee2c9193f5369fa9d70a6ddad635e8",
"version" : "1.0.0"
}
},
{
"identity" : "swiftui-navigation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swiftui-navigation.git",
"state" : {
"revision" : "2aa885e719087ee19df251c08a5980ad3e787f12",
"version" : "0.8.0"
"revision" : "f5bcdac5b6bb3f826916b14705f37a3937c2fd34",
"version" : "1.0.0"
}
},
{
Expand All @@ -86,8 +104,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "4af50b38daf0037cfbab15514a241224c3f62f98",
"version" : "0.8.5"
"revision" : "23cbf2294e350076ea4dbd7d5d047c1e76b03631",
"version" : "1.0.2"
}
}
],
Expand Down
32 changes: 22 additions & 10 deletions goalie/TopicView.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Combine
import CustomDump
import Dependencies
import DependenciesAdditions
import SwiftUI
import SwiftUINavigation
import SystemColors
Expand All @@ -10,6 +11,7 @@ final class TopicStore: ObservableObject {
@Dependency(\.uuid) var uuid
@Dependency(\.calendar) var calendar
@Dependency(\.mainRunLoop) var mainRunLoop
@Dependency(\.notificationCenter) var notificationCenter

@Published var topic: Topic {
didSet {
Expand All @@ -33,22 +35,32 @@ final class TopicStore: ObservableObject {
}

private var save: (Topic) -> Void
private var timerCancellable: Cancellable?
private var cancellables: Set<AnyCancellable> = []

init(topic: Topic, save: @escaping ((Topic) -> Void)) {
self.topic = topic
self.save = save
startOfToday = calendar.startOfDay(for: now)

let approximateOneDayInterval: TimeInterval = 60 * 60 * 24
timerCancellable = mainRunLoop.schedule(
after: .init(calendar.startOfDay(for: now.addingTimeInterval(approximateOneDayInterval))),
interval: .seconds(approximateOneDayInterval),
tolerance: .seconds(1)
) { [weak self] in
guard let self else { return }
self.startOfToday = calendar.startOfDay(for: self.now)
}
mainRunLoop
.schedule(
after: .init(calendar.startOfDay(for: now.addingTimeInterval(approximateOneDayInterval))),
interval: .seconds(approximateOneDayInterval),
tolerance: .seconds(1)
) { [weak self] in
guard let self else { return }
self.startOfToday = calendar.startOfDay(for: self.now)
}
.store(in: &cancellables)

notificationCenter.publisher(for: NSApplication.didBecomeActiveNotification)
.sink { [weak self] _ in
guard let self else { return }
self.startOfToday = calendar.startOfDay(for: self.now)
print(self.startOfToday!)
}
.store(in: &cancellables)
}

func startStopButtonTapped() {
Expand Down Expand Up @@ -226,7 +238,7 @@ struct TopicView: View {
}
.keyboardShortcut("y", modifiers: [.command])
.frame(maxWidth: .infinity, alignment: .trailing)

TimelineView(.animation(minimumInterval: 1, paused: viewData.isTimerPaused)) { timeline in
Text(viewData.timerTitle(startOfDay: store.startOfToday, now: timeline.date))
.monospacedDigit()
Expand Down

0 comments on commit 7639bfa

Please sign in to comment.