fix(plugin): 按需显示本地分享的安装设备选择

Signed-off-by: liugaowei <liugaowei@xd.com>
This commit is contained in:
liugaowei
2026-10-28 18:40:22 +08:00
parent 554b43041f
commit 857f16b07d
3 changed files with 25 additions and 3 deletions

View File

@@ -77,8 +77,10 @@ export function LocalPluginShareView({ snapshotId, onBack, onInstalled, deviceCo
{snapshot.description ? <p className="mt-6 whitespace-pre-wrap break-words text-14 leading-relaxed text-[var(--text-secondary)]">{snapshot.description}</p> : null}
<p className="mt-6 text-13 leading-relaxed text-[var(--text-secondary)]">{t('sharing.localVersionNotice')}</p>
<section className="mt-6 space-y-3" aria-label={t('sharing.localInstallTarget')}>
<p className="text-13 text-[var(--text-secondary)]">{t('sharing.localInstallTarget')}</p>
{deviceControl ? <div className="[&>button]:max-w-full"><PluginDevicePicker {...deviceControl} disabled={busy} /></div> : null}
{deviceControl && (deviceControl.selected || deviceControl.directory.candidates.length > 0) ? <>
<p className="text-13 text-[var(--text-secondary)]">{t('sharing.localInstallTarget')}</p>
<div className="[&>button]:max-w-full"><PluginDevicePicker {...deviceControl} disabled={busy} /></div>
</> : null}
{deviceControl?.selected ? <RemoteShareInstall
key={`${dataOwnerId}:${dataOwnerGeneration}:${snapshotId}:${deviceControl.selected.deviceId}`}
snapshot={snapshot} device={deviceControl.selected} online={deviceControl.directory.online}

View File

@@ -70,6 +70,26 @@ it('does not show an old account response after a new account read finishes', as
const target = { deviceId: 'target-computer', name: 'Office Computer' };
const control = (online = true): CatalogDeviceControl => ({ selected: target, onSelect: vi.fn(),
directory: { candidates: [], target: undefined, relayOnline: online, online } });
// A signed-in recipient with only this computer must install without a redundant
// device choice. Existing tests use no control or a selected remote target;
// neither covers the real catalog control with selected=null (unit, fake IPC).
it.each([false, true])('installs on this computer without requiring a device choice (alternative=%s)', async alternative => {
const selection: CatalogDeviceControl = { selected: null, onSelect: vi.fn(), directory: {
candidates: alternative ? [{ ...target, platform: 'darwin', appVersion: '0.0.0', lastSeenAt: null,
online: true, busy: false, remoteControlEnabled: true, controlEnabled: true, isSelf: false }] : [],
target: undefined, relayOnline: true, online: true,
} };
const installed = vi.fn(); render(view(installed, selection));
await screen.findByText('v1.0.0');
expect(!!screen.queryByRole('button', { name: 'settings.ghosts.remote.device' })).toBe(alternative);
fireEvent.click(screen.getByRole('button', { name: 'sharing.localInstallButton' }));
await waitFor(() => expect(installed).toHaveBeenCalledWith(ghost));
expect(io.install).toHaveBeenCalledWith(snapshotId, snapshot);
expect(selection.onSelect).not.toHaveBeenCalled();
expect(io.invoke).not.toHaveBeenCalled();
});
function remoteHost(supported = true) {
io.invoke.mockImplementation(async (_device, channel, [request]) => {
if (String(channel).includes('manifest')) return { collections: [{ id: 'plugins', actions: [{ id: 'management:snapshot' }] }] };

View File

@@ -3626,7 +3626,7 @@ Share Server 在创建时保存已验签的分享者 `membershipId` 与身份权
公共 `kind=plugin`、`cindy://plugin/<pluginId>` 及其链接复用、版本选择和安装规则保留。
本地分享另用 `kind=local-plugin`、随机 `snapshotId` 和
`cindy://plugin-share/<snapshotId>`;只导航,拒绝 query、fragment、包 URL 和自动安装参数,
沿原冷启动与登录续接进入独立分享详情,优先于本机/远程目录分支。接收者使用原设备选择器选择安装电脑;离线或不支持的目标不可安装,不自动切回本机。不新增 Mobile 入口。
沿原冷启动与登录续接进入独立分享详情,优先于本机/远程目录分支。安装沿用当前所选电脑;仅在有其他候选电脑或已选远程电脑时显示原设备选择器,不额外要求选择。离线或不支持的目标不可安装,不自动切回本机。不新增 Mobile 入口。
两仓 `packages/plugin-protocol/src/localSharing.ts` 同步维护上传、固定快照与交付校验,
不修改已有 manifest、Release 或来源枚举。每次打开本地分享面板生成新操作;用户明确开始后,