-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a timer to sync when app is on foreground
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// FeedSyncTimer.swift | ||
// FeedFlow | ||
// | ||
// Created by Marco Gomiero on 23/07/24. | ||
// Copyright © 2024 FeedFlow. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import shared | ||
|
||
class FeedSyncTimer { | ||
|
||
private var timer: Timer? | ||
|
||
func scheduleTimer() { | ||
timer?.invalidate() | ||
timer = Timer.scheduledTimer(withTimeInterval: 120, repeats: true) { [weak self] _ in | ||
KotlinDependencies.shared.getLogger(tag: "FeedSyncTimer").d(messageString: "Sync scheduled") | ||
KotlinDependencies.shared.getFeedSyncRepository().enqueueBackup(forceBackup: false) | ||
} | ||
|
||
} | ||
|
||
func invalidate() { | ||
KotlinDependencies.shared.getLogger(tag: "FeedSyncTimer").d(messageString: "Sync timer invalidated") | ||
timer?.invalidate() | ||
} | ||
} |