@binblink/wasmnest-plugin-sdk-mobile 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +439 -2
- package/README_en.md +415 -0
- package/bin/build.js +271 -0
- package/bin/cli.js +96 -0
- package/bin/lib.js +349 -0
- package/bin/manifest-gen.js +327 -0
- package/bin/package.js +151 -0
- package/bin/scaffold.js +299 -0
- package/dev-shell/README.md +151 -0
- package/dev-shell/index.html +27 -0
- package/dev-shell/package.json +27 -0
- package/dev-shell/pnpm-workspace.yaml +9 -0
- package/dev-shell/postcss.config.js +6 -0
- package/dev-shell/src/App.vue +90 -0
- package/dev-shell/src/apps/mock-terminal/MockTerminalSlotCard.vue +43 -0
- package/dev-shell/src/apps/mock-terminal/MockTerminalView.vue +168 -0
- package/dev-shell/src/apps/mock-terminal/index.ts +50 -0
- package/dev-shell/src/components/DevToolbar.vue +100 -0
- package/dev-shell/src/components/DialogHost.vue +119 -0
- package/dev-shell/src/components/LogPanel.vue +80 -0
- package/dev-shell/src/i18n.ts +22 -0
- package/dev-shell/src/loader.ts +239 -0
- package/dev-shell/src/locale.ts +29 -0
- package/dev-shell/src/locales/en-shell.ts +332 -0
- package/dev-shell/src/locales/index.ts +70 -0
- package/dev-shell/src/locales/shell.ts +331 -0
- package/dev-shell/src/main.ts +58 -0
- package/dev-shell/src/mock/dialog-service.ts +58 -0
- package/dev-shell/src/mock/file-transfer.ts +390 -0
- package/dev-shell/src/mock/mobile-api.ts +369 -0
- package/dev-shell/src/mock/preset-tasks.ts +186 -0
- package/dev-shell/src/mock/session.ts +121 -0
- package/dev-shell/src/mock-context.ts +374 -0
- package/dev-shell/src/registry.ts +151 -0
- package/dev-shell/src/shared-runtime.ts +44 -0
- package/dev-shell/src/shell/ShellView.vue +52 -0
- package/dev-shell/src/shell/adapters/devAppSource.ts +144 -0
- package/dev-shell/src/shell/components/PluginContextHost.vue +40 -0
- package/dev-shell/src/shell/components/ShellAppCell.vue +75 -0
- package/dev-shell/src/shell/components/ShellAppIcon.vue +111 -0
- package/dev-shell/src/shell/components/ShellAppSurface.vue +46 -0
- package/dev-shell/src/shell/components/ShellBrandTile.vue +27 -0
- package/dev-shell/src/shell/components/ShellCapsuleMenu.vue +123 -0
- package/dev-shell/src/shell/components/ShellChip.vue +49 -0
- package/dev-shell/src/shell/components/ShellGroupCard.vue +17 -0
- package/dev-shell/src/shell/components/ShellHost.vue +75 -0
- package/dev-shell/src/shell/components/ShellNotificationShade.vue +501 -0
- package/dev-shell/src/shell/components/ShellPermissionPrompt.vue +127 -0
- package/dev-shell/src/shell/components/ShellPlaceholderSurface.vue +33 -0
- package/dev-shell/src/shell/components/ShellSection.vue +27 -0
- package/dev-shell/src/shell/components/ShellSheet.vue +74 -0
- package/dev-shell/src/shell/components/ShellStatusbar.vue +84 -0
- package/dev-shell/src/shell/components/screens/PluginRoutePage.vue +98 -0
- package/dev-shell/src/shell/components/screens/ShellAppDetailScreen.vue +359 -0
- package/dev-shell/src/shell/components/screens/ShellAppRunScreen.vue +90 -0
- package/dev-shell/src/shell/components/screens/ShellAppsScreen.vue +195 -0
- package/dev-shell/src/shell/components/screens/ShellHomeScreen.vue +357 -0
- package/dev-shell/src/shell/components/screens/ShellPermissionsScreen.vue +376 -0
- package/dev-shell/src/shell/components/screens/ShellSettingsScreen.vue +240 -0
- package/dev-shell/src/shell/components/screens/ShellSwitcherScreen.vue +559 -0
- package/dev-shell/src/shell/components/ui/ConfirmDialog.vue +137 -0
- package/dev-shell/src/shell/components/ui/Toggle.vue +53 -0
- package/dev-shell/src/shell/composables/useShellApps.ts +417 -0
- package/dev-shell/src/shell/composables/useShellNavigation.ts +197 -0
- package/dev-shell/src/shell/composables/useShellNotifications.ts +115 -0
- package/dev-shell/src/shell/composables/useShellOpen.ts +44 -0
- package/dev-shell/src/shell/composables/useShellOverlays.ts +101 -0
- package/dev-shell/src/shell/composables/useShellPreferences.ts +143 -0
- package/dev-shell/src/shell/composables/useShellRecent.ts +84 -0
- package/dev-shell/src/shell/composables/useSlotCarousel.ts +238 -0
- package/dev-shell/src/shell/composables/useToast.ts +33 -0
- package/dev-shell/src/shell/index.ts +88 -0
- package/dev-shell/src/shell/logger.ts +45 -0
- package/dev-shell/src/shell/permissions.ts +145 -0
- package/dev-shell/src/shell/registry.ts +220 -0
- package/dev-shell/src/shell/slotCards.ts +47 -0
- package/dev-shell/src/shell/styles/shell.css +1155 -0
- package/dev-shell/src/shell/surfaceIntent.ts +107 -0
- package/dev-shell/src/shell/types.ts +152 -0
- package/dev-shell/src/shell/utils.ts +54 -0
- package/dev-shell/src/styles/main.css +153 -0
- package/dev-shell/src/styles/mobile.css +981 -0
- package/dev-shell/src/styles/wallpaper.css +130 -0
- package/dev-shell/src/theme.ts +71 -0
- package/dev-shell/src/vite-env.d.ts +20 -0
- package/dev-shell/tailwind.config.js +101 -0
- package/dev-shell/tsconfig.json +16 -0
- package/dev-shell/vite.config.ts +130 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +229 -0
- package/dist/types.d.ts +738 -0
- package/dist/types.js +0 -0
- package/dist/vite-plugin.d.ts +16 -0
- package/dist/vite-plugin.js +95 -0
- package/package.json +88 -3
- package/src/constants.ts +6 -0
- package/src/global-dialog.ts +168 -0
- package/src/index.ts +96 -0
- package/src/runtime.ts +44 -0
- package/src/types.ts +822 -0
- package/src/ui/AppUpdateSection.d.ts +44 -0
- package/src/ui/AppUpdateSection.vue +253 -0
- package/src/ui/PluginGlobalDialog.vue +388 -0
- package/src/ui/QuickCard.d.ts +33 -0
- package/src/ui/QuickCard.vue +167 -0
- package/src/ui/Select.d.ts +37 -0
- package/src/ui/Select.vue +307 -0
- package/src/ui/plugin-global-dialog.d.ts +11 -0
- package/src/ui/useSwipeTabs.d.ts +20 -0
- package/src/ui/useSwipeTabs.ts +53 -0
- package/src/update.ts +123 -0
- package/src/vite-plugin.ts +132 -0
- package/template/.gitignore +4 -0
- package/template/README.md +46 -0
- package/template/package.json +23 -0
- package/template/plugin.json +13 -0
- package/template/rust/Cargo.toml +19 -0
- package/template/rust/src/lib.rs +33 -0
- package/template/src/env.d.ts +24 -0
- package/template/src/index.ts +37 -0
- package/template/tsconfig.json +17 -0
- package/template/vite.config.ts +21 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Transfer 插件领域 mock(dev-shell 专用,纯通用接线)
|
|
3
|
+
*
|
|
4
|
+
* 浏览器中 Rust WASM 后端不可用,dev-shell 的 commands.execute 只执行前端注册
|
|
5
|
+
* 的 handler。本模块注册对等域与传输域的命令 handler 骨架(query-peer /
|
|
6
|
+
* dial-peer / list-remote / get-settings 等),并模拟事件推送
|
|
7
|
+
* (devices-changed / connection-changed),使插件在 dev-shell 中可完整演示
|
|
8
|
+
* 三态、握手、行内错误与活跃切换。
|
|
9
|
+
*
|
|
10
|
+
* 本模块不包含任何具体业务 mock 数据:全部演示种子由插件工程持有
|
|
11
|
+
* (入口导出 devMock,SDK PluginDevMock 协议的 peer / transfer 子域及本地
|
|
12
|
+
* 扩展字段),按 pluginId 经 getDevMock 取种子驱动命令返回值与事件;
|
|
13
|
+
* 未导出种子的插件不受影响(各子域回退空态)。
|
|
14
|
+
*/
|
|
15
|
+
import { emitDevEvent } from './session'
|
|
16
|
+
import type { PluginContext, PluginDevMock } from '../../../src/types'
|
|
17
|
+
import { pushLog } from '../registry'
|
|
18
|
+
|
|
19
|
+
/** 设备种子条目(插件 devMock 导出的本地扩展字段:mdns:found 载荷形状 + 拨号行为) */
|
|
20
|
+
interface MockDeviceSeed {
|
|
21
|
+
found: {
|
|
22
|
+
instanceName: string
|
|
23
|
+
addresses: string[]
|
|
24
|
+
port: number
|
|
25
|
+
txtRecords: { id: string; name?: string; ver?: string; cap?: string }
|
|
26
|
+
}
|
|
27
|
+
dialBehavior?: 'connected' | 'denied' | 'unreachable'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 对等域种子结构(插件 devMock.peer 的通用形状,dev-shell 只按需取字段) */
|
|
31
|
+
interface MockPeerSeed {
|
|
32
|
+
connectedNodeIds?: string[]
|
|
33
|
+
activeNodeId?: string
|
|
34
|
+
dialLatencyMs?: number
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 传输域种子结构(插件 devMock.transfer 的通用形状) */
|
|
38
|
+
interface MockTransferSeed {
|
|
39
|
+
remoteFs?: {
|
|
40
|
+
roots?: Array<{ id: string; name: string }>
|
|
41
|
+
files?: Record<string, Array<{ name: string; size: number; mtime: number; isDir: boolean }>>
|
|
42
|
+
}
|
|
43
|
+
settings?: {
|
|
44
|
+
roots?: MockSharedDir[]
|
|
45
|
+
policyMode?: string
|
|
46
|
+
askTimeoutSec?: number
|
|
47
|
+
downloadDir?: string
|
|
48
|
+
}
|
|
49
|
+
/** 任务快照种子(插件本地扩展字段;wire camelCase 形状,useTasks mapWire* 消费) */
|
|
50
|
+
tasks?: {
|
|
51
|
+
queue: Array<Record<string, unknown>>
|
|
52
|
+
receiving: Array<Record<string, unknown>>
|
|
53
|
+
history: Array<Record<string, unknown>>
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* consent 演示种子(插件 devMock 导出的本地扩展字段,与插件侧 ConsentDevSeed
|
|
59
|
+
* 形状对齐;SDK PluginDevMock 协议尚未收录,本地声明避免类型越界)
|
|
60
|
+
*/
|
|
61
|
+
interface MockConsentSeed {
|
|
62
|
+
pairedDevices: string[]
|
|
63
|
+
requests: Array<{
|
|
64
|
+
delayMs: number
|
|
65
|
+
request: {
|
|
66
|
+
requestId: string
|
|
67
|
+
nodeId: string
|
|
68
|
+
fingerprintShort?: string
|
|
69
|
+
deviceName?: string | null
|
|
70
|
+
}
|
|
71
|
+
}>
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 可信对端种子条目(插件 devMock 导出的本地扩展字段,SDK 协议未收录) */
|
|
75
|
+
interface MockTrustedSeed {
|
|
76
|
+
nodeId: string
|
|
77
|
+
displayName: string | null
|
|
78
|
+
fingerprintShort: string
|
|
79
|
+
addedAt: string
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 定时器句柄(setTimeout/setInterval 在浏览器返回 number) */
|
|
83
|
+
const timers: number[] = []
|
|
84
|
+
|
|
85
|
+
/** 共享目录条目(宿主 wire DTO 形状,含 SAF tree_uri) */
|
|
86
|
+
interface MockSharedDir {
|
|
87
|
+
id: string
|
|
88
|
+
name: string
|
|
89
|
+
tree_uri: string
|
|
90
|
+
builtin?: boolean
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 注册对等域 + 传输域命令 handler 并推送初始快照(loader 在 activate 前调用)
|
|
95
|
+
*
|
|
96
|
+
* @param context 插件 mock 上下文
|
|
97
|
+
* @param mock 插件领域种子(getDevMock(pluginId));缺省时各子域演示空态
|
|
98
|
+
* @param pluginId 插件 ID(pushLog 归属标签)
|
|
99
|
+
*/
|
|
100
|
+
export function registerFileTransferMock(
|
|
101
|
+
context: PluginContext,
|
|
102
|
+
mock: PluginDevMock | undefined,
|
|
103
|
+
pluginId: string,
|
|
104
|
+
): void {
|
|
105
|
+
const peerSeed = mock?.peer as
|
|
106
|
+
| (MockPeerSeed & { consent?: MockConsentSeed; trusted?: unknown; deviceSeeds?: MockDeviceSeed[] })
|
|
107
|
+
| undefined
|
|
108
|
+
const deviceSeeds: MockDeviceSeed[] = peerSeed?.deviceSeeds ?? []
|
|
109
|
+
/** 种子派生视图:nodeId → 种子(拨号行为/能力位判定用) */
|
|
110
|
+
const seedByNode = new Map(deviceSeeds.map((d) => [d.found.txtRecords.id, d]))
|
|
111
|
+
const connectedNodes = new Set<string>(peerSeed?.connectedNodeIds ?? [])
|
|
112
|
+
let activePeerId = peerSeed?.activeNodeId ?? ''
|
|
113
|
+
const dialLatencyMs = peerSeed?.dialLatencyMs ?? 800
|
|
114
|
+
|
|
115
|
+
// ==================== 对等域事件推送 ====================
|
|
116
|
+
|
|
117
|
+
/** 连接态增量:维护已连接集合并推 connection-changed({ nodeId, connected } 契约) */
|
|
118
|
+
function emitConnection(nodeId: string, connected: boolean): void {
|
|
119
|
+
const seed = seedByNode.get(nodeId)
|
|
120
|
+
if (connected) {
|
|
121
|
+
if (!seed || connectedNodes.has(nodeId)) return
|
|
122
|
+
connectedNodes.add(nodeId)
|
|
123
|
+
} else {
|
|
124
|
+
if (!connectedNodes.has(nodeId)) return
|
|
125
|
+
connectedNodes.delete(nodeId)
|
|
126
|
+
}
|
|
127
|
+
emitDevEvent('plugin:file-transfer:connection-changed', {
|
|
128
|
+
nodeId,
|
|
129
|
+
connected,
|
|
130
|
+
deviceName: seed?.found.txtRecords.name ?? null,
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** 发现推送:逐台延迟发 mdns-found(自建缓存版 wire;晚订阅靠延迟窗口追平) */
|
|
135
|
+
function pushDeviceDiscovery(): void {
|
|
136
|
+
deviceSeeds.forEach((seed, i) => {
|
|
137
|
+
timers.push(
|
|
138
|
+
setTimeout(() => {
|
|
139
|
+
emitDevEvent('plugin:file-transfer:mdns-found', { ...seed.found })
|
|
140
|
+
}, 400 + i * 300),
|
|
141
|
+
)
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** 连接态全量补发(dev-shell 事件总线不重放历史,晚订阅者靠它追平) */
|
|
146
|
+
function pushPeerSnapshot(): void {
|
|
147
|
+
for (const nodeId of connectedNodes) emitConnection(nodeId, true)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// ==================== 对等域命令 handler ====================
|
|
151
|
+
|
|
152
|
+
// 设备缓存自持(Phase 3 步骤 1):快照存取 + 发现事件延迟推送。
|
|
153
|
+
// get-device-snapshot 从种子派生快照(wire 形状与宿主一致):插件视图挂载
|
|
154
|
+
// 晚于激活事件时,设备仍能由「最近可见」快照恢复首屏展示(真实宿主行为同源)
|
|
155
|
+
context.commands.register('file-transfer.get-device-snapshot', () => ({
|
|
156
|
+
devices: deviceSeeds.map((d, i) => ({
|
|
157
|
+
nodeId: d.found.txtRecords.id,
|
|
158
|
+
deviceName: d.found.txtRecords.name ?? '',
|
|
159
|
+
addr: d.found.addresses[0] ?? '',
|
|
160
|
+
port: d.found.port,
|
|
161
|
+
capabilitiesHex: d.found.txtRecords.cap ?? '0',
|
|
162
|
+
instanceName: d.found.instanceName,
|
|
163
|
+
lastSeenMs: Date.now() - i * 8000,
|
|
164
|
+
})),
|
|
165
|
+
}))
|
|
166
|
+
context.commands.register('file-transfer.save-device-snapshot', () => ({ ok: true }))
|
|
167
|
+
context.commands.register('file-transfer.set-active-peer', (args: any) => {
|
|
168
|
+
const id = args?.peerId
|
|
169
|
+
if (typeof id === 'string' && (!id || seedByNode.has(id))) {
|
|
170
|
+
activePeerId = id
|
|
171
|
+
}
|
|
172
|
+
return { activePeerId }
|
|
173
|
+
})
|
|
174
|
+
// 对等拨号:入参携带显式 endpoint;按种子 dialBehavior 返回终态(错误以
|
|
175
|
+
// rejected promise 携带字样供行内文案分流);connected 时推连接态事件
|
|
176
|
+
context.commands.register('file-transfer.dial-peer', (args: any) => {
|
|
177
|
+
const nodeId: string = args?.endpoint?.nodeId ?? args?.nodeId ?? ''
|
|
178
|
+
const seed = seedByNode.get(nodeId)
|
|
179
|
+
const capable = Number.parseInt(seed?.found.txtRecords.cap ?? '0', 16) % 2 === 1
|
|
180
|
+
if (!seed || !capable || connectedNodes.has(nodeId)) {
|
|
181
|
+
return Promise.reject(new Error(`dial endpoint failed: peer unreachable (${nodeId})`))
|
|
182
|
+
}
|
|
183
|
+
const behavior = seed.dialBehavior ?? 'unreachable'
|
|
184
|
+
return new Promise((resolve, reject) => {
|
|
185
|
+
timers.push(
|
|
186
|
+
setTimeout(() => {
|
|
187
|
+
if (behavior === 'connected') {
|
|
188
|
+
emitConnection(nodeId, true)
|
|
189
|
+
resolve({ status: 'connected' })
|
|
190
|
+
} else if (behavior === 'denied') {
|
|
191
|
+
reject(new Error('dial endpoint failed: peer denied'))
|
|
192
|
+
} else {
|
|
193
|
+
reject(new Error('dial endpoint failed: peer unreachable'))
|
|
194
|
+
}
|
|
195
|
+
}, dialLatencyMs),
|
|
196
|
+
)
|
|
197
|
+
})
|
|
198
|
+
})
|
|
199
|
+
context.commands.register('file-transfer.disconnect-peer', (args: any) => {
|
|
200
|
+
const nodeId = args?.nodeId
|
|
201
|
+
if (typeof nodeId === 'string') emitConnection(nodeId, false)
|
|
202
|
+
return Promise.resolve({ existed: true })
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
// ==================== 首连确认演示(ticket 04,种子来自插件扩展字段) ====================
|
|
206
|
+
|
|
207
|
+
const consentSeed = peerSeed?.consent
|
|
208
|
+
if (consentSeed) {
|
|
209
|
+
// 配对名单种子写入插件存储(useConsent 经 storage.get('paired_devices')
|
|
210
|
+
// 读取做迁移规则匹配);异步写入不阻塞其余 mock 接线
|
|
211
|
+
void context.storage.set('paired_devices', [...consentSeed.pairedDevices])
|
|
212
|
+
|
|
213
|
+
// 应答命令 handler:记录并返回命中(真实宿主由 WASM 代理转发宿主闸门)
|
|
214
|
+
context.commands.register('file-transfer.respond-consent', (args: any) => {
|
|
215
|
+
pushLog(
|
|
216
|
+
'info',
|
|
217
|
+
pluginId,
|
|
218
|
+
`respond-consent (mock): ${args?.requestId} accepted=${args?.accepted}`,
|
|
219
|
+
)
|
|
220
|
+
return { hit: true }
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
// 延迟推送首连确认事件,覆盖自动互信与弹窗两路演示
|
|
224
|
+
for (const { delayMs, request } of consentSeed.requests) {
|
|
225
|
+
timers.push(
|
|
226
|
+
setTimeout(() => {
|
|
227
|
+
emitDevEvent('plugin:file-transfer:consent-requested', { ...request })
|
|
228
|
+
}, delayMs),
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// ==================== 可信对端演示(ticket 05,种子来自插件扩展字段) ====================
|
|
234
|
+
|
|
235
|
+
// 异形种子回退空列表;撤销从 mock 数组摘除,重进设置页可见最新列表与空态
|
|
236
|
+
const trustedPeers: MockTrustedSeed[] = Array.isArray(peerSeed?.trusted)
|
|
237
|
+
? (peerSeed!.trusted as MockTrustedSeed[]).map((p) => ({ ...p }))
|
|
238
|
+
: []
|
|
239
|
+
|
|
240
|
+
context.commands.register('file-transfer.list-trusted', () =>
|
|
241
|
+
trustedPeers.map((p) => ({ ...p })),
|
|
242
|
+
)
|
|
243
|
+
context.commands.register('file-transfer.revoke-trusted', (args: any) => {
|
|
244
|
+
const nodeId: string = args?.nodeId ?? ''
|
|
245
|
+
const idx = trustedPeers.findIndex((p) => p.nodeId === nodeId)
|
|
246
|
+
if (idx >= 0) trustedPeers.splice(idx, 1)
|
|
247
|
+
pushLog('info', pluginId, `revoke-trusted (mock): ${nodeId} existed=${idx >= 0}`)
|
|
248
|
+
return idx >= 0
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
// ==================== 远端浏览(useRemoteFs 契约,种子来自 transfer.remoteFs) ====================
|
|
252
|
+
|
|
253
|
+
const transfer = mock?.transfer as MockTransferSeed | undefined
|
|
254
|
+
const remoteRoots = transfer?.remoteFs?.roots?.map((r) => ({ ...r })) ?? []
|
|
255
|
+
const remoteFiles = transfer?.remoteFs?.files ?? {}
|
|
256
|
+
context.commands.register('file-transfer.list-remote', (args: any) => {
|
|
257
|
+
if (!args?.dirId && !args?.path) {
|
|
258
|
+
return { roots: remoteRoots.map((r) => ({ ...r })) }
|
|
259
|
+
}
|
|
260
|
+
const key = `${args?.dirId ?? ''}::${args?.path ?? ''}`
|
|
261
|
+
const entries =
|
|
262
|
+
remoteFiles[key] ?? (args?.path === '' ? [] : (remoteFiles[`${args?.dirId ?? ''}::`] ?? []))
|
|
263
|
+
return { entries: entries.map((e) => ({ ...e })) }
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
// ==================== 设置域(useSettings 契约:宿主 wire DTO 形状,种子来自 transfer.settings) ====================
|
|
267
|
+
// 形状对齐宿主 get_settings 返回值(mapWireSettings 消费 snake_case);
|
|
268
|
+
// 种子缺省回退协议缺省值(policy ask / 超时 60s / 空下载目录)
|
|
269
|
+
|
|
270
|
+
const localRoots: MockSharedDir[] =
|
|
271
|
+
transfer?.settings?.roots?.map((r) => ({ ...r })) ?? []
|
|
272
|
+
let policyMode: string = transfer?.settings?.policyMode ?? 'ask'
|
|
273
|
+
let askTimeoutSec: number = transfer?.settings?.askTimeoutSec ?? 60
|
|
274
|
+
const downloadDir: string = transfer?.settings?.downloadDir ?? ''
|
|
275
|
+
|
|
276
|
+
context.commands.register('file-transfer.get-settings', () => ({
|
|
277
|
+
roots: localRoots.map((r) => ({ ...r })),
|
|
278
|
+
policy_mode: policyMode,
|
|
279
|
+
ask_timeout_sec: askTimeoutSec,
|
|
280
|
+
download_dir: downloadDir,
|
|
281
|
+
}))
|
|
282
|
+
context.commands.register('file-transfer.set-settings', (args: any) => {
|
|
283
|
+
if (typeof args?.receivingPolicy === 'string') {
|
|
284
|
+
policyMode = args.receivingPolicy === 'accept'
|
|
285
|
+
? 'always_accept'
|
|
286
|
+
: args.receivingPolicy === 'reject'
|
|
287
|
+
? 'always_deny'
|
|
288
|
+
: 'ask'
|
|
289
|
+
}
|
|
290
|
+
if (typeof args?.approvalTimeoutSec === 'number') {
|
|
291
|
+
askTimeoutSec = Math.min(Math.max(Math.round(args.approvalTimeoutSec), 10), 600)
|
|
292
|
+
}
|
|
293
|
+
return { ok: true }
|
|
294
|
+
})
|
|
295
|
+
// 添加共享目录(Phase 3 自持版契约):模拟 SAF 目录树选择器授权成功,
|
|
296
|
+
// 返回注册表条目 { id, name, treeUri };真实取消路径由宿主选择器决定
|
|
297
|
+
let safSeq = localRoots.filter((r) => !r.builtin).length
|
|
298
|
+
context.commands.register('file-transfer.mount-local', () => {
|
|
299
|
+
safSeq += 1
|
|
300
|
+
const uri = `content://com.android.externalstorage.documents/tree/primary%3ADocuments-${safSeq}`
|
|
301
|
+
const entry: MockSharedDir = {
|
|
302
|
+
id: `root-saf-${safSeq}`,
|
|
303
|
+
name: `SDCARD${safSeq > 1 ? safSeq : ''}`,
|
|
304
|
+
tree_uri: uri,
|
|
305
|
+
}
|
|
306
|
+
if (!localRoots.some((r) => r.tree_uri === entry.tree_uri)) {
|
|
307
|
+
localRoots.push(entry)
|
|
308
|
+
}
|
|
309
|
+
return { id: entry.id, name: entry.name, treeUri: entry.tree_uri }
|
|
310
|
+
})
|
|
311
|
+
context.commands.register('file-transfer.update-roots', (args: any) => {
|
|
312
|
+
const removeId: string | undefined = typeof args?.remove === 'string' ? args.remove : undefined
|
|
313
|
+
if (!removeId) return { removed: false }
|
|
314
|
+
const target = localRoots.find((r) => r.id === removeId)
|
|
315
|
+
if (!target || target.builtin) return { removed: false }
|
|
316
|
+
const idx = localRoots.indexOf(target)
|
|
317
|
+
localRoots.splice(idx, 1)
|
|
318
|
+
return { removed: true }
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
// ==================== 传输任务快照(useTasks 契约:list-* 命令 + *-changed 事件) ====================
|
|
322
|
+
// 种子来自插件 devMock.transfer.tasks(业务数据归插件工程,此处仅命令骨架接线),
|
|
323
|
+
// 缺省回退空数组 —— 插件未导出任务种子时传输 tab 演示空态。
|
|
324
|
+
// wire 形状与宿主 PeerTransferDto 对齐(camelCase),useTasks 映射层原样消费。
|
|
325
|
+
|
|
326
|
+
const taskSeed = transfer?.tasks
|
|
327
|
+
const taskQueue = taskSeed?.queue?.map((t) => ({ ...t })) ?? []
|
|
328
|
+
const receivingSeed = taskSeed?.receiving?.map((t) => ({ ...t })) ?? []
|
|
329
|
+
const historySeed = taskSeed?.history?.map((t) => ({ ...t })) ?? []
|
|
330
|
+
|
|
331
|
+
context.commands.register('file-transfer.list-tasks', () => taskQueue.map((t) => ({ ...t })))
|
|
332
|
+
context.commands.register('file-transfer.list-batches', () => [])
|
|
333
|
+
context.commands.register('file-transfer.list-receiving', () => receivingSeed.map((t) => ({ ...t })))
|
|
334
|
+
context.commands.register('file-transfer.list-history', () => historySeed.map((t) => ({ ...t })))
|
|
335
|
+
|
|
336
|
+
// 快照整表事件补发(useTasks start() 订阅整表替换;延迟推送模拟宿主激活后首报,
|
|
337
|
+
// 与初始命令同步幂等,double-push 无害)
|
|
338
|
+
if (taskQueue.length || receivingSeed.length || historySeed.length) {
|
|
339
|
+
timers.push(
|
|
340
|
+
setTimeout(() => {
|
|
341
|
+
emitDevEvent('plugin:file-transfer:tasks-changed', taskQueue.map((t) => ({ ...t })))
|
|
342
|
+
emitDevEvent('plugin:file-transfer:receiving-changed', receivingSeed.map((t) => ({ ...t })))
|
|
343
|
+
emitDevEvent('plugin:file-transfer:history-changed', historySeed.map((t) => ({ ...t })))
|
|
344
|
+
}, 1500),
|
|
345
|
+
)
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// ==================== 初始与延迟补发 ====================
|
|
349
|
+
|
|
350
|
+
// 发现事件延迟推送(自建缓存 wire)+ 连接态补发 + WS 控制面在线
|
|
351
|
+
pushDeviceDiscovery()
|
|
352
|
+
timers.push(
|
|
353
|
+
setTimeout(() => {
|
|
354
|
+
pushPeerSnapshot()
|
|
355
|
+
emitDevEvent('device-connected', {
|
|
356
|
+
device_id: activePeerId || deviceSeeds[0]?.found.txtRecords.id || '',
|
|
357
|
+
device_name: deviceSeeds[0]?.found.txtRecords.name ?? '',
|
|
358
|
+
})
|
|
359
|
+
emitDevEvent('ws_paired', {})
|
|
360
|
+
}, 600),
|
|
361
|
+
)
|
|
362
|
+
|
|
363
|
+
// 激活事件早于插件视图挂载(dev-shell 事件总线不重放历史,晚订阅者会漏收):
|
|
364
|
+
// 在常见挂载窗口后再整表重放两次(6s / 14s),幂等合并,覆盖手动/截图两种节奏。
|
|
365
|
+
// 纯通用接线:不新增任何业务数据,只是把种子已有状态重新广播一遍。
|
|
366
|
+
function replayPulse(): void {
|
|
367
|
+
deviceSeeds.forEach((seed) => {
|
|
368
|
+
emitDevEvent('plugin:file-transfer:mdns-found', { ...seed.found })
|
|
369
|
+
})
|
|
370
|
+
for (const nodeId of connectedNodes) {
|
|
371
|
+
const seed = seedByNode.get(nodeId)
|
|
372
|
+
emitDevEvent('plugin:file-transfer:connection-changed', {
|
|
373
|
+
nodeId,
|
|
374
|
+
connected: true,
|
|
375
|
+
deviceName: seed?.found.txtRecords.name ?? null,
|
|
376
|
+
})
|
|
377
|
+
}
|
|
378
|
+
emitDevEvent('device-connected', {
|
|
379
|
+
device_id: activePeerId || deviceSeeds[0]?.found.txtRecords.id || '',
|
|
380
|
+
device_name: deviceSeeds[0]?.found.txtRecords.name ?? '',
|
|
381
|
+
})
|
|
382
|
+
emitDevEvent('ws_paired', {})
|
|
383
|
+
}
|
|
384
|
+
timers.push(setTimeout(replayPulse, 6000), setTimeout(replayPulse, 14000))
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** 清理模拟定时器(插件停用时调用;命令 handler 随 context disposables 摘除) */
|
|
388
|
+
export function disposeFileTransferMock(): void {
|
|
389
|
+
while (timers.length) clearTimeout(timers.pop())
|
|
390
|
+
}
|