Skip to content

Commit 2bf78d8

Browse files
fix(mobile): keep screen awake during dictation
1 parent 0150c6a commit 2bf78d8

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

‎apps/mobile/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"expo-image": "~57.0.3",
9494
"expo-image-manipulator": "~57.0.17",
9595
"expo-image-picker": "~57.0.14",
96+
"expo-keep-awake": "~57.0.2",
9697
"expo-linking": "~57.0.8",
9798
"expo-network": "~57.0.1",
9899
"expo-notifications": "~57.0.15",

‎apps/mobile/src/features/voice-input/useVoiceInputController.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import {
77
type RecordingStatus,
88
} from "expo-audio";
99
import { File } from "expo-file-system";
10+
import { activateKeepAwakeAsync, deactivateKeepAwake } from "expo-keep-awake";
1011
import { useFocusEffect } from "@react-navigation/native";
11-
import { useCallback, useEffect, useRef, useState } from "react";
12+
import { useCallback, useEffect, useId, useRef, useState } from "react";
1213
import { AppState } from "react-native";
1314
import { useSharedValue } from "react-native-reanimated";
1415

@@ -71,6 +72,8 @@ export function useVoiceInputController(input: {
7172
}) {
7273
const [state, setState] = useState<VoiceInputState>(INITIAL_STATE);
7374
const [elapsedSeconds, setElapsedSeconds] = useState(0);
75+
const keepAwakeId = useId();
76+
const keepAwakeSessionRef = useRef(0);
7477
const elapsedSecondsRef = useRef(0);
7578
const audioLevelsRef = useRef(Array<number>(VOICE_WAVEFORM_SAMPLE_COUNT).fill(0));
7679
const audioLevels = useSharedValue(audioLevelsRef.current);
@@ -156,6 +159,18 @@ export function useVoiceInputController(input: {
156159

157160
useEffect(() => () => controller.dispose(), [controller]);
158161

162+
useEffect(() => {
163+
if (state.phase !== "recording") return;
164+
165+
const tag = `voice-input:${keepAwakeId}:${++keepAwakeSessionRef.current}`;
166+
const activation = activateKeepAwakeAsync(tag);
167+
void activation.catch(() => {});
168+
return () => {
169+
// Release after activation settles, even if the recording ends immediately.
170+
void activation.then(() => deactivateKeepAwake(tag)).catch(() => {});
171+
};
172+
}, [keepAwakeId, state.phase]);
173+
159174
useEffect(() => {
160175
if (state.phase !== "preparing" && state.phase !== "recording") return;
161176

‎docs/user/composer.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ recording started, ready for you to review and edit before sending.
131131
The first use may download Apple's speech model and needs a network connection.
132132
Later transcription works offline for that language. Recordings can be up to five
133133
minutes long. Canceling, leaving the screen, or an audio interruption discards the
134-
recording and preserves your existing draft.
134+
recording and preserves your existing draft. While recording, the screen stays
135+
awake; it can sleep normally once recording stops.
135136

136137
Transcription runs on your device. T3 Code deletes the temporary audio after
137138
transcription or cancellation; only the message text is sent when you submit.

‎pnpm-lock.yaml‎

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)