Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): 隐藏安卓语音入口

DavidShendb6fcb16237c
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsx
index b2c13b2f2b..7f780e76f1 100644
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@ -300,7 +300,11 @@ import {
resolveComposerVoiceHoldActive,
shouldArmComposerVoiceHold,
} from '@/session/composerVoiceHold';
-import { isMobileRealtimeAudioAvailable, prewarmMobileRealtimeAudio } from '@/session/mobileRealtimeAudio';
+import {
+ isMobileRealtimeAudioAvailable,
+ prewarmMobileRealtimeAudio,
+ shouldShowMobileVoiceUi,
+} from '@/session/mobileRealtimeAudio';
import {
discardPendingPrewarm,
prewarmMobileVoiceStart,
@@ -1375,6 +1379,7 @@ export default function SessionScreen() {
: [],
[atResources, canUseComposer, composerTrigger],
);
+ const voiceUiAvailable = shouldShowMobileVoiceUi(Platform.OS);
const voiceIsListening = voiceState === 'listening';
const voiceIsProcessing = voiceState === 'submitting' || voiceState === 'refining';
const voiceIsBusy = voiceIsListening || voiceIsProcessing;
@@ -1605,15 +1610,17 @@ export default function SessionScreen() {
const composerFloatingVoiceButtonStyle = composerShowInlineStop && composerShowSendButton
? styles.composerFloatingVoiceButtonWithInlineStop
: undefined;
- const composerVoicePlacement = resolveMobileComposerVoiceButtonPlacement({
- // 行尾有发送或占发送位的停止按钮时让位;附件-only(无文字)同样命中。
- hasTrailingAction: composerSendSlotIsStop || composerShowSendButton,
- });
+ const composerVoicePlacement = voiceUiAvailable
+ ? resolveMobileComposerVoiceButtonPlacement({
+ // 行尾有发送或占发送位的停止按钮时让位;附件-only(无文字)同样命中。
+ hasTrailingAction: composerSendSlotIsStop || composerShowSendButton,
+ })
+ : undefined;
const composerEffectiveContentHeight = composerInputContentHeight;
const voiceDraftShowsListeningPrompt = voiceIsListening && draft.length === 0;
// 状态行只承载错误信息;「正在听 / 转写中」不再占一行,对齐桌面版——
// 录音状态由输入框内的语音按钮形态(Mic / Square / spinner)表达。
- const voiceStatusVisible = Boolean(voiceError);
+ const voiceStatusVisible = voiceUiAvailable && Boolean(voiceError);
const nativeShellLayout = useMemo(() => buildSessionNativeShellLayout({
attachmentPickerOpen: false,
keyboardHeight: keyboardState.height,
@@ -1809,7 +1816,7 @@ export default function SessionScreen() {
/>
) : null}
<ComposerToolbarSpacer />
- {composerVoicePlacement.inline || composerVoicePlacement.floating
+ {composerVoicePlacement?.inline || composerVoicePlacement?.floating
? <ComposerToolbarVoiceSlot />
: null}
{renderComposerTrailingActions()}
@@ -7000,7 +7007,7 @@ export default function SessionScreen() {
caretHidden={voiceIsListening}
compact={compactComposer && !composerCardActive}
editable={!composerLayout.input.disabled}
- floatingVoiceButton={renderComposerVoiceButton}
+ floatingVoiceButton={voiceUiAvailable ? renderComposerVoiceButton : undefined}
floatingVoiceButtonStyle={composerFloatingVoiceButtonStyle}
cursorColor={colors.inputCaret}
inputFrameHeight={composerResize.frameHeight}
diff --git a/apps/mobile/app/sessions/new.tsx b/apps/mobile/app/sessions/new.tsx
index bbd7e82d74..1f3eff1bbc 100644
--- a/apps/mobile/app/sessions/new.tsx
+++ b/apps/mobile/app/sessions/new.tsx
@@ -194,7 +194,11 @@ import {
resolveComposerVoiceHoldActive,
shouldArmComposerVoiceHold,
} from '@/session/composerVoiceHold';
-import { isMobileRealtimeAudioAvailable, prewarmMobileRealtimeAudio } from '@/session/mobileRealtimeAudio';
+import {
+ isMobileRealtimeAudioAvailable,
+ prewarmMobileRealtimeAudio,
+ shouldShowMobileVoiceUi,
+} from '@/session/mobileRealtimeAudio';
import {
discardPendingPrewarm,
prewarmMobileVoiceStart,
@@ -734,6 +738,7 @@ export default function NewRemoteSessionScreen() {
);
const composerHasMessage = draft.firstMessage.trim().length > 0;
const composerShowCreateButton = composerHasMessage || attachments.length > 0 || pendingUploads.length > 0;
+ const voiceUiAvailable = shouldShowMobileVoiceUi(Platform.OS);
const voiceIsListening = voiceState === 'listening';
const voiceIsProcessing = voiceState === 'submitting' || voiceState === 'refining';
// 只有一台可选设备时无可切换项:禁用下拉、隐藏 ⇕(用户反馈:单选项不要出选框)。
@@ -747,11 +752,13 @@ export default function NewRemoteSessionScreen() {
const canOpenVoiceSettings = isMobileVoiceMicPermissionError(voiceError);
// 状态行只承载错误信息;「正在听 / 转写中」不再占一行,对齐桌面版——
// 录音状态由输入框内的语音按钮形态(Mic / Square / spinner)表达。
- const voiceStatusVisible = Boolean(voiceError);
- const composerVoicePlacement = resolveMobileComposerVoiceButtonPlacement({
- // 行尾有创建按钮时让位;附件-only(无文字)同样命中(composerShowCreateButton 含附件判定)。
- hasTrailingAction: composerShowCreateButton,
- });
+ const voiceStatusVisible = voiceUiAvailable && Boolean(voiceError);
+ const composerVoicePlacement = voiceUiAvailable
+ ? resolveMobileComposerVoiceButtonPlacement({
+ // 行尾有创建按钮时让位;附件-only(无文字)同样命中(composerShowCreateButton 含附件判定)。
+ hasTrailingAction: composerShowCreateButton,
+ })
+ : undefined;
const composerInputContentHeight = firstMessageInputContentHeight;
const keyboardState = useMobileKeyboardState();
const windowDimensions = useWindowDimensions();
@@ -1692,7 +1699,7 @@ export default function NewRemoteSessionScreen() {
<ChevronDown color={colors.textTertiary} size={iconSize.sm} strokeWidth={iconStroke.regular} />
</Pressable>
<ComposerToolbarSpacer />
- {composerVoicePlacement.inline || composerVoicePlacement.floating
+ {composerVoicePlacement?.inline || composerVoicePlacement?.floating
? <ComposerToolbarVoiceSlot />
: null}
{composerShowCreateButton ? renderCreateButton() : null}
@@ -2729,7 +2736,7 @@ export default function NewRemoteSessionScreen() {
trailing={composerCardActive || !composerShowCreateButton ? null : renderCreateButton()}
value={draft.firstMessage}
voicePlacement={composerVoicePlacement}
- floatingVoiceButton={renderComposerVoiceButton}
+ floatingVoiceButton={voiceUiAvailable ? renderComposerVoiceButton : undefined}
/>
</View>
</View>
diff --git a/apps/mobile/src/__tests__/mobileRealtimeAudio.test.ts b/apps/mobile/src/__tests__/mobileRealtimeAudio.test.ts
index 6eec43ed79..aa9e571d72 100644
--- a/apps/mobile/src/__tests__/mobileRealtimeAudio.test.ts
+++ b/apps/mobile/src/__tests__/mobileRealtimeAudio.test.ts
@@ -42,6 +42,13 @@ describe('mobileRealtimeAudio', () => {
.rejects.toThrow('realtime microphone PCM capture');
});
+ it('hides voice UI on Android without changing the supported iOS surface', async () => {
+ const { shouldShowMobileVoiceUi } = await import('@/session/mobileRealtimeAudio');
+
+ expect(shouldShowMobileVoiceUi('android')).toBe(false);
+ expect(shouldShowMobileVoiceUi('ios')).toBe(true);
+ });
+
it('keeps the iOS native realtime recorder wired for interruption cleanup', () => {
const source = readFileSync(
resolve(process.cwd(), 'modules/xdt-mobile-realtime-audio/ios/XdtMobileRealtimeAudioModule.swift'),
diff --git a/apps/mobile/src/__tests__/newSession.test.ts b/apps/mobile/src/__tests__/newSession.test.ts
index 4cd833af70..0f8ae5a3db 100644
--- a/apps/mobile/src/__tests__/newSession.test.ts
+++ b/apps/mobile/src/__tests__/newSession.test.ts
@@ -802,7 +802,7 @@ describe('new session composer surface', () => {
expect(newComposerSource).toContain('cardActive={composerCardActive}');
expect(newComposerSource).toContain('toolbar={renderComposerToolbar()}');
expect(newComposerSource).toContain('voicePlacement={composerVoicePlacement}');
- expect(newComposerSource).toContain('floatingVoiceButton={renderComposerVoiceButton}');
+ expect(newComposerSource).toContain('floatingVoiceButton={voiceUiAvailable ? renderComposerVoiceButton : undefined}');
expect(newComposerSource).toContain('cursorColor={colors.inputCaret}');
expect(newComposerSource).toContain('selectionColor={colors.inputCaret}');
expect(newComposerSource).toContain('inputRef={firstMessageInputRef}');
@@ -939,9 +939,11 @@ describe('new session composer surface', () => {
expect(newSource).toContain('connectionProvider: (providerId: string) => voiceContext.createAsrConnection(providerId),');
expect(newSource).toContain('voiceContext.createRefinerTarget(providerId, options),');
expect(newSource).toContain('voiceContext.warmRefiner(input),');
- expect(newSource).toContain('const composerVoicePlacement = resolveMobileComposerVoiceButtonPlacement({');
+ expect(newSource).toContain('const voiceUiAvailable = shouldShowMobileVoiceUi(Platform.OS);');
+ expect(newSource).toContain('const composerVoicePlacement = voiceUiAvailable');
expect(newSource).toContain('hasTrailingAction: composerShowCreateButton');
- expect(newSource).toContain('const voiceStatusVisible = Boolean(voiceError);');
+ expect(newSource).toContain('const voiceStatusVisible = voiceUiAvailable && Boolean(voiceError);');
+ expect(newSource).toContain('floatingVoiceButton={voiceUiAvailable ? renderComposerVoiceButton : undefined}');
expect(sessionSource).toContain('voicePlacement={composerVoicePlacement}');
expect(sharedSource).toContain('export const MOBILE_COMPOSER_INPUT_MAX_VISIBLE_LINES = 12;');
expect(sharedSource).toContain('export const MOBILE_COMPOSER_CONTROL_SIZE = 34;');
diff --git a/apps/mobile/src/__tests__/sessionComposerDesktopFirst.test.ts b/apps/mobile/src/__tests__/sessionComposerDesktopFirst.test.ts
index 249e6c4b96..8ec598481e 100644
--- a/apps/mobile/src/__tests__/sessionComposerDesktopFirst.test.ts
+++ b/apps/mobile/src/__tests__/sessionComposerDesktopFirst.test.ts
@@ -29,7 +29,7 @@ describe('mobile session composer desktop-first surface', () => {
const voiceButtonStart = source.indexOf('const renderComposerVoiceButton = (buttonStyle?: StyleProp<ViewStyle>) => (');
const voiceButtonEnd = source.indexOf('const removeRemoteFileAttachment = useCallback', voiceButtonStart);
const voiceButtonSource = source.slice(voiceButtonStart, voiceButtonEnd);
- const floatingVoiceIndex = composerInputSource.indexOf('floatingVoiceButton={renderComposerVoiceButton}');
+ const floatingVoiceIndex = composerInputSource.indexOf('floatingVoiceButton={voiceUiAvailable ? renderComposerVoiceButton : undefined}');
const floatingVoiceStyleIndex = composerInputSource.indexOf('floatingVoiceButtonStyle={composerFloatingVoiceButtonStyle}');
const sendIndex = composerInputSource.indexOf('trailing={composerCardActive ? null : renderComposerTrailingActions()}');
const composerSurfaceStart = source.indexOf('composerSurface: {');
@@ -294,11 +294,12 @@ describe('mobile session composer desktop-first surface', () => {
expect(source).toContain('const canStopComposer = canStopQueue || canStopCurrentRun;');
expect(source).toContain('canStop: canUseComposer && canStopComposer,');
expect(source).not.toContain('canStop: canUseComposer && canStopQueue,');
- expect(source).toContain('const composerVoicePlacement = resolveMobileComposerVoiceButtonPlacement({');
+ expect(source).toContain('const voiceUiAvailable = shouldShowMobileVoiceUi(Platform.OS);');
+ expect(source).toContain('const composerVoicePlacement = voiceUiAvailable');
expect(source).toContain('hasTrailingAction: composerSendSlotIsStop || composerShowSendButton');
expect(source).toContain('const renderComposerVoiceButton = (buttonStyle?: StyleProp<ViewStyle>) => (');
// 录音状态由语音按钮形态表达(Mic / Square / spinner),状态行只承载错误。
- expect(source).toContain('const voiceStatusVisible = Boolean(voiceError);');
+ expect(source).toContain('const voiceStatusVisible = voiceUiAvailable && Boolean(voiceError);');
expect(voiceButtonSource).toContain(') : voiceIsListening ? (');
expect(voiceButtonSource).toContain('<Square');
expect(voiceStatusIndex).toBeGreaterThan(-1);
@@ -396,7 +397,7 @@ describe('mobile session composer desktop-first surface', () => {
finishVoiceSource.indexOf('const latestDraft = await controller.stop();'),
);
expect(finishVoiceSource).toContain('voiceStopInFlightRef.current = false;');
- expect(composerInputSource).toContain('floatingVoiceButton={renderComposerVoiceButton}');
+ expect(composerInputSource).toContain('floatingVoiceButton={voiceUiAvailable ? renderComposerVoiceButton : undefined}');
expect(composerInputSource).toContain('floatingVoiceButtonStyle={composerFloatingVoiceButtonStyle}');
expect(composerInputSource).toContain('voicePlacement={composerVoicePlacement}');
expect(sharedSource).toContain('voicePlacement?.inline || voicePlacement?.floating');
diff --git a/apps/mobile/src/session/mobileRealtimeAudio.ts b/apps/mobile/src/session/mobileRealtimeAudio.ts
index 3cdc81a9c8..a6f001b36d 100644
--- a/apps/mobile/src/session/mobileRealtimeAudio.ts
+++ b/apps/mobile/src/session/mobileRealtimeAudio.ts
@@ -57,6 +57,18 @@ export function isMobileRealtimeAudioAvailable(): boolean {
return getNativeBinding() !== null;
}
+/**
+ * Keeps unfinished platform implementations out of the product surface. This
+ * is intentionally a UI-only gate; the native permission and runtime fallback
+ * stay unchanged so Android can be re-enabled without a native configuration
+ * migration.
+ */
+export function shouldShowMobileVoiceUi(
+ platform: string,
+): boolean {
+ return platform !== 'android';
+}
+
export async function startMobileRealtimeAudio(
options: {
onChunk: (chunk: MobileRealtimeAudioChunk) => void;