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
6 changes: 6 additions & 0 deletions ios/Phrasedeck/KeepAwake.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import SwiftUI

/// Keeps the screen on while the app is in front, so the deck is ready to tap (#159).
enum KeepAwake {
static func idleTimerDisabled(for phase: ScenePhase) -> Bool { phase == .active }
}
4 changes: 4 additions & 0 deletions ios/Phrasedeck/PhrasedeckApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct PhrasedeckApp: App {
private let stub: StubHelper?
/// Bonjour discovery (#11); nil under UI tests, so no local-network prompt.
@State private var browser: NearbyBrowser?
@Environment(\.scenePhase) private var scenePhase

init() {
#if DEBUG
Expand Down Expand Up @@ -55,6 +56,9 @@ struct PhrasedeckApp: App {
browser?.start()
}
}
.onChange(of: scenePhase, initial: true) { _, phase in
UIApplication.shared.isIdleTimerDisabled = KeepAwake.idleTimerDisabled(for: phase)
}
.modelContainer(container)
// UI tests keep the button size in their throwaway defaults.
.defaultAppStorage(stub?.defaults ?? .standard)
Expand Down
15 changes: 15 additions & 0 deletions ios/PhrasedeckTests/KeepAwakeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import SwiftUI
import Testing
@testable import Phrasedeck

/// The screen stays on only while the app is in front (#159).
struct KeepAwakeTests {
@Test(arguments: [
(ScenePhase.active, true),
(.inactive, false),
(.background, false),
])
func idleTimerIsOffOnlyWhileActive(phase: ScenePhase, disabled: Bool) {
#expect(KeepAwake.idleTimerDisabled(for: phase) == disabled)
}
}
Loading