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(desktop): add Android connection guidance (#1065)

Kmnyf1625dbf7817
diff --git a/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx b/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx
index 59261827a3..8b98ae71b8 100644
--- a/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx
+++ b/apps/desktop/src/renderer/components/settings/ComputerUseSection.tsx
@@ -43,7 +43,12 @@ import {
} from '@/components/ui/dropdown-menu';
import { createLogger } from '@/lib/logger';
import { BrowserBackendSubsection } from './BrowserBackendSubsection';
-import { androidDeviceLabel, androidStatusFallback, describeAndroidDeviceStatus } from './androidStatusPresentation';
+import {
+ androidDeviceLabel,
+ androidStatusFallback,
+ describeAndroidDeviceStatus,
+ getAndroidConnectionGuideKind,
+} from './androidStatusPresentation';
import {
getComputerPermissionSwitchChecked,
isComputerPermissionPreflightInconclusive,
@@ -1135,6 +1140,7 @@ export function ComputerUseSection({
&& !androidDevices.some((device) => device.device_serial === configuredDefaultAndroidDevice),
);
const androidDeviceStatusText = describeAndroidDeviceStatus(androidStatus, t);
+ const androidConnectionGuideKind = getAndroidConnectionGuideKind(androidStatus);
const androidAdbSource = androidStatus?.adb_path_source ?? androidStatus?.adb_preparation?.source ?? null;
const androidAdbSourceText = androidPreparePending
? t('settings.computerUse.android.adb.preparing')
@@ -1635,6 +1641,41 @@ export function ComputerUseSection({
</button>
</div>
</div>
+ {androidConnectionGuideKind ? (
+ <div className="border-t border-[var(--settings-theme-card-border)] px-4 py-3">
+ <div className="rounded-xl bg-[var(--settings-input-bg)] px-3 py-3">
+ <p className="text-12 font-medium leading-[1.5] text-[var(--settings-section-title)]">
+ {t(
+ `settings.computerUse.android.connectionGuide.${androidConnectionGuideKind}.title`,
+ )}
+ </p>
+ {androidConnectionGuideKind === 'connect' ? (
+ <>
+ <p className="mt-1.5 text-12 leading-[1.5] text-[var(--settings-section-desc)]">
+ {t(
+ 'settings.computerUse.android.connectionGuide.connect.adbNote',
+ )}
+ </p>
+ <ol className="mt-2 list-decimal space-y-1 pl-4 text-12 leading-[1.5] text-[var(--settings-section-desc)]">
+ {[1, 2, 3, 4].map((step) => (
+ <li key={step}>
+ {t(
+ `settings.computerUse.android.connectionGuide.connect.step${step}`,
+ )}
+ </li>
+ ))}
+ </ol>
+ </>
+ ) : (
+ <p className="mt-1.5 text-12 leading-[1.5] text-[var(--settings-section-desc)]">
+ {t(
+ `settings.computerUse.android.connectionGuide.${androidConnectionGuideKind}.body`,
+ )}
+ </p>
+ )}
+ </div>
+ </div>
+ ) : null}
<div className="flex flex-wrap items-center justify-between gap-3 border-t border-[var(--settings-theme-card-border)] px-4 py-[14px]">
<div className="flex min-w-0 flex-col gap-1">
<p className="text-12 font-medium leading-[1.5] text-[var(--settings-section-title)]">
diff --git a/apps/desktop/src/renderer/components/settings/__tests__/androidStatusPresentation.test.ts b/apps/desktop/src/renderer/components/settings/__tests__/androidStatusPresentation.test.ts
index 48346fd428..d76ac516b4 100644
--- a/apps/desktop/src/renderer/components/settings/__tests__/androidStatusPresentation.test.ts
+++ b/apps/desktop/src/renderer/components/settings/__tests__/androidStatusPresentation.test.ts
@@ -5,6 +5,7 @@ import {
androidStatusFallback,
describeAndroidDeviceStatus,
describeAndroidStatus,
+ getAndroidConnectionGuideKind,
} from '../androidStatusPresentation';
const t = ((key: string, options?: Record<string, unknown>) =>
@@ -115,4 +116,91 @@ describe('android status presentation', () => {
'settings.computerUse.android.status.defaultUnavailable:{"device":"missing"}',
);
});
+
+ it.each([
+ ['NO_DEVICE', 'connect'],
+ ['DEVICE_UNAUTHORIZED', 'unauthorized'],
+ ['DEVICE_OFFLINE', 'offline'],
+ ] as const)('maps %s to its actionable connection guide', (issue, guide) => {
+ expect(
+ getAndroidConnectionGuideKind({
+ adb_available: true,
+ adb_path: '/sdk/platform-tools/adb',
+ version: 'Android Debug Bridge version 1.0.41',
+ devices: [],
+ default_device_serial: null,
+ issue,
+ }),
+ ).toBe(guide);
+ });
+
+ it('does not show a reconnect guide when a ready device is available', () => {
+ expect(
+ getAndroidConnectionGuideKind({
+ adb_available: true,
+ adb_path: '/sdk/platform-tools/adb',
+ version: 'Android Debug Bridge version 1.0.41',
+ devices: [{ device_serial: 'ready-1', state: 'device' }],
+ default_device_serial: 'missing',
+ configured_default_device_serial: 'missing',
+ issue: 'NO_DEVICE',
+ }),
+ ).toBeNull();
+ });
+
+ it.each([
+ ['unauthorized', 'unauthorized'],
+ ['offline', 'offline'],
+ ] as const)(
+ 'prefers a listed %s device when a stale configured default reports NO_DEVICE',
+ (state, guide) => {
+ expect(
+ getAndroidConnectionGuideKind({
+ adb_available: true,
+ adb_path: '/sdk/platform-tools/adb',
+ version: 'Android Debug Bridge version 1.0.41',
+ devices: [{ device_serial: 'connected-1', state }],
+ default_device_serial: 'missing',
+ configured_default_device_serial: 'missing',
+ issue: 'NO_DEVICE',
+ }),
+ ).toBe(guide);
+ },
+ );
+
+ it.each([
+ ['unauthorized', 'unauthorized'],
+ ['offline', 'offline'],
+ ] as const)(
+ 'keeps the configured default %s guide when another device is ready',
+ (state, guide) => {
+ expect(
+ getAndroidConnectionGuideKind({
+ adb_available: true,
+ adb_path: '/sdk/platform-tools/adb',
+ version: 'Android Debug Bridge version 1.0.41',
+ devices: [
+ { device_serial: 'selected-1', state },
+ { device_serial: 'ready-1', state: 'device' },
+ ],
+ default_device_serial: 'selected-1',
+ configured_default_device_serial: 'selected-1',
+ issue: state === 'unauthorized' ? 'DEVICE_UNAUTHORIZED' : 'DEVICE_OFFLINE',
+ }),
+ ).toBe(guide);
+ },
+ );
+
+ it('does not show a connection guide while ADB is unavailable', () => {
+ expect(
+ getAndroidConnectionGuideKind({
+ adb_available: false,
+ adb_path: null,
+ version: null,
+ devices: [],
+ default_device_serial: null,
+ issue: 'ADB_NOT_FOUND',
+ }),
+ ).toBeNull();
+ });
});
diff --git a/apps/desktop/src/renderer/components/settings/androidStatusPresentation.ts b/apps/desktop/src/renderer/components/settings/androidStatusPresentation.ts
index e7b033ec89..8fc90bda96 100644
--- a/apps/desktop/src/renderer/components/settings/androidStatusPresentation.ts
+++ b/apps/desktop/src/renderer/components/settings/androidStatusPresentation.ts
@@ -8,6 +8,8 @@
import type { TFunction } from 'i18next';
import { extractIpcError } from '@/utils/ipcError';
+export type AndroidConnectionGuideKind = 'connect' | 'unauthorized' | 'offline';
+
export function androidStatusFallback(err: unknown): AndroidStatusSummary {
const ipcError = extractIpcError(err);
return {
@@ -87,6 +89,37 @@ export function describeAndroidStatus(status: AndroidStatusSummary, t: TFunction
});
}
+/**
+ * Return the actionable connection guide for a device state.
+ *
+ * When a configured default is present, its concrete unauthorized/offline
+ * state takes priority even if another device is ready. A stale configured
+ * default can also force the aggregate issue to NO_DEVICE, so when no device is
+ * ready we inspect the listed device states before falling back to that issue.
+ */
+export function getAndroidConnectionGuideKind(
+ status: AndroidStatusSummary | null,
+): AndroidConnectionGuideKind | null {
+ if (!status?.adb_available) return null;
+
+ const configuredDefault = status.configured_default_device_serial?.trim();
+ const configuredDevice = configuredDefault
+ ? status.devices.find((device) => device.device_serial === configuredDefault)
+ : undefined;
+ if (configuredDevice?.state === 'unauthorized') return 'unauthorized';
+ if (configuredDevice?.state === 'offline') return 'offline';
+
+ const hasReadyDevice = status.devices.some((device) => device.state === 'device');
+ if (hasReadyDevice) return null;
+
+ if (status.devices.some((device) => device.state === 'unauthorized')) return 'unauthorized';
+ if (status.devices.some((device) => device.state === 'offline')) return 'offline';
+ if (status.issue === 'DEVICE_UNAUTHORIZED') return 'unauthorized';
+ if (status.issue === 'DEVICE_OFFLINE') return 'offline';
+ if (status.issue === 'NO_DEVICE' || !status.issue) return 'connect';
+ return null;
+}
+
export function describeAndroidDeviceStatus(
status: AndroidStatusSummary | null,
t: TFunction,
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 2c734386f7..92f99e22bd 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -1962,6 +1962,24 @@
"failed": "ADB status check failed: {{message}}",
"unknownIssue": "ADB issue: {{issue}}"
},
+ "connectionGuide": {
+ "connect": {
+ "title": "How to connect an Android phone",
+ "adbNote": "Cindy prepares ADB automatically; you do not need to install the Android SDK. Custom ADB path is for advanced users.",
+ "step1": "Connect the phone to the computer with a USB cable that supports data transfer.",
+ "step2": "On the phone, open Settings → About phone and tap the build number repeatedly to enable Developer options.",
+ "step3": "Open Developer options and turn on USB debugging.",
+ "step4": "Keep the phone unlocked, return to Cindy, and click Recheck."
+ },
+ "unauthorized": {
+ "title": "Allow USB debugging",
+ "body": "On the phone, choose Allow in the USB debugging permission dialog. We recommend checking Always allow from this computer, then return to Cindy and click Recheck."
+ },
+ "offline": {
+ "title": "The device is offline",
+ "body": "Reconnect the USB cable, keep the phone unlocked, then return to Cindy and click Recheck."
+ }
+ },
"device": {
"title": "Device",
"ariaLabel": "Select default Android device",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 91400cf638..1d054a730f 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -1961,6 +1961,24 @@
"failed": "ADB 状態確認に失敗しました: {{message}}",
"unknownIssue": "ADB の問題: {{issue}}"
},
+ "connectionGuide": {
+ "connect": {
+ "title": "Android スマートフォンを接続する方法",
+ "adbNote": "Cindy が ADB を自動で準備するため、Android SDK のインストールは不要です。「カスタム ADB パス」は上級者向けです。",
+ "step1": "データ転送に対応した USB ケーブルでスマートフォンとパソコンを接続します。",
+ "step2": "スマートフォンの「設定 → デバイス情報」でビルド番号を連続してタップし、開発者向けオプションを有効にします。",
+ "step3": "「開発者向けオプション」で「USB デバッグ」をオンにします。",
+ "step4": "スマートフォンのロックを解除したまま Cindy に戻り、「再確認」をクリックします。"
+ },
+ "unauthorized": {
+ "title": "USB デバッグを許可してください",
+ "body": "スマートフォンに表示された USB デバッグの許可ダイアログで「許可」を選び、可能なら「このパソコンを常に許可」にチェックを入れてから、Cindy で「再確認」をクリックします。"
+ },
+ "offline": {
+ "title": "デバイスが offline です",
+ "body": "USB ケーブルをいったん抜き差しし、スマートフォンのロックを解除したまま、Cindy に戻って「再確認」をクリックします。"
+ }
+ },
"device": {
"title": "デバイス",
"ariaLabel": "デフォルトの Android デバイスを選択",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 47f3ac1180..834190bb07 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -1961,6 +1961,24 @@
"failed": "ADB 상태 확인 실패: {{message}}",
"unknownIssue": "ADB 문제: {{issue}}"
},
+ "connectionGuide": {
+ "connect": {
+ "title": "Android 휴대폰 연결 방법",
+ "adbNote": "Cindy가 ADB를 자동으로 준비하므로 Android SDK를 설치할 필요가 없습니다. 사용자 지정 ADB 경로는 고급 설정입니다.",
+ "step1": "데이터 전송을 지원하는 USB 케이블로 휴대폰을 컴퓨터에 연결합니다.",
+ "step2": "휴대폰에서 설정 → 휴대전화 정보로 이동한 다음 빌드 번호를 여러 번 눌러 개발자 옵션을 활성화합니다.",
+ "step3": "개발자 옵션에서 USB 디버깅을 켭니다.",
+ "step4": "휴대폰 잠금을 해제한 상태로 Cindy로 돌아와 다시 확인을 누릅니다."
+ },
+ "unauthorized": {
+ "title": "USB 디버깅을 허용하세요",
+ "body": "휴대폰에 표시된 USB 디버깅 권한 대화상자에서 허용을 선택하세요. 가능하면 이 컴퓨터에서 항상 허용을 선택한 후 Cindy로 돌아와 다시 확인을 누르세요."
+ },
+ "offline": {
+ "title": "기기가 offline 상태입니다",
+ "body": "USB 케이블을 뺐다가 다시 연결하고 휴대폰 잠금을 해제한 상태로 Cindy로 돌아와 다시 확인을 누르세요."
+ }
+ },
"device": {
"title": "기기",
"ariaLabel": "기본 Android 기기 선택",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index f972035724..99951446dd 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -1961,6 +1961,24 @@
"failed": "ADB 状态检查失败:{{message}}",
"unknownIssue": "ADB 状态异常:{{issue}}"
},
+ "connectionGuide": {
+ "connect": {
+ "title": "如何连接 Android 手机",
+ "adbNote": "Cindy 会自动准备 ADB,无需安装 Android SDK;自定义 ADB 路径仅供高级设置使用。",
+ "step1": "使用支持数据传输的 USB 数据线连接手机和电脑。",
+ "step2": "在手机「设置 → 关于手机」中连续点击版本号,开启开发者选项。",
+ "step3": "在「开发者选项」中开启「USB 调试」。",
+ "step4": "保持手机解锁,回到 Cindy 点击「重新检查」。"
+ },
+ "unauthorized": {
+ "title": "请允许 USB 调试",
+ "body": "请在手机弹出的「允许 USB 调试」窗口中点击「允许」,建议勾选「始终允许使用这台电脑」,然后回到 Cindy 点击「重新检查」。"
+ },
+ "offline": {
+ "title": "设备处于 offline 状态",
+ "body": "请重新插拔 USB 数据线,保持手机解锁,然后回到 Cindy 点击「重新检查」。"
+ }
+ },
"device": {
"title": "设备",
"ariaLabel": "选择默认 Android 设备",