Skip to content

Commit

Permalink
fixed check timer to still work if mac sleeps
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Jun 8, 2023
1 parent 85b7117 commit af491f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
17 changes: 14 additions & 3 deletions XCreds/ScheduleManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import Cocoa
class ScheduleManager {

static let shared=ScheduleManager()

var nextCheckTime = Date()
var timer:Timer?
func startCredentialCheck() {
func setNextCheckTime() {
if let timer = timer, timer.isValid==true {
return
}
Expand All @@ -24,7 +24,13 @@ class ScheduleManager {
else if rate > 168 {
rate = 168
}
timer=Timer.scheduledTimer(withTimeInterval: TimeInterval(rate*60*60), repeats: true, block: { timer in
nextCheckTime = Date(timeIntervalSinceNow: TimeInterval(rate*60*60))

}
func startCredentialCheck() {

setNextCheckTime()
timer=Timer.scheduledTimer(withTimeInterval: 60*5, repeats: true, block: { timer in //check every 5 minutes
self.checkToken()
})
self.checkToken()
Expand All @@ -44,6 +50,11 @@ class ScheduleManager {
// return
// }

if nextCheckTime>Date() {
TCSLogWithMark("Token will be checked at \(nextCheckTime)")
return
}
setNextCheckTime()
TokenManager.shared.getNewAccessToken(completion: { isSuccessful, hadConnectionError in

if hadConnectionError==true {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "B835CF57-4699-45EB-9D7D-FCB99468A05F"
uuid = "BEA98AD8-FEDB-4D48-ABFA-1483C0A7C282"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XCreds/KeychainUtil.swift"
filePath = "XCreds/ScheduleManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "61"
endingLineNumber = "61"
landmarkName = "findPassword(serviceName:accountName:)"
startingLineNumber = "54"
endingLineNumber = "54"
landmarkName = "checkToken()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
Expand Down

0 comments on commit af491f5

Please sign in to comment.