Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): keep desktop connected when audio playback fails
Dash0a23d92fed78
diff --git a/apps/mobile/src/i18n/locales/en/remoteDesktop.json b/apps/mobile/src/i18n/locales/en/remoteDesktop.jsonindex 37299c16b5..ec5b16bde6 100644--- a/apps/mobile/src/i18n/locales/en/remoteDesktop.json+++ b/apps/mobile/src/i18n/locales/en/remoteDesktop.json@@ -109,6 +109,7 @@"resolutionControlHint": "Take control to change the resolution.","videoSettingsFailed": "Live video is unavailable. Compatibility viewing does not apply frame rate, quality or sound settings. Select a setting again to retry.","settingFailed": "Could not apply the setting. Please retry.",+ "audioUnavailable": "Sound is temporarily unavailable for this connection. Your preference is saved. Turn sound off and on to retry.","pipUnavailable": "Picture in picture is unavailable. Keep Cindy open to view the desktop.","clipboardUnsupported": "This clipboard content is not supported yet. Copy a single image, text, or link. Files and app-specific formats cannot be transferred yet.","clipboardTransferring": "Transferring clipboard content…",diff --git a/apps/mobile/src/i18n/locales/ja/remoteDesktop.json b/apps/mobile/src/i18n/locales/ja/remoteDesktop.jsonindex f7df5a4d79..dae8c435ad 100644--- a/apps/mobile/src/i18n/locales/ja/remoteDesktop.json+++ b/apps/mobile/src/i18n/locales/ja/remoteDesktop.json@@ -109,6 +109,7 @@"resolutionControlHint": "解像度を変更するには操作権を取得してください。","videoSettingsFailed": "リアルタイム映像に接続できません。互換表示ではフレームレート・画質・サウンド設定は適用されません。設定を選び直して再試行できます。","settingFailed": "設定を適用できませんでした。再試行してください。",+ "audioUnavailable": "この接続では一時的に音声を利用できません。設定は保持されています。音声をオフにしてからオンにすると再試行できます。","pipUnavailable": "ピクチャインピクチャを開始できません。Cindy を開いたまま表示してください。","clipboardUnsupported": "この形式にはまだ対応していません。画像1枚、テキスト、またはリンクをコピーしてください。ファイルやアプリ独自の形式は転送できません。","clipboardTransferring": "クリップボードの内容を転送中…",diff --git a/apps/mobile/src/i18n/locales/ko/remoteDesktop.json b/apps/mobile/src/i18n/locales/ko/remoteDesktop.jsonindex 54bb4a20b9..e13fd9b3de 100644--- a/apps/mobile/src/i18n/locales/ko/remoteDesktop.json+++ b/apps/mobile/src/i18n/locales/ko/remoteDesktop.json@@ -109,6 +109,7 @@"resolutionControlHint": "해상도를 변경하려면 제어권을 가져오세요.","videoSettingsFailed": "실시간 영상에 연결하지 못했습니다. 호환 모드에서는 프레임 속도, 화질, 소리가 적용되지 않습니다. 설정을 다시 선택해 재시도하세요.","settingFailed": "설정을 적용하지 못했습니다. 다시 시도하세요.",+ "audioUnavailable": "이 연결에서는 일시적으로 소리를 사용할 수 없습니다. 설정은 유지됩니다. 소리를 껐다가 켜서 다시 시도하세요.","pipUnavailable": "화면 속 화면을 시작할 수 없습니다. Cindy를 열어 둔 상태로 시청하세요.","clipboardUnsupported": "아직 지원하지 않는 형식입니다. 이미지 한 장, 텍스트 또는 링크를 복사해 주세요. 파일과 앱 전용 형식은 아직 전송할 수 없습니다.","clipboardTransferring": "클립보드 내용을 전송하는 중…",diff --git a/apps/mobile/src/i18n/locales/zh-CN/remoteDesktop.json b/apps/mobile/src/i18n/locales/zh-CN/remoteDesktop.jsonindex 97e2af589d..0395dad4c4 100644--- a/apps/mobile/src/i18n/locales/zh-CN/remoteDesktop.json+++ b/apps/mobile/src/i18n/locales/zh-CN/remoteDesktop.json@@ -109,6 +109,7 @@"resolutionControlHint": "接管操作后可以更改分辨率。","videoSettingsFailed": "实时传输未建立,当前使用兼容画面。帧率、画质和声音暂未生效,可重新选择设置重试。","settingFailed": "设置未能应用,请重试。",+ "audioUnavailable": "本次连接暂时无声,声音偏好已保留。关闭再开启声音可重试。","pipUnavailable": "当前无法开启系统画中画,请保持 Cindy 在前台观看。","clipboardUnsupported": "这种剪贴板内容暂不支持,请单独复制一张图片、文字或链接。文件和应用专有格式暂不能传输。","clipboardTransferring": "正在传输剪贴板内容…",diff --git a/apps/mobile/src/i18n/locales/zh-TW/remoteDesktop.json b/apps/mobile/src/i18n/locales/zh-TW/remoteDesktop.jsonindex 926cd9da44..c9a0dafbd2 100644--- a/apps/mobile/src/i18n/locales/zh-TW/remoteDesktop.json+++ b/apps/mobile/src/i18n/locales/zh-TW/remoteDesktop.json@@ -109,6 +109,7 @@"resolutionControlHint": "接管操作後可以變更解析度。","videoSettingsFailed": "即時傳輸未建立,目前使用相容畫面。幀率、畫質與聲音尚未生效,可重新選擇設定重試。","settingFailed": "設定未能套用,請重試。",+ "audioUnavailable": "本次連線暫時無聲,聲音偏好已保留。關閉再開啟聲音可重試。","pipUnavailable": "目前無法開啟系統子母畫面,請保持 Cindy 在前景觀看。","clipboardUnsupported": "暫不支援這種剪貼簿內容,請單獨複製一張圖片、文字或連結。檔案及應用程式專有格式暫時無法傳輸。","clipboardTransferring": "正在傳輸剪貼簿內容…",diff --git a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsxindex 107e472a7d..9a3e4afe6d 100644--- a/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx+++ b/apps/mobile/src/remote-desktop/RemoteDesktopScreen.tsx@@ -217,6 +217,7 @@ export default function RemoteDesktopScreen() {const [videoSettings, setVideoSettings, videoPreferencesLoaded] = useVideoSettingsPreference();const videoSettingsRef = useRef(videoSettings);videoSettingsRef.current = videoSettings;+ const audioUnavailable = useRef(false);const [settingNotice, setSettingNotice] = useState<string | null>(null);const [settingBusy, setSettingBusy] = useState(false);const settingInFlight = useRef(false);@@ -463,8 +464,17 @@ export default function RemoteDesktopScreen() {};setLease({ ...next });setStatus("compatibility");+ audioUnavailable.current = false;+ setSettingNotice(null);if (result.systemAudio && videoSettingsRef.current.audio) {- await remotePresentation?.playback(true);+ try {+ await remotePresentation?.playback(true);+ } catch {+ if (current !== generation.current) return;+ audioUnavailable.current = true;+ setSettingNotice(t("remoteDesktop.audioUnavailable"));+ await remotePresentation?.playback(false).catch(() => {});+ }if (current !== generation.current) return;}send({@@ -474,7 +484,7 @@ export default function RemoteDesktopScreen() {width: display.width,height: display.height,fillHeight: landscape,- audio: result.systemAudio && videoSettingsRef.current.audio,+ audio: result.systemAudio && videoSettingsRef.current.audio && !audioUnavailable.current,});send({ type: "mode", mode });// Entering remote desktop is the user's intent to control. The existing@@ -498,7 +508,7 @@ export default function RemoteDesktopScreen() {if (current === generation.current) connecting.current = false;}},- [deviceId, fail, landscape, mode, request, send, stop, videoPreferencesLoaded],+ [deviceId, fail, landscape, mode, request, send, stop, t, videoPreferencesLoaded],);const connectRef = useRef(connect);connectRef.current = connect;@@ -764,7 +774,7 @@ export default function RemoteDesktopScreen() {settings: {...videoSettingsRef.current,audio: Boolean(- caps.systemAudio && videoSettingsRef.current.audio,+ caps.systemAudio && videoSettingsRef.current.audio && !audioUnavailable.current,),},}@@ -1028,6 +1038,7 @@ export default function RemoteDesktopScreen() {if (settings.audio) await remotePresentation?.playback(true);else if (!presentation.current) await remotePresentation?.playback(false);if (active.current !== current) return;+ audioUnavailable.current = false;videoSettingsRef.current = settings;setVideoSettings(settings);streaming.current = false;@@ -1376,7 +1387,7 @@ export default function RemoteDesktopScreen() {settings: videoSettings,busy: settingBusy,modesSupported: Boolean(caps?.displayModes),- notice: settingNotice,+ notice: audioUnavailable.current ? t("remoteDesktop.audioUnavailable") : settingNotice,onChange: (settings) => {void changeVideoSettings(settings);},diff --git a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsxindex 0cfc61e2c9..e4742166a1 100644--- a/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx+++ b/apps/mobile/src/remote-desktop/__tests__/screen.test.tsx@@ -17,6 +17,8 @@ const fixture = vi.hoisted(() => ({message: null as null | ((e: unknown) => void),size: { width: 390, height: 844 },canControl: true,+ systemAudio: false,+ playback: vi.fn(async (_enabled: boolean) => {}),trickleIce: false,focused: true,status: "online",@@ -91,6 +93,9 @@ vi.mock("react-i18next", () => {return { useTranslation: () => ({ t }) };});vi.mock("expo-modules-core", () => ({ requireOptionalNativeModule: () => null }));+vi.mock("../../../modules/cindy-remote-presentation/src", () => ({+ remotePresentation: { playback: fixture.playback, rotate: vi.fn(async () => {}) },+}));vi.mock("expo-clipboard", () => ({ getStringAsync: vi.fn(), setStringAsync: vi.fn() }));vi.mock("@expo/ui/community/segmented-control", () => ({ default: () => null }));vi.mock("@/platform/chrome/NativePullDownMenu", () => ({@@ -186,6 +191,8 @@ beforeEach(() => {fixture.trickleIce = false;fixture.size = { width: 390, height: 844 };fixture.openLink.mockResolvedValue({});+ fixture.systemAudio = false;+ fixture.playback.mockReset().mockResolvedValue(undefined);fixture.invoke.mockImplementation(async (_device, _channel, [request]) => {switch (request.op) {case "capabilities":@@ -195,6 +202,8 @@ beforeEach(() => {automaticReconnect: true,enabled: true,canControl: fixture.canControl,+ systemAudio: fixture.systemAudio,+ videoSettings: fixture.systemAudio,platform: "darwin",displays: [display],};@@ -231,6 +240,29 @@ const connect = async () => {};describe("remote desktop controls", () => {+ it("keeps video and control when playback fails without changing the sound preference", async () => {+ fixture.systemAudio = true;+ fixture.playback.mockImplementation(async (enabled) => { if (enabled) throw new Error("audio interrupted"); });+ await connect();+ expect(sent().find((m) => m.type === "init")).toMatchObject({ audio: false });+ expect(sent().find((m) => m.type === "control")).toMatchObject({ enabled: true });+ expect(fixture.playback).toHaveBeenLastCalledWith(false);+ await act(async () => {+ fixture.message!({ nativeEvent: { data: JSON.stringify({ type: "offer", epoch: "lease", sdp: "sdp", attemptId: "attempt" }) } });+ });+ expect(requests().find((r) => r.op === "offer").settings.audio).toBe(false);+ await act(async () => vi.advanceTimersByTimeAsync(15_000));+ expect(requests().filter((r) => r.op === "start")).toHaveLength(1);+ act(() => button("operations").click());+ expect(host.textContent).toContain("remoteDesktop.audioUnavailable");+ expect(button("sound").getAttribute("aria-selected")).toBe("true");+ fixture.playback.mockResolvedValue(undefined);+ await act(async () => button("sound").click());+ act(() => fixture.message!({ nativeEvent: { data: JSON.stringify({ type: "streaming", epoch: "lease" }) } }));+ await act(async () => button("sound").click());+ expect(sent().filter((m) => m.type === "videoSettings").at(-1)).toMatchObject({ audio: true });+ expect(host.textContent).not.toContain("remoteDesktop.audioUnavailable");+ });it("overlays landscape keyboards and includes their measured occlusion", async () => {fixture.size = { width: 844, height: 390 };act(() => root.render(<RemoteDesktopScreen />));