ios: CallKit enhancements (#2010)

* ios: CallKit enhancements

* better checks
This commit is contained in:
Stanislav Dmitrenko
2023-03-15 18:32:27 +03:00
committed by GitHub
parent 0404b020e6
commit 840df89ca6
5 changed files with 46 additions and 13 deletions

View File

@@ -22,6 +22,7 @@ struct SimpleXApp: App {
@State private var doAuthenticate = false
@State private var canConnectCall = false
@State private var enteredBackground: TimeInterval? = nil
@State private var lastSuccessfulUnlock: TimeInterval? = nil
init() {
hs_init(0, nil)
@@ -35,7 +36,7 @@ struct SimpleXApp: App {
var body: some Scene {
return WindowGroup {
ContentView(doAuthenticate: $doAuthenticate, userAuthorized: $userAuthorized, canConnectCall: $canConnectCall)
ContentView(doAuthenticate: $doAuthenticate, userAuthorized: $userAuthorized, canConnectCall: $canConnectCall, lastSuccessfulUnlock: $lastSuccessfulUnlock)
.environmentObject(chatModel)
.onOpenURL { url in
logger.debug("ContentView.onOpenURL: \(url)")
@@ -65,6 +66,7 @@ struct SimpleXApp: App {
NtfManager.shared.setNtfBadgeCount(chatModel.totalUnreadCountForAllUsers())
case .active:
CallController.shared.onEndCall = nil
chatModel.sceneWasActiveAtLeastOnce = true
let appState = appStateGroupDefault.get()
startChatAndActivate()
if appState.inactive && chatModel.chatRunning == true {
@@ -74,7 +76,7 @@ struct SimpleXApp: App {
}
}
doAuthenticate = authenticationExpired()
canConnectCall = !(doAuthenticate && prefPerformLA)
canConnectCall = !(doAuthenticate && prefPerformLA) || unlockedRecently()
default:
break
}
@@ -114,6 +116,15 @@ struct SimpleXApp: App {
}
}
private func unlockedRecently() -> Bool {
if let lastSuccessfulUnlock = lastSuccessfulUnlock {
return ProcessInfo.processInfo.systemUptime - lastSuccessfulUnlock < 2
} else {
return false
}
}
private func updateChats() {
do {
let chats = try apiGetChats()