Skip to content

Commit

Permalink
added immediate check after launch
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Jun 4, 2022
1 parent d666ab2 commit eacff8d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
54 changes: 30 additions & 24 deletions XCreds/ScheduleManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,52 @@ class ScheduleManager {

var timer:Timer?
func startCredentialCheck() {

if let timer = timer, timer.isValid==true {
return
}

var rate = UserDefaults.standard.integer(forKey: PrefKeys.refreshRate.rawValue)

if rate < 5 {
rate = 5
}
timer=Timer.scheduledTimer(withTimeInterval: TimeInterval(rate), repeats: true, block: { timer in
TokenManager.shared.getNewAccessToken(completion: { isSuccessful, hadConnectionError in
self.checkToken()
})
self.checkToken()
}
func stopCredentialCheck() {
if let timer = timer, timer.isValid==true {
timer.invalidate()

if hadConnectionError==true {
NotifyManager.shared.sendMessage(message: "Could not check token.")
}
}
func checkToken() {
TokenManager.shared.getNewAccessToken(completion: { isSuccessful, hadConnectionError in

return
}
else if isSuccessful == true {
NotifyManager.shared.sendMessage(message: "Azure password unchanged")
if hadConnectionError==true {
NotifyManager.shared.sendMessage(message: "Could not check token.")

}
else {
timer.invalidate()
NotifyManager.shared.sendMessage(message: "Azure password changed or not set")
DispatchQueue.main.async {
mainMenu.webView = WebViewController()
mainMenu.webView?.window!.forceToFrontAndFocus(nil)
mainMenu.webView?.run()
return
}
else if isSuccessful == true {
NotifyManager.shared.sendMessage(message: "Azure password unchanged")

}
}
else {
if let timer = self.timer {
timer.invalidate()
}
NotifyManager.shared.sendMessage(message: "Azure password changed or not set")
DispatchQueue.main.async {
mainMenu.webView = WebViewController()
mainMenu.webView?.window!.forceToFrontAndFocus(nil)
mainMenu.webView?.run()

}
})

}
})
}
func stopCredentialCheck() {
if let timer = timer, timer.isValid==true {
timer.invalidate()

}
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
filePath = "XCreds/ScheduleManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "26"
endingLineNumber = "26"
startingLineNumber = "24"
endingLineNumber = "24"
landmarkName = "startCredentialCheck()"
landmarkType = "7">
</BreakpointContent>
Expand Down

0 comments on commit eacff8d

Please sign in to comment.