dsh-miniwin 0.0.0-stage → 0.3.0

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.
Files changed (49) hide show
  1. package/LICENSE +28 -0
  2. package/README.en.md +83 -0
  3. package/README.md +304 -2
  4. package/cordis.patch.yml +10 -0
  5. package/lib/client.js +532 -0
  6. package/lib/discover.js +244 -0
  7. package/lib/index.js +2290 -0
  8. package/lib/qr.js +313 -0
  9. package/package.json +57 -6
  10. package/runtime/adb-control.js +470 -0
  11. package/runtime/apk/miniwin.apk +0 -0
  12. package/runtime/assets/icon.ico +0 -0
  13. package/runtime/assets/icon.png +0 -0
  14. package/runtime/assets/tray-16.png +0 -0
  15. package/runtime/assets/tray-32.png +0 -0
  16. package/runtime/au.js +131 -0
  17. package/runtime/audio-bridge.js +267 -0
  18. package/runtime/audio-healer.js +369 -0
  19. package/runtime/audio-router.js +175 -0
  20. package/runtime/avcc.js +186 -0
  21. package/runtime/device.js +307 -0
  22. package/runtime/main.js +3309 -0
  23. package/runtime/mkv-reader.js +326 -0
  24. package/runtime/package.json +5 -0
  25. package/runtime/preload.js +122 -0
  26. package/runtime/scrcpy-capture.js +623 -0
  27. package/runtime/streamer.js +192 -0
  28. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/AdbWinApi.dll +0 -0
  29. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/AdbWinUsbApi.dll +0 -0
  30. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/LICENSE.txt +204 -0
  31. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/SDL3.dll +0 -0
  32. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/adb.exe +0 -0
  33. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/avcodec-63.dll +0 -0
  34. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/avformat-63.dll +0 -0
  35. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/avutil-61.dll +0 -0
  36. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/disconnected.png +0 -0
  37. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/libusb-1.0.dll +0 -0
  38. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/open_a_terminal_here.bat +1 -0
  39. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/scrcpy-noconsole.vbs +7 -0
  40. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/scrcpy-server +0 -0
  41. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/scrcpy.exe +0 -0
  42. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/scrcpy.png +0 -0
  43. package/runtime/tools/scrcpy/scrcpy-win64-v5.0.1/swresample-7.dll +0 -0
  44. package/runtime/ui.html +3166 -0
  45. package/runtime/usb-hotplug.js +194 -0
  46. package/runtime/wifi-adb-keeper.js +395 -0
  47. package/runtime/wifi-discovery.js +213 -0
  48. package/runtime/wifi-receiver.js +733 -0
  49. package/screenshots.json +5 -0
package/lib/client.js ADDED
@@ -0,0 +1,532 @@
1
+ /**
2
+ * dsh-miniwin — 浏览器半侧
3
+ * ---------------------------------------------------------------------------
4
+ * 侧边栏底部一个「投屏」按钮,点开是配对面板:
5
+ * 1. 大二维码(PC 侧出码,手机扫码)
6
+ * 2. 扫码方式说明(相机优先,微信兜底)
7
+ * 3. 一键自动连接(不需要填任何东西)
8
+ * 4. 连上后起桌面透明迷你窗
9
+ *
10
+ * 数据走 Host 半侧 HTTP 路由 /dsh-miniwin/*。
11
+ * 注册 id 必须等于 loader entry 名(dsh-miniwin)。
12
+ */
13
+ window.__ModuleLoader__.load({
14
+ id: 'dsh-miniwin',
15
+ factory: (require) => {
16
+ var module = { exports: {} }
17
+ var exports = module.exports
18
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
19
+
20
+ var react = require('react')
21
+ var h = react.createElement
22
+
23
+ var API = '/dsh-miniwin'
24
+
25
+ /* ══════════════════════════════════════════════════════════════════
26
+ 设计系统
27
+ ══════════════════════════════════════════════════════════════════ */
28
+ var CSS = [
29
+ /* ---- 容器 ---- */
30
+ '.__mw_root{display:flex;flex-direction:column;gap:16px;font-size:13px;',
31
+ ' color:var(--dsw-alias-label-primary);letter-spacing:.005em}',
32
+ '.__mw_root *{box-sizing:border-box}',
33
+
34
+ /* ---- 状态灯(卡片里那一个)---- */
35
+ '.__mw_dot{width:9px;height:9px;border-radius:50%;background:#4a5060;flex:0 0 auto;',
36
+ ' position:relative;transition:background .25s}',
37
+ '.__mw_dot::after{content:"";position:absolute;inset:-4px;border-radius:50%;',
38
+ ' background:currentColor;opacity:0;transition:opacity .25s}',
39
+ '.__mw_dot.live{background:#3ddc84;color:#3ddc84;box-shadow:0 0 10px rgba(61,220,132,.6)}',
40
+ '.__mw_dot.live::after{opacity:.14}',
41
+ '.__mw_dot.err{background:#ff5d55;color:#ff5d55;box-shadow:0 0 10px rgba(255,93,85,.55)}',
42
+ '.__mw_dot.err::after{opacity:.12}',
43
+ '.__mw_dot.wait{background:#f0b429;color:#f0b429;box-shadow:0 0 10px rgba(240,180,41,.5);',
44
+ ' animation:__mw_pulse 1.4s ease-in-out infinite}',
45
+ '.__mw_dot.wait::after{opacity:.14}',
46
+ '@keyframes __mw_pulse{0%,100%{opacity:1}50%{opacity:.4}}',
47
+
48
+ /* ---- 副标题 ---- */
49
+ '.__mw_sub{font-size:12.5px;line-height:1.65;color:var(--dsw-alias-label-tertiary)}',
50
+ '.__mw_sub b{color:var(--dsw-alias-label-primary);font-weight:600}',
51
+
52
+ /* ---- 卡片 ---- */
53
+ '.__mw_card{border:1px solid var(--dsw-alias-border-l2);border-radius:14px;',
54
+ ' padding:16px;display:flex;flex-direction:column;gap:13px;',
55
+ ' background:var(--dsw-alias-bg-layer-2)}',
56
+ '.__mw_cardT{font-size:11px;font-weight:700;letter-spacing:.09em;text-transform:uppercase;',
57
+ ' color:var(--dsw-alias-label-tertiary)}',
58
+
59
+ /* ---- 提示条 ---- */
60
+ '.__mw_hint{display:flex;gap:10px;align-items:flex-start;padding:12px 13px;',
61
+ ' border-radius:11px;font-size:12.5px;line-height:1.7;',
62
+ ' background:rgba(74,144,248,.08);border:1px solid rgba(74,144,248,.2);',
63
+ ' color:var(--dsw-alias-label-secondary,#bbc3d4)}',
64
+ '.__mw_hint.warn{background:rgba(240,180,41,.09);border-color:rgba(240,180,41,.26)}',
65
+ '.__mw_hint b{color:var(--dsw-alias-label-primary);font-weight:650}',
66
+ '.__mw_hintIcon{width:17px;height:17px;flex:0 0 auto;margin-top:2px;stroke:#7ab0ff;',
67
+ ' fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}',
68
+ '.__mw_hint.warn .__mw_hintIcon{stroke:#e0b458}',
69
+
70
+ /* ---- 步骤 ---- */
71
+ '.__mw_steps{margin:0;padding:0;list-style:none;display:flex;flex-direction:column;gap:10px}',
72
+ '.__mw_steps li{display:flex;gap:11px;align-items:flex-start;font-size:12.5px;',
73
+ ' line-height:1.65;color:var(--dsw-alias-label-secondary,#a8b0c4)}',
74
+ '.__mw_steps li b{color:var(--dsw-alias-label-primary);font-weight:650}',
75
+ '.__mw_steps .n{width:20px;height:20px;border-radius:6px;flex:0 0 auto;',
76
+ ' display:grid;place-items:center;font-size:11px;font-weight:700;',
77
+ ' background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-tertiary);',
78
+ ' margin-top:1px;font-variant-numeric:tabular-nums}',
79
+ '.__mw_steps li.k .n{background:rgba(74,144,248,.2);color:#9cc4ff;',
80
+ ' box-shadow:inset 0 0 0 1px rgba(74,144,248,.22)}',
81
+
82
+ /* ---- WiFi 模式的精简块 ---- */
83
+ // 状态行:绿点=投屏中,灰点=等待。放在码上面,扫之前扫之后都能一眼看到
84
+ '.__mw_state{display:flex;align-items:center;gap:8px;font-size:12.5px;',
85
+ ' color:var(--dsw-alias-label-secondary,#9aa3b8);margin-bottom:12px}',
86
+ '.__mw_state .d{width:7px;height:7px;border-radius:50%;flex:0 0 auto;',
87
+ ' background:var(--dsw-alias-label-tertiary,#697);opacity:.5}',
88
+ '.__mw_state.on{color:#48c98a}',
89
+ '.__mw_state.on .d{background:#26c97a;opacity:1;box-shadow:0 0 8px rgba(38,201,122,.8)}',
90
+ '.__mw_warn{font-size:12px;line-height:1.6;color:#e08a8a;margin-top:10px}',
91
+ '.__mw_row{display:flex;gap:8px;margin-top:14px}',
92
+ '.__mw_hintLine{font-size:11.5px;line-height:1.6;margin-top:12px;',
93
+ ' color:var(--dsw-alias-label-tertiary)}',
94
+
95
+ /* ---- 按钮 ---- */
96
+ '.__mw_btns{display:flex;gap:9px}',
97
+ '.__mw_btn{flex:1 1 0;border:1px solid var(--dsw-alias-border-l2);',
98
+ ' background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);',
99
+ ' border-radius:10px;padding:10px 14px;font:inherit;font-size:13px;font-weight:560;',
100
+ ' cursor:pointer;white-space:nowrap;transition:background .14s,border-color .14s}',
101
+ '.__mw_btn:hover:not(:disabled){border-color:var(--dsw-alias-state-business-primary);',
102
+ ' background:var(--dsw-alias-bg-layer-2)}',
103
+ '.__mw_btn:active:not(:disabled){transform:translateY(1px)}',
104
+ '.__mw_btn:disabled{opacity:.42;cursor:default}',
105
+ '.__mw_btnPri{flex:1 1 0;border-color:transparent;',
106
+ ' background:linear-gradient(180deg,#4a90f8,#2f6fd8);color:#fff;',
107
+ ' box-shadow:0 3px 12px rgba(47,111,216,.32)}',
108
+ '.__mw_btnPri:hover:not(:disabled){background:linear-gradient(180deg,#5b9bf9,#3a7ae2);',
109
+ ' border-color:transparent}',
110
+ '.__mw_btnIcon{width:15px;height:15px;vertical-align:-2px;margin-right:6px;',
111
+ ' stroke:currentColor;fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}',
112
+
113
+ /* ---- 消息 ---- */
114
+ '.__mw_msg{font-size:12.5px;line-height:1.65;padding:11px 13px;border-radius:10px;',
115
+ ' display:none;align-items:flex-start;gap:9px}',
116
+ '.__mw_msg.ok{display:flex;background:rgba(61,220,132,.1);',
117
+ ' border:1px solid rgba(61,220,132,.28);color:#6fdba0}',
118
+ '.__mw_msg.err{display:flex;background:rgba(255,92,84,.1);',
119
+ ' border:1px solid rgba(255,92,84,.28);color:#ff9b94}',
120
+ '.__mw_msg.wait{display:flex;background:rgba(240,180,41,.1);',
121
+ ' border:1px solid rgba(240,180,41,.28);color:#e8c46c}',
122
+ '.__mw_msgIcon{width:15px;height:15px;flex:0 0 auto;margin-top:2px;',
123
+ ' fill:none;stroke-width:2.2;stroke-linecap:round;stroke-linejoin:round}',
124
+ '.__mw_msg.ok .__mw_msgIcon{stroke:#5fd394}',
125
+ '.__mw_msg.err .__mw_msgIcon{stroke:#ff8d85}',
126
+ '.__mw_msg.wait .__mw_msgIcon{stroke:#e0b458}',
127
+
128
+ /* ---- 日志 ---- */
129
+ '.__mw_logBox{margin-top:2px;border-top:1px solid var(--dsw-alias-border-l2);padding-top:11px}',
130
+ '.__mw_logToggle{display:flex;align-items:center;gap:7px;font-size:11.5px;',
131
+ ' color:var(--dsw-alias-label-tertiary);cursor:pointer;user-select:none}',
132
+ '.__mw_logToggle:hover{color:var(--dsw-alias-label-primary)}',
133
+ '.__mw_logToggle .arw{font-size:9px;transition:transform .16s;display:inline-block}',
134
+ '.__mw_logToggle .arw.open{transform:rotate(90deg)}',
135
+ '.__mw_logs{max-height:168px;overflow-y:auto;margin-top:9px;',
136
+ ' font-family:ui-monospace,Consolas,"Cascadia Mono",monospace;font-size:11px;',
137
+ ' line-height:1.7;color:var(--dsw-alias-label-tertiary);',
138
+ ' background:var(--dsw-alias-bg-layer-3);border-radius:9px;padding:10px 12px}',
139
+ '.__mw_logs::-webkit-scrollbar{width:6px}',
140
+ '.__mw_logs::-webkit-scrollbar-thumb{background:rgba(255,255,255,.12);border-radius:3px}',
141
+ '.__mw_logl{display:flex;gap:9px;margin-bottom:3px;word-break:break-word}',
142
+ '.__mw_logl .lv{flex:0 0 auto;width:34px;font-weight:600}',
143
+ '.__mw_logl .lv.ok{color:#5fd394}',
144
+ '.__mw_logl .lv.err{color:#ff8d85}',
145
+ '.__mw_logl .lv.warn{color:#e0b458}',
146
+ '.__mw_logl .lv.info{color:#7ab0ff}'
147
+ ].join('')
148
+
149
+ var tagId = 'dsh-miniwin/main.css'
150
+ if (typeof document !== 'undefined' && !document.querySelector('style[data-plugin-css="' + tagId + '"]')) {
151
+ var tag = document.createElement('style')
152
+ tag.dataset.plugin = 'dsh-miniwin'
153
+ tag.dataset.pluginCss = tagId
154
+ tag.textContent = CSS
155
+ document.head.appendChild(tag)
156
+ }
157
+
158
+ /* ══════════════════════════════════════════════════════════════════
159
+ 图标
160
+ ══════════════════════════════════════════════════════════════════ */
161
+ function Icon(props) {
162
+ return h('svg', {
163
+ className: props.className,
164
+ viewBox: '0 0 24 24',
165
+ fill: 'none',
166
+ stroke: 'currentColor',
167
+ strokeWidth: 2,
168
+ strokeLinecap: 'round',
169
+ strokeLinejoin: 'round'
170
+ }, props.children)
171
+ }
172
+
173
+ function IcoScan() {
174
+ return h(Icon, { className: '__mw_hintIcon' },
175
+ h('path', { d: 'M3 8V5a2 2 0 012-2h3M16 3h3a2 2 0 012 2v3M21 16v3a2 2 0 01-2 2h-3M8 21H5a2 2 0 01-2-2v-3' }),
176
+ h('path', { d: 'M3 12h18' })
177
+ )
178
+ }
179
+
180
+ function IcoPhone() {
181
+ return h(Icon, { className: '__mw_btnIcon' },
182
+ h('rect', { x: 6, y: 2, width: 12, height: 20, rx: 2.5 }),
183
+ h('path', { d: 'M11 18.5h2' })
184
+ )
185
+ }
186
+
187
+ function IcoCheck() {
188
+ return h(Icon, { className: '__mw_msgIcon' }, h('path', { d: 'M4 12.5l5 5L20 6.5' }))
189
+ }
190
+
191
+ function IcoWarn() {
192
+ return h(Icon, { className: '__mw_msgIcon' },
193
+ h('path', { d: 'M12 8.5v5M12 17h.01' }),
194
+ h('circle', { cx: 12, cy: 12, r: 9 })
195
+ )
196
+ }
197
+
198
+ function IcoWait() {
199
+ return h(Icon, { className: '__mw_msgIcon' }, h('path', { d: 'M12 7v5l3.5 2' }),
200
+ h('circle', { cx: 12, cy: 12, r: 9 }))
201
+ }
202
+
203
+ /* ══════════════════════════════════════════════════════════════════
204
+ 小组件
205
+ ══════════════════════════════════════════════════════════════════ */
206
+ function Msg(props) {
207
+ if (!props.kind) return null
208
+ var ico = props.kind === 'ok' ? IcoCheck() : props.kind === 'err' ? IcoWarn() : IcoWait()
209
+ return h('div', { className: '__mw_msg ' + props.kind }, ico, h('span', null, props.children))
210
+ }
211
+
212
+ function Hint(props) {
213
+ return h('div', { className: '__mw_hint' + (props.warn ? ' warn' : '') },
214
+ props.warn ? h(Icon, { className: '__mw_hintIcon' },
215
+ h('path', { d: 'M12 8.5v5M12 17h.01' }), h('circle', { cx: 12, cy: 12, r: 9 })) : IcoScan(),
216
+ h('span', null, props.children))
217
+ }
218
+
219
+ /* ══════════════════════════════════════════════════════════════════
220
+ 主面板
221
+ ══════════════════════════════════════════════════════════════════ */
222
+ function Panel() {
223
+ var st = react.useState({
224
+ phase: 'idle', device: null, message: '', logs: [],
225
+ busy: false, kind: '', showLogs: false
226
+ })
227
+ var s = st[0], setS = st[1]
228
+ var upd = function (patch) { setS(function (prev) { return Object.assign({}, prev, patch) }) }
229
+
230
+ /* ---- 轮询状态 ---- */
231
+ /**
232
+ * 面板状态以前只同步 phase / device / logs,于是迷你窗推上来的
233
+ * 「在等手机上线(最长 3 分钟)」和「连接失败原因」都不会出现在
234
+ * 侧边栏里 —— 用户点了按钮之后面板一动不动,看起来像卡死。
235
+ *
236
+ * 现在把 message / error 一起带过来,并在 phase=error 时把
237
+ * 红灯和信息条点亮。
238
+ */
239
+ react.useEffect(function () {
240
+ var timer = setInterval(function () {
241
+ fetch(API + '/state', { headers: { Accept: 'application/json' } })
242
+ .then(function (r) { return r.json() })
243
+ .then(function (j) {
244
+ if (!j || !j.ok) return
245
+ var ss = j.state || {}
246
+ setS(function (prev) {
247
+ var next = Object.assign({}, prev, {
248
+ phase: ss.phase || prev.phase,
249
+ device: ss.device || prev.device,
250
+ logs: ss.logs || prev.logs
251
+ })
252
+ if (ss.phase === 'error') {
253
+ next.kind = 'err'
254
+ next.message = ss.error || ss.message || '连接失败'
255
+ } else if (ss.message) {
256
+ // 等待/进行中的提示,只在没有本地消息时覆盖,避免打断按钮自己的提示
257
+ if (!prev.busy) { next.kind = prev.kind === 'err' ? 'wait' : prev.kind }
258
+ if (prev.phase !== ss.phase) next.message = ss.message
259
+ }
260
+ return next
261
+ })
262
+ })
263
+ .catch(function () {})
264
+ }, 1500)
265
+ return function () { clearInterval(timer) }
266
+ }, [])
267
+
268
+ /* ---- 一键自动连接 ---- */
269
+ function doAuto () {
270
+ upd({ busy: true, kind: 'wait', message: '正在查找手机…' })
271
+ fetch(API + '/auto', { headers: { Accept: 'application/json' } })
272
+ .then(function (r) { return r.json() })
273
+ .then(function (j) {
274
+ if (j && j.ok) {
275
+ return upd({
276
+ busy: false,
277
+ kind: 'ok',
278
+ message: '找到手机:' + (j.model || j.serial),
279
+ device: { serial: j.serial, model: j.model, transport: j.via }
280
+ })
281
+ }
282
+ if (j && j.needPair) {
283
+ return upd({
284
+ busy: false,
285
+ kind: 'wait',
286
+ message: '手机已开无线调试,只差配对码。用手机扫码,在页面上填那 6 位数字即可。'
287
+ })
288
+ }
289
+ upd({
290
+ busy: false,
291
+ kind: 'err',
292
+ message: (j && j.message) || '没找到手机。请在手机上打开「开发人员选项 → 无线调试」。'
293
+ })
294
+ })
295
+ .catch(function (e) { upd({ busy: false, kind: 'err', message: '请求失败: ' + e.message }) })
296
+ }
297
+
298
+ /**
299
+ * 启动迷你窗。
300
+ *
301
+ * 2.0 架构下不需要预先知道 serial —— 迷你窗启动后会自己
302
+ * 扫描局域网找手机(wifi-adb-keeper),连上自动出画面。
303
+ * 旧版强制「先点自动连接找到手机」,那是 adb 插线流程的产物。
304
+ *
305
+ * 传 serial 仍然支持(可选优化):已连过时传过去能省一次扫描。
306
+ */
307
+ function doLaunch () {
308
+ var serial = s.device && s.device.serial
309
+ upd({ busy: true, kind: 'wait', message: '正在启动桌面迷你窗…' })
310
+ fetch(API + '/launch', {
311
+ method: 'POST',
312
+ headers: { 'Content-Type': 'application/json' },
313
+ body: JSON.stringify(serial ? { serial: serial } : {})
314
+ })
315
+ .then(function (r) { return r.json() })
316
+ .then(function (j) {
317
+ if (!j.ok) return upd({ busy: false, kind: 'err', message: j.error || '启动失败' })
318
+ upd({ busy: false, kind: 'ok', message: '迷你窗已打开,正在连接手机…' })
319
+ })
320
+ .catch(function (e) { upd({ busy: false, kind: 'err', message: '请求失败: ' + e.message }) })
321
+ }
322
+
323
+ /* ---- 状态灯:只保留卡片里那一个 ---- */
324
+ var logs = Array.isArray(s.logs) ? s.logs.slice(-40) : []
325
+ var connected = !!(s.device && s.device.serial)
326
+
327
+ /**
328
+ * 设备在线探测 —— 面板状态要反映「手机在不在」,不是「迷你窗开没开」。
329
+ *
330
+ * 之前只有 s.device,而它只在迷你窗启动后才被推上来。于是手机明明
331
+ * 连着、adb 里能看到,面板照样写「未连接」,用户以为坏了。
332
+ *
333
+ * 每 10 秒问一次 /devices(本地 adb,几十毫秒),有设备就记下型号。
334
+ * 频率刻意放低:这只是个状态提示,不值得频繁 fork adb。
335
+ */
336
+ var devRef = react.useState(null)
337
+ var devInfo = devRef[0], setDevInfo = devRef[1]
338
+
339
+ react.useEffect(function () {
340
+ var alive = true
341
+ function probe () {
342
+ fetch(API + '/devices', { headers: { Accept: 'application/json' } })
343
+ .then(function (r) { return r.json() })
344
+ .then(function (j) {
345
+ if (!alive || !j) return
346
+ var list = Array.isArray(j.devices) ? j.devices : []
347
+ var hit = list.filter(function (d) { return d.state === 'device' })[0] || null
348
+ setDevInfo(hit)
349
+ })
350
+ .catch(function () {})
351
+ }
352
+ probe()
353
+ var t = setInterval(probe, 10000)
354
+ return function () { alive = false; clearInterval(t) }
355
+ }, [])
356
+
357
+ /**
358
+ * 状态判定 —— 只认 adb。
359
+ *
360
+ * 原来的写法是 `streaming = wifi ? wifi.connected : connected`。
361
+ * `wifi` 由 refreshWifiQr 在面板打开时填充,只要接收端**在跑**
362
+ * 它就会变成非空对象(哪怕手机根本没连过来)。于是 adb 明明连着、
363
+ * 画面明明在投,面板顶部却写「未连接」。
364
+ *
365
+ * 现在:判定只来自 adb(s.device.serial 优先,其次设备探测)。
366
+ */
367
+ var streaming = connected
368
+ var phoneOnline = !!(devInfo && devInfo.serial)
369
+ var phoneName = (connected && s.device && s.device.model) ||
370
+ (devInfo && devInfo.model) || ''
371
+
372
+ return h('div', { className: '__mw_root' },
373
+
374
+ /**
375
+ * ══════════ 面板主体 ══════════
376
+ *
377
+ * 手机端什么都不用装、不用扫码、不用配对。
378
+ * 采集由 PC 侧的 scrcpy.exe 通过 adb 完成,手机只是个被采集的屏幕。
379
+ *
380
+ * 「手机投屏」这个标题在弹窗顶栏已经有了,这里不再重复一遍;
381
+ * 状态也只说一次(卡片里那个带灯的),不要「未连接」写两遍。
382
+ */
383
+ h('div', { className: '__mw_card' },
384
+
385
+ /* 状态行 —— 全面板唯一一处状态文字 */
386
+ h('div', { className: '__mw_state' + (streaming || phoneOnline ? ' on' : '') },
387
+ h('span', { className: 'd' }),
388
+ h('span', null, (function () {
389
+ if (s.busy) return '正在启动…'
390
+ if (streaming) return phoneName ? '投屏中 · ' + phoneName : '投屏中'
391
+ if (phoneOnline) return (phoneName || '手机') + ' 已连接,待启动'
392
+ return '手机不在线'
393
+ })())
394
+ ),
395
+
396
+ /* 一句话说明 —— 只在没连上时出现 */
397
+ !streaming
398
+ ? h('div', { className: '__mw_hintLine' },
399
+ phoneOnline
400
+ ? '点下面的按钮,画面就出来。'
401
+ : '手机连同一个 WiFi,点下面的按钮就行。什么都不用装。')
402
+ : null,
403
+
404
+ /* 唯一的按钮 */
405
+ h('div', { className: '__mw_row' },
406
+ h('button', {
407
+ className: '__mw_btn __mw_btnPri',
408
+ style: { flex: '1' },
409
+ disabled: s.busy,
410
+ onClick: doLaunch
411
+ }, s.busy ? '启动中…' : (streaming ? '重开迷你窗' : '启动迷你窗'))
412
+ ),
413
+
414
+ /* 连不上时的排查提示 —— 折叠起来,不打扰正常使用 */
415
+ phoneOnline && !streaming
416
+ ? h('div', { className: '__mw_warn' },
417
+ '一直没画面:手机重启后需要插一次 USB(3 秒),程序会自动切回无线。')
418
+ : null
419
+ ),
420
+
421
+ h(Msg, { kind: s.kind }, s.message),
422
+
423
+ /* ── 日志 ── */
424
+ logs.length
425
+ ? h('div', { className: '__mw_logBox' },
426
+ h('div', {
427
+ className: '__mw_logToggle',
428
+ onClick: function () { upd({ showLogs: !s.showLogs }) }
429
+ },
430
+ h('span', { className: 'arw' + (s.showLogs ? ' open' : '') }, '▶'),
431
+ h('span', null, '运行日志 (' + logs.length + ')')
432
+ ),
433
+ s.showLogs
434
+ ? h('div', { className: '__mw_logs' },
435
+ logs.map(function (l, i) {
436
+ return h('div', { className: '__mw_logl', key: i },
437
+ h('span', { className: 'lv ' + (l.level || 'info') }, l.level || 'info'),
438
+ h('span', null, l.msg)
439
+ )
440
+ })
441
+ )
442
+ : null
443
+ )
444
+ : null
445
+ )
446
+ }
447
+
448
+ /* ══════════════════════════════════════════════════════════════════
449
+ 侧边栏入口
450
+ ══════════════════════════════════════════════════════════════════ */
451
+ function SidebarButton () {
452
+ var open = react.useState(false)
453
+ var o = open[0], setO = open[1]
454
+
455
+ return h(react.Fragment, null,
456
+ h('button', {
457
+ title: '手机投屏',
458
+ onClick: function () { setO(!o) },
459
+ style: {
460
+ display: 'flex', alignItems: 'center', gap: '9px', width: '100%',
461
+ padding: '9px 12px', border: '1px solid var(--dsw-alias-border-l2)',
462
+ background: o ? 'var(--dsw-alias-bg-layer-3)' : 'transparent',
463
+ color: 'var(--dsw-alias-label-primary)',
464
+ borderRadius: '10px', font: 'inherit', fontSize: '13px',
465
+ fontWeight: '560', cursor: 'pointer', textAlign: 'left',
466
+ transition: 'background .14s,border-color .14s'
467
+ },
468
+ onMouseEnter: function (e) { e.currentTarget.style.borderColor = 'var(--dsw-alias-state-business-primary)' },
469
+ onMouseLeave: function (e) { e.currentTarget.style.borderColor = 'var(--dsw-alias-border-l2)' }
470
+ },
471
+ h(Icon, { className: '__mw_btnIcon', style: { marginRight: '0' } },
472
+ h('rect', { x: 6, y: 2, width: 12, height: 20, rx: 2.5 }),
473
+ h('path', { d: 'M11 18.5h2' })
474
+ ),
475
+ h('span', null, '投屏')
476
+ ),
477
+ o
478
+ ? h('div', {
479
+ style: {
480
+ position: 'fixed', zIndex: 2147483000,
481
+ right: '18px', bottom: '92px', width: '372px',
482
+ maxHeight: 'calc(100vh - 130px)', overflowY: 'auto',
483
+ background: 'var(--dsw-alias-bg-layer-1,#12141a)',
484
+ border: '1px solid var(--dsw-alias-border-l2)',
485
+ borderRadius: '16px', padding: '18px',
486
+ boxShadow: '0 26px 70px rgba(0,0,0,.6)',
487
+ overscrollBehavior: 'contain'
488
+ }
489
+ },
490
+ h('div', {
491
+ style: {
492
+ display: 'flex', justifyContent: 'space-between',
493
+ alignItems: 'center', marginBottom: '14px'
494
+ }
495
+ },
496
+ h('span', { style: { fontSize: '14px', fontWeight: '650' } }, '手机投屏'),
497
+ h('span', {
498
+ style: {
499
+ cursor: 'pointer', color: 'var(--dsw-alias-label-tertiary)',
500
+ fontSize: '17px', lineHeight: 1, width: '24px', height: '24px',
501
+ display: 'grid', placeItems: 'center', borderRadius: '6px'
502
+ },
503
+ onMouseEnter: function (e) { e.currentTarget.style.background = 'var(--dsw-alias-bg-layer-3)' },
504
+ onMouseLeave: function (e) { e.currentTarget.style.background = 'transparent' },
505
+ onClick: function () { setO(false) }
506
+ }, '×')
507
+ ),
508
+ h(Panel, null)
509
+ )
510
+ : null
511
+ )
512
+ }
513
+
514
+ /* ══════════════════════════════════════════════════════════════════
515
+ 插件
516
+ ══════════════════════════════════════════════════════════════════ */
517
+ var inject = ['slots']
518
+
519
+ function apply (ctx) {
520
+ ctx.slots.inject('sidebar.footer.action', function () {
521
+ return ctx.slots.register(
522
+ { name: 'sidebar.footer.action', id: 'miniwin-launch', order: 40, label: '手机投屏' },
523
+ SidebarButton
524
+ )
525
+ })
526
+ }
527
+
528
+ exports.apply = apply
529
+ exports.inject = inject
530
+ return module.exports
531
+ }
532
+ })