Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extension EuriaWebViewDelegate: WKScriptMessageHandler {
enum MessageTopic: String, CaseIterable {
case logout
case unauthenticated
case keepDeviceAwake
}

func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
Expand All @@ -38,6 +39,9 @@ extension EuriaWebViewDelegate: WKScriptMessageHandler {
logoutUser()
case .unauthenticated:
userTokenIsInvalid()
case .keepDeviceAwake:
guard let shouldKeepDeviceAwake = message.body as? Bool else { return }
keepDeviceAwake(shouldKeepDeviceAwake)
}
}

Expand All @@ -64,4 +68,8 @@ extension EuriaWebViewDelegate: WKScriptMessageHandler {
}
logoutUser()
}

private func keepDeviceAwake(_ shouldKeepDeviceAwake: Bool) {
UIApplication.shared.isIdleTimerDisabled = shouldKeepDeviceAwake
}
}
6 changes: 5 additions & 1 deletion EuriaFeatures/MainView/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public struct MainView: View {
}
universalLinksState.linkedWebView = nil
}
.sceneLifecycle(willEnterForeground: willEnterForeground)
.sceneLifecycle(willEnterForeground: willEnterForeground, didEnterBackground: didEnterBackground)
}

private func willEnterForeground() {
Expand All @@ -119,6 +119,10 @@ public struct MainView: View {
}
}

private func didEnterBackground() {
UIApplication.shared.isIdleTimerDisabled = false
}

private func registerForNotificationIfNeeded() async {
let options: UNAuthorizationOptions = [.alert, .sound]
guard let granted = try? await UNUserNotificationCenter.current().requestAuthorization(options: options),
Expand Down
Loading