forked from shadowfacts/Tusker
Tweak iCloud timeline sync
This commit is contained in:
parent
3cba0bce34
commit
967bff063b
|
@ -134,7 +134,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
}
|
}
|
||||||
.debounce(for: .milliseconds(500), scheduler: DispatchQueue.main)
|
.debounce(for: .milliseconds(500), scheduler: DispatchQueue.main)
|
||||||
.sink { [unowned self] _ in
|
.sink { [unowned self] _ in
|
||||||
_ = promptToSyncPositionIfNecessary()
|
_ = syncPositionIfNecessary(alwaysPrompt: true)
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
@ -225,11 +225,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if promptToSyncPositionIfNecessary() {
|
syncAndCheckPresentIfEnoughTimeElapsed()
|
||||||
// no-op
|
|
||||||
} else {
|
|
||||||
checkPresentIfEnoughTimeElapsed()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,11 +444,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
view.window?.windowScene == scene else {
|
view.window?.windowScene == scene else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if promptToSyncPositionIfNecessary() {
|
syncAndCheckPresentIfEnoughTimeElapsed()
|
||||||
// no-op
|
|
||||||
} else {
|
|
||||||
checkPresentIfEnoughTimeElapsed()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func sceneDidEnterBackground(_ notification: Foundation.Notification) {
|
@objc private func sceneDidEnterBackground(_ notification: Foundation.Notification) {
|
||||||
|
@ -465,7 +457,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
saveState()
|
saveState()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func promptToSyncPositionIfNecessary() -> Bool {
|
private func syncPositionIfNecessary(alwaysPrompt: Bool) -> Bool {
|
||||||
guard persistsState,
|
guard persistsState,
|
||||||
let timelinePosition = mastodonController.persistentContainer.getTimelinePosition(timeline: timeline) else {
|
let timelinePosition = mastodonController.persistentContainer.getTimelinePosition(timeline: timeline) else {
|
||||||
return false
|
return false
|
||||||
|
@ -491,16 +483,20 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
guard timelinePosition.centerStatusID != centerVisibleStatusID else {
|
guard timelinePosition.centerStatusID != centerVisibleStatusID else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
var config = ToastConfiguration(title: "Sync Position")
|
if !alwaysPrompt {
|
||||||
config.edge = .top
|
|
||||||
config.dismissAutomaticallyAfter = 5
|
|
||||||
config.systemImageName = "arrow.triangle.2.circlepath"
|
|
||||||
config.action = { [unowned self] toast in
|
|
||||||
toast.dismissToast(animated: true)
|
|
||||||
_ = self.restoreState()
|
_ = self.restoreState()
|
||||||
|
} else {
|
||||||
|
var config = ToastConfiguration(title: "Sync Position")
|
||||||
|
config.edge = .top
|
||||||
|
config.dismissAutomaticallyAfter = 5
|
||||||
|
config.systemImageName = "arrow.triangle.2.circlepath"
|
||||||
|
config.action = { [unowned self] toast in
|
||||||
|
toast.dismissToast(animated: true)
|
||||||
|
_ = self.restoreState()
|
||||||
|
}
|
||||||
|
showToast(configuration: config, animated: true)
|
||||||
|
UIAccessibility.post(notification: .announcement, argument: "Synced Position Updated")
|
||||||
}
|
}
|
||||||
showToast(configuration: config, animated: true)
|
|
||||||
UIAccessibility.post(notification: .announcement, argument: "Synced Position Updated")
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,14 +525,18 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func checkPresentIfEnoughTimeElapsed() {
|
private func syncAndCheckPresentIfEnoughTimeElapsed() {
|
||||||
guard let disappearedAt,
|
guard let disappearedAt,
|
||||||
-disappearedAt.timeIntervalSinceNow > 60 * 60 /* 1 hour */ else {
|
-disappearedAt.timeIntervalSinceNow > 60 * 60 /* 1 hour */ else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.disappearedAt = nil
|
self.disappearedAt = nil
|
||||||
Task {
|
if syncPositionIfNecessary(alwaysPrompt: false) {
|
||||||
await checkPresent(jumpImmediately: false)
|
// no-op
|
||||||
|
} else {
|
||||||
|
Task {
|
||||||
|
await checkPresent(jumpImmediately: false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue