dsh-builtin-browser 1.0.0 → 1.0.3
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/CHANGELOG.md +61 -0
- package/README.md +1 -1
- package/assets/browser-panel-locales.mjs +37 -5
- package/assets/browser-policy.d.mts +29 -0
- package/assets/browser-policy.mjs +40 -0
- package/desktop-bridge/desktop-discovery.d.mts +1 -1
- package/desktop-bridge/desktop-discovery.mjs +59 -9
- package/desktop-bridge/desktop-identity.json +12 -0
- package/desktop-bridge/install.mjs +14 -7
- package/desktop-bridge/plugin-browser-bridge.js +19 -7
- package/docs/acceptance-2026-11-27.md +67 -0
- package/docs/architecture.md +1 -1
- package/docs/development.md +33 -4
- package/docs/dsh-0.2.3-host-patch-task.md +34 -0
- package/docs/hardcoding-audit.md +28 -8
- package/docs/known-issues.md +26 -0
- package/docs/limitations.md +6 -2
- package/docs/pr64-maintenance.md +1 -1
- package/docs/tool-reference.md +1 -1
- package/docs/user-guide.md +1 -1
- package/docs/v1.1.0-bu-data-batching-task.md +66 -0
- package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
- package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
- package/dsh-builtin-browser-1.0.3.tgz +0 -0
- package/dsh-host-patch/README.md +4 -0
- package/dsh-host-patch/apply.mjs +61 -13
- package/dsh-host-patch/rc3-revision9.json.gz +0 -0
- package/dsh-host-patch/rc5-revision9.json.gz +0 -0
- package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/manifest.json +218 -0
- package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/series.json +260 -0
- package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
- package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
- package/dsh-host-patch/tauri-revision1.json +39 -0
- package/dsh-host-patch/tauri.json +43 -0
- package/dsh-host-patch/v023-alpha2.json +153 -0
- package/lib/browser/anti-bot.js +215 -0
- package/lib/browser/deep-dom.js +39 -0
- package/lib/browser/runtime.js +15 -0
- package/lib/browser/takeover-target.js +13 -6
- package/lib/browser/types.js +30 -1
- package/lib/browser-electron/authenticated-route.js +16 -2
- package/lib/browser-electron/automatic-maintenance.js +16 -10
- package/lib/browser-electron/bridge-connection.js +3 -8
- package/lib/browser-electron/bridge-install.js +2 -1
- package/lib/browser-electron/bridge-status.js +55 -26
- package/lib/browser-electron/desktop-bridge-host.js +7 -6
- package/lib/browser-electron/desktop-identity.js +28 -5
- package/lib/browser-electron/desktop-shell.js +64 -0
- package/lib/browser-electron/electron-provision.js +105 -18
- package/lib/browser-electron/entry.js +129 -46
- package/lib/browser-electron/extension-browser.js +4 -4
- package/lib/browser-electron/foreground-watch.js +134 -0
- package/lib/browser-electron/guest-cookie-jar.js +13 -13
- package/lib/browser-electron/guest-route.js +181 -32
- package/lib/browser-electron/guest-runtime.js +61 -10
- package/lib/browser-electron/guest-storage.js +2 -2
- package/lib/browser-electron/history-store.js +1 -5
- package/lib/browser-electron/host-main.js +8 -4
- package/lib/browser-electron/host-patch-maintenance.js +14 -8
- package/lib/browser-electron/maintenance-route.js +2 -1
- package/lib/browser-electron/missing-system-browser.js +5 -9
- package/lib/browser-electron/preferred-browser.js +7 -3
- package/lib/browser-electron/preview-route.js +9 -13
- package/lib/browser-electron/process-ownership.js +1 -1
- package/lib/browser-electron/profile-command.js +2 -1
- package/lib/browser-electron/profile-extension.js +5 -0
- package/lib/browser-electron/profile-lease.js +152 -47
- package/lib/browser-electron/provider-core.js +527 -0
- package/lib/browser-electron/provider-interaction.js +963 -0
- package/lib/browser-electron/provider-media.js +518 -0
- package/lib/browser-electron/provider-navigation.js +301 -0
- package/lib/browser-electron/provider-observation.js +623 -0
- package/lib/browser-electron/provider-tabs.js +372 -0
- package/lib/browser-electron/provider.js +150 -3301
- package/lib/browser-electron/reference-route.js +9 -18
- package/lib/browser-electron/remote-host.js +79 -34
- package/lib/browser-electron/runtime-status.js +56 -6
- package/lib/browser-electron/settings-store.js +3 -6
- package/lib/browser-electron/sidebar-only-host.js +1 -1
- package/lib/browser-electron/system-browser.js +539 -172
- package/lib/browser-electron/tauri-host.js +208 -0
- package/lib/browser-electron/virtual-cursor.js +23 -13
- package/lib/browser-reference/service.js +22 -4
- package/lib/browser-reference/web-sources.js +1 -1
- package/lib/client.js +43409 -0
- package/lib/compat/host-features.js +75 -0
- package/lib/reference-source.js +1 -1
- package/lib/reference-text.js +23 -1
- package/lib/takeover-protocol.js +1 -1
- package/lib/tool-browser/block-recovery.js +69 -0
- package/lib/tool-browser/code-tool.js +170 -19
- package/lib/tool-browser/code-worker.js +115 -20
- package/lib/tool-browser/errors.js +34 -0
- package/lib/tool-browser/index.js +66 -3593
- package/lib/tool-browser/page-probe.js +227 -28
- package/lib/tool-browser/panel-page.js +2 -1
- package/lib/tool-browser/probe-client.js +157 -0
- package/lib/tool-browser/screenshot-annotations.js +108 -0
- package/lib/tool-browser/state.js +337 -0
- package/lib/tool-browser/takeover.js +1 -1
- package/lib/tool-browser/tools-debug.js +862 -0
- package/lib/tool-browser/tools-interaction.js +993 -0
- package/lib/tool-browser/tools-navigation.js +807 -0
- package/lib/tool-browser/tools-observation.js +461 -0
- package/lib/tool-browser/tools-reference.js +293 -0
- package/lib/web-guest.js +1 -0
- package/package.json +16 -54
- package/README.en.md +0 -89
- package/browser-extension/constants.mjs +0 -20
- package/browser-extension/controller.mjs +0 -293
- package/browser-extension/locales.mjs +0 -15
- package/browser-extension/manifest.json +0 -12
- package/browser-extension/options.html +0 -14
- package/browser-extension/options.mjs +0 -9
- package/browser-extension/permission-guard.mjs +0 -13
- package/browser-extension/worker.mjs +0 -74
- package/dist/client.cjs +0 -43167
- package/lib/browser-electron/package-removal.js +0 -5
- package/lib/browser-reference/submission-receipts.js +0 -139
- package/scripts/build.mjs +0 -66
- package/scripts/bundle-host.mjs +0 -28
- package/scripts/fix-exports.mjs +0 -50
- package/scripts/install-electron.mjs +0 -51
- package/scripts/verify-exports.mjs +0 -47
- package/scripts/verify-preview-sdk.mjs +0 -93
- package/skills/dsh-builtin-browser/SKILL.md +0 -73
- package/skills/dsh-builtin-browser/references/batch.md +0 -53
- package/skills/dsh-builtin-browser/references/deliver.md +0 -31
- package/skills/dsh-builtin-browser/references/locate.md +0 -11
- package/skills/dsh-builtin-browser/references/recover.md +0 -11
- package/skills/dsh-builtin-browser/references/verify.md +0 -13
- package/skills/dsh-debug-host/SKILL.md +0 -56
- package/skills/dsh-debug-self/SKILL.md +0 -50
- package/src/bridge-compatibility.ts +0 -39
- package/src/browser/handles.ts +0 -89
- package/src/browser/runtime.ts +0 -560
- package/src/browser/takeover-target.ts +0 -36
- package/src/browser/types.ts +0 -817
- package/src/browser-electron/authenticated-route.ts +0 -84
- package/src/browser-electron/automatic-maintenance.ts +0 -726
- package/src/browser-electron/bridge-auto.ts +0 -159
- package/src/browser-electron/bridge-connection.ts +0 -385
- package/src/browser-electron/bridge-endpoint.ts +0 -129
- package/src/browser-electron/bridge-install.ts +0 -289
- package/src/browser-electron/bridge-maintenance.ts +0 -189
- package/src/browser-electron/bridge-status.ts +0 -347
- package/src/browser-electron/desktop-bridge-host.ts +0 -251
- package/src/browser-electron/desktop-identity.ts +0 -320
- package/src/browser-electron/document-readiness.ts +0 -45
- package/src/browser-electron/electron-provision.ts +0 -261
- package/src/browser-electron/entry.ts +0 -1301
- package/src/browser-electron/ephemeral-profile.ts +0 -189
- package/src/browser-electron/extension-browser.ts +0 -223
- package/src/browser-electron/extension-setup.ts +0 -67
- package/src/browser-electron/file-write.ts +0 -31
- package/src/browser-electron/guest-cookie-jar.ts +0 -176
- package/src/browser-electron/guest-cookie-store.ts +0 -59
- package/src/browser-electron/guest-css-runtime.ts +0 -76
- package/src/browser-electron/guest-css.ts +0 -68
- package/src/browser-electron/guest-route.ts +0 -568
- package/src/browser-electron/guest-runtime.ts +0 -357
- package/src/browser-electron/guest-storage-runtime.ts +0 -54
- package/src/browser-electron/guest-storage.ts +0 -117
- package/src/browser-electron/history-store.ts +0 -227
- package/src/browser-electron/host-main.ts +0 -1381
- package/src/browser-electron/host-patch-maintenance.ts +0 -112
- package/src/browser-electron/http-body.ts +0 -65
- package/src/browser-electron/json-reply.ts +0 -47
- package/src/browser-electron/maintenance-broker.ts +0 -166
- package/src/browser-electron/maintenance-lifecycle.ts +0 -91
- package/src/browser-electron/maintenance-route.ts +0 -67
- package/src/browser-electron/missing-system-browser.ts +0 -113
- package/src/browser-electron/open-slot.ts +0 -49
- package/src/browser-electron/package-removal.ts +0 -4
- package/src/browser-electron/paths.ts +0 -25
- package/src/browser-electron/preferred-browser.ts +0 -120
- package/src/browser-electron/preview-route.ts +0 -218
- package/src/browser-electron/process-ownership.ts +0 -168
- package/src/browser-electron/process.ts +0 -23
- package/src/browser-electron/profile-checkpoint.ts +0 -187
- package/src/browser-electron/profile-command.ts +0 -46
- package/src/browser-electron/profile-extension.ts +0 -124
- package/src/browser-electron/profile-lease.ts +0 -115
- package/src/browser-electron/profile-residue.ts +0 -49
- package/src/browser-electron/provider.ts +0 -4571
- package/src/browser-electron/reference-route.ts +0 -608
- package/src/browser-electron/remote-host.ts +0 -1462
- package/src/browser-electron/rpc-input.ts +0 -13
- package/src/browser-electron/rpc-ops.ts +0 -41
- package/src/browser-electron/runtime-diagnostics.ts +0 -38
- package/src/browser-electron/runtime-route.ts +0 -105
- package/src/browser-electron/runtime-status.ts +0 -242
- package/src/browser-electron/settings-route.ts +0 -64
- package/src/browser-electron/settings-store.ts +0 -589
- package/src/browser-electron/shortcuts-route.ts +0 -112
- package/src/browser-electron/sidebar-only-host.ts +0 -298
- package/src/browser-electron/startpage-shortcuts.ts +0 -213
- package/src/browser-electron/system-browser.ts +0 -1497
- package/src/browser-electron/timing.ts +0 -16
- package/src/browser-electron/virtual-cursor.ts +0 -152
- package/src/browser-electron/windows-system.ts +0 -24
- package/src/browser-reference/delivery.ts +0 -384
- package/src/browser-reference/entry.ts +0 -631
- package/src/browser-reference/export.ts +0 -339
- package/src/browser-reference/import.ts +0 -303
- package/src/browser-reference/page-script.ts +0 -1537
- package/src/browser-reference/service.ts +0 -1315
- package/src/browser-reference/store.ts +0 -172
- package/src/browser-reference/submission-receipts.ts +0 -122
- package/src/browser-reference/text-quote.ts +0 -219
- package/src/browser-reference/types.ts +0 -195
- package/src/browser-reference/visible.ts +0 -367
- package/src/browser-reference/web-sources.ts +0 -103
- package/src/client/browser/BrowserController.ts +0 -693
- package/src/client/browser/BrowserFrame.ts +0 -78
- package/src/client/browser/BrowserNavigation.ts +0 -169
- package/src/client/browser/BrowserPage.ts +0 -23
- package/src/client/browser/BrowserPersistence.ts +0 -44
- package/src/client/browser/IframeImpl.ts +0 -176
- package/src/client/browser/child-tabs.ts +0 -14
- package/src/client/browser/iframe-reference.ts +0 -67
- package/src/client/browser/initialization.ts +0 -262
- package/src/client/browser/omnibox.ts +0 -243
- package/src/client/browser/store.ts +0 -38
- package/src/client/browser/takeover-channel.ts +0 -72
- package/src/client/browser/url.ts +0 -46
- package/src/client/browser/web-reference-source.ts +0 -52
- package/src/client/css-modules.d.ts +0 -4
- package/src/client/definition.tsx +0 -30
- package/src/client/electron/ElectronWebViewImpl.ts +0 -364
- package/src/client/electron/ElectronWebviewPresentation.ts +0 -138
- package/src/client/electron/NativeChildPresentation.ts +0 -45
- package/src/client/electron/NativeViewPage.ts +0 -251
- package/src/client/electron/pages.ts +0 -23
- package/src/client/electron/reference-overlay.ts +0 -53
- package/src/client/electron/workspace.ts +0 -33
- package/src/client/index.ts +0 -293
- package/src/client/locales.ts +0 -857
- package/src/client/pages.ts +0 -28
- package/src/client/reference/client/BrowserRefLink.tsx +0 -142
- package/src/client/reference/client/draft-reference.ts +0 -167
- package/src/client/reference/client/index.ts +0 -7
- package/src/client/reference/client/ordered-submission.ts +0 -108
- package/src/client/reference/client/pending-delivery.ts +0 -216
- package/src/client/reference/client/plugin.ts +0 -189
- package/src/client/reference/client/production/ReferenceCapsules.tsx +0 -345
- package/src/client/reference/client/production/ReferenceDock.module.css +0 -193
- package/src/client/reference/client/production/ReferenceDock.tsx +0 -6
- package/src/client/reference/client/production/ReferenceFeedback.tsx +0 -15
- package/src/client/reference/client/production/ReferenceMath.tsx +0 -44
- package/src/client/reference/client/production/ReferenceText.tsx +0 -36
- package/src/client/reference/client/production/assembly.ts +0 -471
- package/src/client/reference/client/production/asset-store.ts +0 -144
- package/src/client/reference/client/production/availability.ts +0 -74
- package/src/client/reference/client/production/bytes.ts +0 -36
- package/src/client/reference/client/production/delivery-client.ts +0 -211
- package/src/client/reference/client/production/draft-adapter.ts +0 -508
- package/src/client/reference/client/production/http-transport.ts +0 -217
- package/src/client/reference/client/production/production-submission.ts +0 -310
- package/src/client/reference/client/production/protocol.ts +0 -231
- package/src/client/reference/client/production/reference-card.ts +0 -240
- package/src/client/reference/client/production/reference-labels.ts +0 -29
- package/src/client/reference/client/production/reply-link-bridge.ts +0 -222
- package/src/client/reference/client/production/reveal.ts +0 -215
- package/src/client/reference/client/production/runtime.ts +0 -1101
- package/src/client/reference/client/production/snapshot-adapter.ts +0 -154
- package/src/client/reference/client/production/source-marker.ts +0 -63
- package/src/client/reference/client/production/source-opener.ts +0 -55
- package/src/client/reference/client/production/styles.ts +0 -104
- package/src/client/reference/client/production/user-text-rule.ts +0 -58
- package/src/client/reference/client/reveal.ts +0 -107
- package/src/client/reference/client/scheme.ts +0 -114
- package/src/client/reference/client/types.ts +0 -168
- package/src/client/reference/css-modules.d.ts +0 -4
- package/src/client/reference/index.ts +0 -11
- package/src/client/reference-capture-owner.ts +0 -162
- package/src/client/reference-intents.ts +0 -36
- package/src/client/settings/index.ts +0 -34
- package/src/client/settings/panel.ts +0 -2657
- package/src/client/shortcut-open.ts +0 -30
- package/src/client/startpage/binding.ts +0 -99
- package/src/client/startpage/controller.ts +0 -303
- package/src/client/startpage/model.ts +0 -279
- package/src/client/view/Browser.module.css +0 -751
- package/src/client/view/BrowserBody.tsx +0 -314
- package/src/client/view/BrowserPresentation.ts +0 -9
- package/src/client/view/BrowserTitle.tsx +0 -17
- package/src/client/view/IframePresentation.ts +0 -344
- package/src/client/view/StartPage.tsx +0 -597
- package/src/client/view/TakeoverBanner.tsx +0 -21
- package/src/index.ts +0 -110
- package/src/reference-owner.ts +0 -5
- package/src/reference-page.ts +0 -9
- package/src/reference-source.ts +0 -3
- package/src/reference-text.ts +0 -197
- package/src/startpage-settings.ts +0 -103
- package/src/startpage.ts +0 -71
- package/src/takeover-protocol.ts +0 -19
- package/src/tool-browser/code-tool.ts +0 -401
- package/src/tool-browser/code-worker.ts +0 -639
- package/src/tool-browser/element-fields.ts +0 -167
- package/src/tool-browser/index.ts +0 -3733
- package/src/tool-browser/page-probe.ts +0 -474
- package/src/tool-browser/panel-page.ts +0 -124
- package/src/tool-browser/screenshot-image.ts +0 -49
- package/src/tool-browser/takeover.ts +0 -198
- package/src/types/electron-shim.d.ts +0 -144
- package/src/types.ts +0 -85
- package/src/web-guest.ts +0 -34
- package/tools/accept-desktop.mjs +0 -148
|
@@ -1,2657 +0,0 @@
|
|
|
1
|
-
import { zh, en } from '../../../assets/browser-panel-locales.mjs'
|
|
2
|
-
import { REFERENCE_REVEAL_ROUTE, REFERENCE_INSERT_ROUTE, REFERENCE_IMPORT_ROUTE, REFERENCE_DELIVERY_REMOVE_ROUTE, PREVIEW_ROUTE, PREVIEW_SESSIONS_ROUTE, BRIDGE_STATUS_ROUTE, RUNTIME_STATUS_ROUTE, RUNTIME_PROVISION_ROUTE } from '../../../assets/browser-policy.mjs'
|
|
3
|
-
import { SETTINGS_ROUTE, EXTENSION_INSTALL_ROUTE } from '../../../assets/browser-policy.mjs'
|
|
4
|
-
/**
|
|
5
|
-
* 设置面板(客户端半):从旧插件的 ModuleLoader bundle 机械移植而来,内部实现未改一行。
|
|
6
|
-
*
|
|
7
|
-
* 它注册进设置页的 `settings.section` 插槽,渲染宿主 `/dsh-builtin-browser/settings` 返回的
|
|
8
|
-
* 设置文档并回写补丁;宿主那一份文件仍是唯一事实来源(面板不可用时也能手改)。
|
|
9
|
-
*
|
|
10
|
-
* 外壳由 `window.__ModuleLoader__.load({factory})` 换成普通导出函数:本仓库的客户端半由
|
|
11
|
-
* tsdown 打成 CJS 工厂,`require` 由模块加载器在运行期注入,语义与旧加载器一致。
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
export interface LegacyClientModule {
|
|
15
|
-
readonly name?: string
|
|
16
|
-
readonly inject?: readonly string[]
|
|
17
|
-
readonly apply: (ctx: never) => void
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function requestExtensionSetup(fetcher = fetch) {
|
|
21
|
-
const response = await fetcher(EXTENSION_INSTALL_ROUTE, { method: 'POST', headers: { accept: 'application/json' } })
|
|
22
|
-
const result = await response.json()
|
|
23
|
-
if (!response.ok || !result.ok) throw new Error(result.detail ?? `HTTP ${response.status}`)
|
|
24
|
-
return result
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 装配旧面板:调用一次返回它的 `{ name, inject, apply }`。
|
|
29
|
-
* @param require - 模块加载器注入的 require(与旧加载器同签名)。
|
|
30
|
-
* @returns 旧 bundle 导出的模块对象。
|
|
31
|
-
*/
|
|
32
|
-
export function loadSettingsPanel(require: (id: string) => unknown): LegacyClientModule {
|
|
33
|
-
var module = { exports: {} }
|
|
34
|
-
var exports = module.exports
|
|
35
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" })
|
|
36
|
-
|
|
37
|
-
const react = require("react")
|
|
38
|
-
const h = react.createElement
|
|
39
|
-
const { useCallback, useEffect, useRef, useState } = react
|
|
40
|
-
|
|
41
|
-
const name = "dsh-builtin-browser"
|
|
42
|
-
const inject = ["slots", "locale"]
|
|
43
|
-
const NS = "settings.dsh-builtin-browser"
|
|
44
|
-
const ROUTE = SETTINGS_ROUTE
|
|
45
|
-
let translate = (key) => key
|
|
46
|
-
let currentLocale = "zh"
|
|
47
|
-
function updateCurrentLocale(locale) {
|
|
48
|
-
let active
|
|
49
|
-
try { active = locale.getSnapshot?.().active ?? locale.getLocale?.().active } catch { /* Older hosts may only expose bind. */ }
|
|
50
|
-
const language = typeof active === "string" ? active : typeof document === "undefined" ? "" : document.documentElement?.lang
|
|
51
|
-
currentLocale = typeof language === "string" && /^en(?:-|$)/i.test(language) ? "en" : "zh"
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Re-evaluate the floating watch entry.
|
|
55
|
-
*
|
|
56
|
-
* Set by `installWatchPanel`, called by the settings writer after a `remoteView` change so the
|
|
57
|
-
* switch takes effect on the spot. A no-op until the panel is installed, and a no-op forever on a
|
|
58
|
-
* host without one.
|
|
59
|
-
*/
|
|
60
|
-
let refreshWatchEntry = () => {}
|
|
61
|
-
/**
|
|
62
|
-
* Re-apply the locale to the watch panel's static labels.
|
|
63
|
-
*
|
|
64
|
-
* Set by `installWatchPanel`, called from the locale subscription in `apply()`. Separate from
|
|
65
|
-
* {@link refreshWatchEntry} because a language switch must not re-probe or re-mount anything.
|
|
66
|
-
*/
|
|
67
|
-
let refreshWatchLabels = () => {}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Read or patch the host-owned settings document.
|
|
72
|
-
*
|
|
73
|
-
* A patch that touches remote viewing re-evaluates the floating entry right away. Without that,
|
|
74
|
-
* turning the switch on wrote the file and did nothing anyone could see until the page was
|
|
75
|
-
* reloaded — unusable from a phone, and reported as such on #46.
|
|
76
|
-
*/
|
|
77
|
-
async function callSettings(patch) {
|
|
78
|
-
const response = await fetch(ROUTE, patch === undefined
|
|
79
|
-
? { method: "GET", headers: { accept: "application/json" } }
|
|
80
|
-
: {
|
|
81
|
-
method: "PUT",
|
|
82
|
-
headers: { "content-type": "application/json" },
|
|
83
|
-
body: JSON.stringify(patch),
|
|
84
|
-
})
|
|
85
|
-
const data = await response.json().catch(() => undefined)
|
|
86
|
-
if (data === undefined || data.ok !== true) {
|
|
87
|
-
throw new Error((data && data.error) || `HTTP ${response.status}`)
|
|
88
|
-
}
|
|
89
|
-
if (patch !== undefined && patch !== null && typeof patch === "object" && patch.remoteView !== undefined) {
|
|
90
|
-
try { refreshWatchEntry() } catch { /* the entry is a convenience, not the setting */ }
|
|
91
|
-
}
|
|
92
|
-
return data
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* The panel's own stylesheet.
|
|
97
|
-
*
|
|
98
|
-
* Inline styles cannot express `:hover`, and the rows need one — an interactive row with no
|
|
99
|
-
* feedback reads as decoration. The colours come from DSH's own design tokens
|
|
100
|
-
* (`--dsw-alias-*`, the same ones the host's settings rows use) so this follows the active
|
|
101
|
-
* theme instead of guessing at it; each has a literal fallback because a token may be absent
|
|
102
|
-
* under a third-party theme, and an unstyled row is worse than a slightly-off one.
|
|
103
|
-
*/
|
|
104
|
-
const CSS = `
|
|
105
|
-
.dsh-bb-settings .dsh-bb-row {
|
|
106
|
-
min-height: 36px;
|
|
107
|
-
align-items: center;
|
|
108
|
-
justify-content: space-between;
|
|
109
|
-
padding: 8px 0;
|
|
110
|
-
border-bottom: .5px solid var(--dsw-alias-border-l2, GrayText);
|
|
111
|
-
border-radius: 0;
|
|
112
|
-
background: transparent;
|
|
113
|
-
}
|
|
114
|
-
.dsh-bb-settings { font-size: 14px; line-height: 22px; }
|
|
115
|
-
.dsh-bb-references > summary { display: list-item; }
|
|
116
|
-
.dsh-bb-ref-count { margin-left: 8px; color: var(--dsw-alias-label-tertiary, GrayText); font-size: 12px; font-weight: 400; }
|
|
117
|
-
.dsh-bb-ref-toolbar, .dsh-bb-ref-transfer-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
|
118
|
-
.dsh-bb-ref-toolbar { justify-content: flex-end; margin: 4px 0; }
|
|
119
|
-
.dsh-bb-ref-list { list-style: none; padding: 0; margin: 0; }
|
|
120
|
-
.dsh-bb-ref-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: .5px solid var(--dsw-alias-border-l2, GrayText); }
|
|
121
|
-
.dsh-bb-ref-content { flex: 1; min-width: 0; display: grid; gap: 4px; }
|
|
122
|
-
.dsh-bb-ref-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
|
|
123
|
-
.dsh-bb-ref-preview { margin: 0; color: var(--dsw-alias-label-secondary, inherit); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; font-size: 13px; line-height: 1.5; }
|
|
124
|
-
.dsh-bb-ref-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; color: var(--dsw-alias-label-tertiary, GrayText); font-size: 12px; line-height: 1.5; }
|
|
125
|
-
.dsh-bb-ref-source { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
126
|
-
.dsh-bb-ref-item > button { flex: none; white-space: nowrap; }
|
|
127
|
-
.dsh-bb-ref-transfer { margin-top: 10px; }
|
|
128
|
-
.dsh-bb-ref-transfer-actions { padding: 6px 0; }
|
|
129
|
-
.dsh-bb-ref-outcome { margin: 0; font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
|
|
130
|
-
@media (pointer: coarse) { .dsh-bb-ref-item > button, .dsh-bb-ref-toolbar button, .dsh-bb-ref-transfer-actions button { min-height: 40px !important; } }
|
|
131
|
-
.dsh-bb-ref-menu { position: relative; display: inline-flex; align-items: center; }
|
|
132
|
-
.dsh-bb-ref-toggle { font: inherit; padding: 4px 10px; border: .5px solid var(--dsw-alias-border-l2, GrayText); border-radius: 6px; background: transparent; color: inherit; cursor: pointer; white-space: nowrap; }
|
|
133
|
-
.dsh-bb-ref-toggle:hover { background: var(--dsw-alias-fill-hover, rgba(127,127,127,.12)); }
|
|
134
|
-
.dsh-bb-ref-popover { position: fixed; right: 24px; bottom: 88px; z-index: 2147483000; width: min(460px, calc(100vw - 32px)); max-height: min(70vh, 640px); overflow: auto; padding: 14px 16px; border: .5px solid var(--dsw-alias-border-l2, GrayText); border-radius: 10px; background: var(--dsw-alias-bg-l1, Canvas); color: var(--dsw-alias-label-primary, CanvasText); box-shadow: 0 8px 28px rgba(0,0,0,.18); font-size: 13px; }
|
|
135
|
-
.dsh-bb-ref-actions { display: flex; flex-wrap: wrap; gap: 6px; flex: none; }
|
|
136
|
-
.dsh-bb-ref-actions button { font-size: 12px; }
|
|
137
|
-
@media (pointer: coarse) { .dsh-bb-ref-actions button, .dsh-bb-ref-toggle { min-height: 40px !important; } }
|
|
138
|
-
.dsh-bb-settings .dsh-bb-diagnostics { margin-top: 4px; }
|
|
139
|
-
.dsh-bb-diagnostics code { display: block; max-height: 160px; overflow: auto; }
|
|
140
|
-
.dsh-bb-toggle { justify-content: space-between; cursor: pointer; }
|
|
141
|
-
.dsh-bb-toggle:has(:disabled) { cursor: default; }
|
|
142
|
-
.dsh-bb-switch {
|
|
143
|
-
appearance: none;
|
|
144
|
-
position: relative;
|
|
145
|
-
flex: 0 0 36px;
|
|
146
|
-
width: 36px;
|
|
147
|
-
height: 20px;
|
|
148
|
-
margin: 0;
|
|
149
|
-
box-sizing: border-box;
|
|
150
|
-
border: 0;
|
|
151
|
-
border-radius: 999px;
|
|
152
|
-
corner-shape: round;
|
|
153
|
-
background: var(--dsw-alias-border-l3, GrayText);
|
|
154
|
-
color: var(--dsw-alias-switch-thumb, Canvas);
|
|
155
|
-
cursor: inherit;
|
|
156
|
-
}
|
|
157
|
-
.dsh-bb-switch::after {
|
|
158
|
-
content: "";
|
|
159
|
-
position: absolute;
|
|
160
|
-
inset: 2px auto auto 2px;
|
|
161
|
-
width: 16px;
|
|
162
|
-
height: 16px;
|
|
163
|
-
border-radius: 50%;
|
|
164
|
-
corner-shape: round;
|
|
165
|
-
background: currentColor;
|
|
166
|
-
}
|
|
167
|
-
.dsh-bb-switch:checked {
|
|
168
|
-
background: var(--dsw-alias-brand-primary, Highlight);
|
|
169
|
-
color: var(--dsw-alias-label-primary-foreground, HighlightText);
|
|
170
|
-
}
|
|
171
|
-
.dsh-bb-switch:checked::after { transform: translateX(16px); }
|
|
172
|
-
.dsh-bb-switch:disabled { opacity: .6; }
|
|
173
|
-
.dsh-bb-settings :is(button, input, textarea, select, summary):focus-visible {
|
|
174
|
-
outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, Highlight);
|
|
175
|
-
outline-offset: 2px;
|
|
176
|
-
}
|
|
177
|
-
.dsh-bb-settings summary { cursor: pointer; padding: 5px 0; }
|
|
178
|
-
.dsh-bb-settings .dsh-bb-dd { flex: 0 1 auto; margin: 0; }
|
|
179
|
-
.dsh-bb-settings .dsh-bb-dd-btn {
|
|
180
|
-
min-height: 36px;
|
|
181
|
-
padding: 0 14px;
|
|
182
|
-
border: 0;
|
|
183
|
-
border-radius: var(--dsw-radius-md, 8px);
|
|
184
|
-
background: var(--dsw-alias-bg-module-platform, ButtonFace);
|
|
185
|
-
}
|
|
186
|
-
.dsh-bb-settings .dsh-bb-dd-list { left: auto; right: 0; }
|
|
187
|
-
.dsh-bb-settings .dsh-bb-input {
|
|
188
|
-
box-sizing: border-box;
|
|
189
|
-
width: 100%;
|
|
190
|
-
min-height: 34px;
|
|
191
|
-
padding: 6px 8px;
|
|
192
|
-
border: 1px solid var(--dsw-alias-border, GrayText);
|
|
193
|
-
border-radius: 7px;
|
|
194
|
-
background: var(--dsw-alias-bg-layer-1, Canvas);
|
|
195
|
-
color: var(--dsw-alias-label-primary, CanvasText);
|
|
196
|
-
font: inherit;
|
|
197
|
-
}
|
|
198
|
-
.dsh-bb-settings fieldset { min-inline-size: 0; }
|
|
199
|
-
.dsh-bb-settings textarea { resize: vertical; }
|
|
200
|
-
.dsh-bb-row {
|
|
201
|
-
border-radius: 8px;
|
|
202
|
-
padding: 7px 9px;
|
|
203
|
-
color: var(--dsw-alias-label-primary, inherit);
|
|
204
|
-
transition: background-color .12s ease;
|
|
205
|
-
}
|
|
206
|
-
/* Only the switch rows act as a single control; status and selector rows are plain text. */
|
|
207
|
-
.dsh-bb-toggle:hover:not(:has(:disabled)) {
|
|
208
|
-
background: var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.15));
|
|
209
|
-
}
|
|
210
|
-
.dsh-bb-toggle:active:not(:has(:disabled)) {
|
|
211
|
-
background: var(--dsw-alias-interactive-bg-active, rgba(128,128,128,.22));
|
|
212
|
-
}
|
|
213
|
-
/* The dropdown is drawn here rather than by the OS.
|
|
214
|
-
A native <select> paints its popup with system colours on Windows: the highlight overrides
|
|
215
|
-
whatever the option sets (white text on a white bar), and the list carries a border no CSS
|
|
216
|
-
can remove. Only the collapsed control is styleable, so a panel that matches its theme
|
|
217
|
-
everywhere else ends up with one control that does not. Everything below is ours: the
|
|
218
|
-
surface, the highlight, and the absence of that line. */
|
|
219
|
-
.dsh-bb-dd {
|
|
220
|
-
position: relative;
|
|
221
|
-
display: inline-block;
|
|
222
|
-
max-width: min(100%, calc(100vw - 32px));
|
|
223
|
-
margin-top: 4px;
|
|
224
|
-
}
|
|
225
|
-
.dsh-bb-dd-btn {
|
|
226
|
-
display: flex;
|
|
227
|
-
align-items: center;
|
|
228
|
-
gap: 8px;
|
|
229
|
-
max-width: 100%;
|
|
230
|
-
padding: 4px 8px 4px 9px;
|
|
231
|
-
border: 1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.4));
|
|
232
|
-
border-radius: 6px;
|
|
233
|
-
background: var(--dsw-alias-bg-layer-2, rgba(128,128,128,.12));
|
|
234
|
-
color: var(--dsw-alias-label-primary, inherit);
|
|
235
|
-
font: inherit;
|
|
236
|
-
text-align: left;
|
|
237
|
-
cursor: pointer;
|
|
238
|
-
}
|
|
239
|
-
.dsh-bb-dd-btn:hover:not(:disabled) {
|
|
240
|
-
background: var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.18));
|
|
241
|
-
}
|
|
242
|
-
.dsh-bb-dd-btn:disabled { opacity: .55; cursor: default; }
|
|
243
|
-
.dsh-bb-dd-btn > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
244
|
-
.dsh-bb-dd-caret { flex-shrink: 0; opacity: .6; font-size: 10px; line-height: 1; }
|
|
245
|
-
.dsh-bb-dd-list {
|
|
246
|
-
position: absolute;
|
|
247
|
-
box-sizing: border-box;
|
|
248
|
-
z-index: 20;
|
|
249
|
-
top: calc(100% + 4px);
|
|
250
|
-
left: 0;
|
|
251
|
-
width: max-content;
|
|
252
|
-
min-width: 100%;
|
|
253
|
-
max-width: min(340px, calc(100vw - 32px));
|
|
254
|
-
padding: 4px;
|
|
255
|
-
border: 1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.4));
|
|
256
|
-
border-radius: 8px;
|
|
257
|
-
background: var(--dsw-alias-bg-layer-2, #2f2f2f);
|
|
258
|
-
box-shadow: 0 6px 20px rgba(0,0,0,.28);
|
|
259
|
-
}
|
|
260
|
-
.dsh-bb-dd-opt {
|
|
261
|
-
display: block;
|
|
262
|
-
box-sizing: border-box;
|
|
263
|
-
width: 100%;
|
|
264
|
-
padding: 6px 9px;
|
|
265
|
-
border: none;
|
|
266
|
-
border-radius: 6px;
|
|
267
|
-
background: transparent;
|
|
268
|
-
color: var(--dsw-alias-label-primary, inherit);
|
|
269
|
-
font: inherit;
|
|
270
|
-
text-align: left;
|
|
271
|
-
white-space: nowrap;
|
|
272
|
-
overflow: hidden;
|
|
273
|
-
text-overflow: ellipsis;
|
|
274
|
-
cursor: pointer;
|
|
275
|
-
}
|
|
276
|
-
/* The same ellipse the rows use, so the panel reads as one surface — and it is ours to draw,
|
|
277
|
-
which is the whole reason this control exists. */
|
|
278
|
-
.dsh-bb-dd-opt:hover,
|
|
279
|
-
.dsh-bb-dd-opt[data-active="true"] {
|
|
280
|
-
background: var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.18));
|
|
281
|
-
}
|
|
282
|
-
.dsh-bb-dd-opt[aria-selected="true"] { font-weight: 600; }
|
|
283
|
-
|
|
284
|
-
/* Live-view panel. Fixed layer rather than a slot: the host has no stable slot for an extra
|
|
285
|
-
surface over the conversation, and a layer works in every layout including a phone. */
|
|
286
|
-
.dsh-bw-watch {
|
|
287
|
-
position: fixed; right: 16px; bottom: 16px; font-family: inherit;
|
|
288
|
-
/* Below a modal or popover rather than above everything: the old 2147483000 sat on top of the page,
|
|
289
|
-
* its inputs and any dialog the host opened (issue #46). A floating helper is a guest here. */
|
|
290
|
-
z-index: 1000;
|
|
291
|
-
}
|
|
292
|
-
.dsh-bw-watch-open {
|
|
293
|
-
display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
|
|
294
|
-
border: 1px solid var(--dsw-alias-border, rgba(128,128,128,.45)); border-radius: 999px;
|
|
295
|
-
padding: 7px 13px; font-size: 12px; color: inherit;
|
|
296
|
-
background: var(--dsw-alias-interactive-bg, rgba(128,128,128,.12));
|
|
297
|
-
}
|
|
298
|
-
.dsh-bw-watch-open:hover { background: var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.2)); }
|
|
299
|
-
.dsh-bw-watch-dot { width: 7px; height: 7px; border-radius: 50%; background: #d9534f; }
|
|
300
|
-
.dsh-bw-watch-panel {
|
|
301
|
-
position: absolute; right: 0; bottom: calc(100% + 8px); width: min(560px, calc(100vw - 32px));
|
|
302
|
-
/* The panel used to sit at 40px from the bottom while the button it hangs off occupied 16-46px
|
|
303
|
-
* from the bottom edge of its own box: the two overlapped by 6px and, because the panel's
|
|
304
|
-
* background is opaque, it covered the only way back out (issue #46). 100% is the button's own
|
|
305
|
-
* height, so the gap survives a font-size or padding change instead of being a second magic
|
|
306
|
-
* number. */
|
|
307
|
-
border: 1px solid var(--dsw-alias-border, rgba(128,128,128,.35)); border-radius: 10px;
|
|
308
|
-
/* --dsw-alias-bg-elevated does not exist in the theme this ships against (measured on rc.5: 0
|
|
309
|
-
* occurrences, while --dsw-alias-bg-layer-2 has 5). With a token that is never defined, the
|
|
310
|
-
* fallback is what everyone sees — a dark card in a light theme. bg-layer-2 is the token the
|
|
311
|
-
* host's own elevated rows use. */
|
|
312
|
-
background: var(--dsw-alias-bg-layer-2, #1b1b1f); color: inherit; overflow: hidden;
|
|
313
|
-
box-shadow: 0 10px 30px rgba(0,0,0,.35);
|
|
314
|
-
}
|
|
315
|
-
.dsh-bw-watch-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-size: 12px; }
|
|
316
|
-
.dsh-bw-watch-title { font-weight: 600; }
|
|
317
|
-
.dsh-bw-watch-state { opacity: .7; margin-left: auto; }
|
|
318
|
-
.dsh-bw-watch-session {
|
|
319
|
-
max-width: 40%; font-size: 11px; color: inherit; background: transparent; cursor: pointer;
|
|
320
|
-
border: 1px solid var(--dsw-alias-border, rgba(128,128,128,.45)); border-radius: 5px; padding: 2px 4px;
|
|
321
|
-
}
|
|
322
|
-
.dsh-bw-watch-session[hidden] { display: none; }
|
|
323
|
-
.dsh-bw-watch-close {
|
|
324
|
-
/* A visible control, not a hinted one: the old close was a 16px glyph at 70% opacity with no border
|
|
325
|
-
* or background, in the same colour as the title — reported as 'no way out but a page refresh'
|
|
326
|
-
* (issue #46). */
|
|
327
|
-
border: 1px solid var(--dsw-alias-border, rgba(128,128,128,.45)); border-radius: 6px;
|
|
328
|
-
background: var(--dsw-alias-interactive-bg, rgba(128,128,128,.12));
|
|
329
|
-
color: inherit; cursor: pointer; font-size: 14px; line-height: 1; padding: 3px 7px;
|
|
330
|
-
}
|
|
331
|
-
.dsh-bw-watch-close:hover { background: var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.2)); }
|
|
332
|
-
.dsh-bw-watch-stage { background: #000; min-height: 120px; display: flex; align-items: center; justify-content: center; }
|
|
333
|
-
.dsh-bw-watch-img { display: block; max-width: 100%; height: auto; }
|
|
334
|
-
/* The hidden ATTRIBUTE is styled by the UA sheet as [hidden]{display:none}, and an author rule
|
|
335
|
-
* defeats it whatever its specificity — so img.hidden = true in the script did nothing and the
|
|
336
|
-
* empty-state image kept taking space (issue #46). */
|
|
337
|
-
.dsh-bw-watch-img[hidden] { display: none; }
|
|
338
|
-
.dsh-bw-watch-note { margin: 0; padding: 24px 14px; font-size: 12px; opacity: .75; text-align: center; }
|
|
339
|
-
.dsh-bw-watch-foot {
|
|
340
|
-
display: flex; align-items: center; gap: 8px; padding: 7px 10px;
|
|
341
|
-
font-size: 11px; border-top: 1px solid var(--dsw-alias-border, rgba(128,128,128,.25));
|
|
342
|
-
}
|
|
343
|
-
.dsh-bw-watch-readonly { opacity: .6; }
|
|
344
|
-
.dsh-bw-watch-bridge { padding: 8px 10px; font-size: 11px; border-bottom: 1px solid var(--dsw-alias-border, rgba(128,128,128,.25)); background: rgba(217,83,79,.12); }
|
|
345
|
-
.dsh-bw-watch-bridge-line { line-height: 1.5; }
|
|
346
|
-
.dsh-bw-watch-bridge-cmd { display: block; margin-top: 5px; padding: 5px 7px; font-size: 11px; white-space: pre-wrap; word-break: break-all; background: rgba(0,0,0,.28); border-radius: 5px; }
|
|
347
|
-
.dsh-bw-watch-stop {
|
|
348
|
-
margin-left: auto; cursor: pointer; font-size: 11px; padding: 4px 10px;
|
|
349
|
-
border: 1px solid var(--dsw-alias-border, rgba(128,128,128,.45)); border-radius: 6px;
|
|
350
|
-
background: transparent; color: inherit;
|
|
351
|
-
}
|
|
352
|
-
`
|
|
353
|
-
|
|
354
|
-
/** Install the stylesheet once, however many times the panel is mounted. */
|
|
355
|
-
function installStyles() {
|
|
356
|
-
if (typeof document === "undefined") return
|
|
357
|
-
if (document.getElementById("dsh-builtin-browser-styles") !== null) return
|
|
358
|
-
const tag = document.createElement("style")
|
|
359
|
-
tag.id = "dsh-builtin-browser-styles"
|
|
360
|
-
tag.textContent = CSS
|
|
361
|
-
document.head.appendChild(tag)
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
const styles = {
|
|
365
|
-
wrap: { display: "flex", flexDirection: "column", gap: "12px" },
|
|
366
|
-
lead: { opacity: 0.75, lineHeight: 1.6, margin: 0 },
|
|
367
|
-
group: { minWidth: 0 },
|
|
368
|
-
groupTitle: { margin: "0 0 2px", fontSize: "14px", fontWeight: 600, color: "var(--dsw-alias-label-primary, inherit)" },
|
|
369
|
-
row: { display: "flex", gap: "10px", alignItems: "flex-start" },
|
|
370
|
-
label: { display: "flex", flexDirection: "column", gap: "2px", cursor: "pointer" },
|
|
371
|
-
hint: { color: "var(--dsw-alias-label-tertiary, inherit)", fontSize: "12px", lineHeight: 1.5 },
|
|
372
|
-
status: { opacity: 0.7, minHeight: "18px" },
|
|
373
|
-
error: { color: "var(--dsw-alias-label-error, #c9342c)" },
|
|
374
|
-
pathLine: { opacity: 0.6, wordBreak: "break-all", lineHeight: 1.5 },
|
|
375
|
-
button: { minHeight: "32px", padding: "5px 12px", borderRadius: "8px", border: "1px solid var(--dsw-alias-border, rgba(128,128,128,.4))", background: "transparent", color: "inherit", font: "inherit", cursor: "pointer" },
|
|
376
|
-
// Readiness: one headline state, three one-line facts, and at most two buttons. The colours are
|
|
377
|
-
// the only place this panel states an opinion, which is why they carry no text of their own —
|
|
378
|
-
// the label next to them is always a locale string.
|
|
379
|
-
badge: { display: "inline-block", padding: "1px 8px", marginRight: "8px", borderRadius: "10px", fontSize: "11px", lineHeight: 1.6, border: "1px solid transparent" },
|
|
380
|
-
badgeOk: { color: "#2f9e44", borderColor: "rgba(47,158,68,.5)", background: "rgba(47,158,68,.12)" },
|
|
381
|
-
badgeWarn: { color: "#e5534b", borderColor: "rgba(229,83,75,.5)", background: "rgba(229,83,75,.12)" },
|
|
382
|
-
badgeUnknown: { color: "#a0a0a8", borderColor: "rgba(160,160,168,.5)", background: "rgba(160,160,168,.12)" },
|
|
383
|
-
kv: { display: "grid", gridTemplateColumns: "auto 1fr", gap: "3px 12px", margin: "8px 0 0", fontSize: "12px" },
|
|
384
|
-
kvKey: { opacity: 0.68 },
|
|
385
|
-
kvVal: { lineHeight: 1.5 },
|
|
386
|
-
mono: { fontFamily: "ui-monospace, SFMono-Regular, Consolas, monospace", fontSize: "11px", whiteSpace: "pre-wrap", wordBreak: "break-all", background: "var(--dsw-alias-bg-layer-2, rgba(0,0,0,.22))", borderRadius: "5px", padding: "4px 6px", marginTop: "4px" },
|
|
387
|
-
buttons: { display: "flex", gap: "8px", alignItems: "center", marginTop: "10px", flexWrap: "wrap" },
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* A dropdown drawn by this panel rather than by the operating system.
|
|
392
|
-
*
|
|
393
|
-
* Replaces a native `<select>`, whose popup Windows paints with system colours: the hover
|
|
394
|
-
* highlight overrode the option's background (white text on a white bar) and the list carried
|
|
395
|
-
* a border no CSS could remove. Both are unfixable from outside the control, and this panel's
|
|
396
|
-
* two dropdowns were the only places it did not match its own theme.
|
|
397
|
-
*
|
|
398
|
-
* Keyboard and assistive-technology behaviour is reimplemented rather than inherited, which is
|
|
399
|
-
* the cost of owning the rendering: Up/Down move, Enter/Space commit, Escape closes and
|
|
400
|
-
* returns focus, Home/End jump, clicking outside closes.
|
|
401
|
-
*/
|
|
402
|
-
function Dropdown(props) {
|
|
403
|
-
const [open, setOpen] = useState(false)
|
|
404
|
-
// Index the keyboard has moved to; -1 means "the selected value, unless the user moved".
|
|
405
|
-
const [active, setActive] = useState(-1)
|
|
406
|
-
const rootRef = useRef(null)
|
|
407
|
-
const buttonRef = useRef(null)
|
|
408
|
-
|
|
409
|
-
const selected = props.options.findIndex(option => option.value === props.value)
|
|
410
|
-
const current = props.options[selected] ?? props.options[0]
|
|
411
|
-
|
|
412
|
-
useEffect(() => {
|
|
413
|
-
if (!open) return undefined
|
|
414
|
-
const away = event => {
|
|
415
|
-
if (rootRef.current !== null && !rootRef.current.contains(event.target)) setOpen(false)
|
|
416
|
-
}
|
|
417
|
-
document.addEventListener("mousedown", away)
|
|
418
|
-
return () => document.removeEventListener("mousedown", away)
|
|
419
|
-
}, [open])
|
|
420
|
-
|
|
421
|
-
const commit = index => {
|
|
422
|
-
const option = props.options[index]
|
|
423
|
-
if (option === undefined) return
|
|
424
|
-
setOpen(false)
|
|
425
|
-
setActive(-1)
|
|
426
|
-
buttonRef.current?.focus()
|
|
427
|
-
if (option.value !== props.value) props.onChange(option.value)
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
const onKeyDown = event => {
|
|
431
|
-
if (event.key === "Escape") {
|
|
432
|
-
if (open) { event.preventDefault(); setOpen(false); buttonRef.current?.focus() }
|
|
433
|
-
return
|
|
434
|
-
}
|
|
435
|
-
if (!open && (event.key === "Enter" || event.key === " " || event.key === "ArrowDown")) {
|
|
436
|
-
event.preventDefault()
|
|
437
|
-
setOpen(true)
|
|
438
|
-
setActive(selected >= 0 ? selected : 0)
|
|
439
|
-
return
|
|
440
|
-
}
|
|
441
|
-
if (!open) return
|
|
442
|
-
const last = props.options.length - 1
|
|
443
|
-
if (event.key === "ArrowDown") { event.preventDefault(); setActive(a => Math.min(last, (a < 0 ? selected : a) + 1)) }
|
|
444
|
-
else if (event.key === "ArrowUp") { event.preventDefault(); setActive(a => Math.max(0, (a < 0 ? selected : a) - 1)) }
|
|
445
|
-
else if (event.key === "Home") { event.preventDefault(); setActive(0) }
|
|
446
|
-
else if (event.key === "End") { event.preventDefault(); setActive(last) }
|
|
447
|
-
else if (event.key === "Enter" || event.key === " ") { event.preventDefault(); commit(active < 0 ? selected : active) }
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
return h("div", { key: "s", className: "dsh-bb-dd", ref: rootRef }, [
|
|
451
|
-
h("button", {
|
|
452
|
-
key: "b",
|
|
453
|
-
type: "button",
|
|
454
|
-
ref: buttonRef,
|
|
455
|
-
className: "dsh-bb-dd-btn",
|
|
456
|
-
"aria-label": props.label + ": " + (current?.label ?? ""),
|
|
457
|
-
disabled: props.disabled,
|
|
458
|
-
"aria-haspopup": "listbox",
|
|
459
|
-
"aria-expanded": open ? "true" : "false",
|
|
460
|
-
onBlur: event => {
|
|
461
|
-
if (!rootRef.current?.contains(event.relatedTarget)) setOpen(false)
|
|
462
|
-
},
|
|
463
|
-
onClick: () => { setOpen(o => !o); setActive(-1) },
|
|
464
|
-
onKeyDown,
|
|
465
|
-
}, [
|
|
466
|
-
h("span", { key: "v" }, current === undefined ? "" : current.label),
|
|
467
|
-
h("span", { key: "c", className: "dsh-bb-dd-caret", "aria-hidden": "true" }, "\u25be"),
|
|
468
|
-
]),
|
|
469
|
-
open ? h("div", {
|
|
470
|
-
key: "l",
|
|
471
|
-
className: "dsh-bb-dd-list",
|
|
472
|
-
role: "listbox",
|
|
473
|
-
"aria-label": props.label,
|
|
474
|
-
}, props.options.map((option, index) => h("button", {
|
|
475
|
-
key: option.value,
|
|
476
|
-
type: "button",
|
|
477
|
-
className: "dsh-bb-dd-opt",
|
|
478
|
-
role: "option",
|
|
479
|
-
tabIndex: -1,
|
|
480
|
-
"aria-selected": option.value === props.value ? "true" : "false",
|
|
481
|
-
onMouseDown: event => event.preventDefault(),
|
|
482
|
-
"data-active": index === active ? "true" : "false",
|
|
483
|
-
onMouseEnter: () => setActive(index),
|
|
484
|
-
onClick: () => commit(index),
|
|
485
|
-
}, option.label))) : null,
|
|
486
|
-
])
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
/** One boolean switch bound to a settings path. */
|
|
490
|
-
function Toggle(props) {
|
|
491
|
-
const t = translate
|
|
492
|
-
return h("label", { style: styles.row, className: "dsh-bb-row dsh-bb-toggle" }, [
|
|
493
|
-
h("span", { key: "l", style: styles.label }, [
|
|
494
|
-
h("span", { key: "t" }, t(props.labelKey)),
|
|
495
|
-
props.hintKey ? h("span", { key: "h", style: styles.hint }, t(props.hintKey)) : null,
|
|
496
|
-
]),
|
|
497
|
-
h("input", {
|
|
498
|
-
key: "i",
|
|
499
|
-
type: "checkbox",
|
|
500
|
-
className: "dsh-bb-switch",
|
|
501
|
-
role: "switch",
|
|
502
|
-
"aria-label": t(props.labelKey),
|
|
503
|
-
checked: props.checked,
|
|
504
|
-
disabled: props.busy,
|
|
505
|
-
onChange: event => props.onChange(event.target.checked),
|
|
506
|
-
}),
|
|
507
|
-
])
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* Re-render this component when the interface language changes at run time.
|
|
512
|
-
*
|
|
513
|
-
* `translate` is a module-level binding that `apply()` re-binds on every locale snapshot, but
|
|
514
|
-
* React has no idea that happened: every label rendered so far keeps the language it was rendered
|
|
515
|
-
* in, which is exactly the defect the watch panel hit (#40) and the one commit `666cbff` fixed for
|
|
516
|
-
* that panel's DOM. The settings section is rendered by React, so it needs the notification rather
|
|
517
|
-
* than a text pass.
|
|
518
|
-
*/
|
|
519
|
-
let localeVersion = 0
|
|
520
|
-
const localeWatchers = new Set()
|
|
521
|
-
function useLocaleVersion() {
|
|
522
|
-
const [, setVersion] = useState(localeVersion)
|
|
523
|
-
useEffect(() => {
|
|
524
|
-
const update = () => setVersion(localeVersion)
|
|
525
|
-
localeWatchers.add(update)
|
|
526
|
-
return () => { localeWatchers.delete(update) }
|
|
527
|
-
}, [])
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
/**
|
|
531
|
-
* Readiness: can the browser serve a call right now, and what is missing if not.
|
|
532
|
-
*
|
|
533
|
-
* This is the "it works once you install it" promise, made visible. The bundled runtime downloads
|
|
534
|
-
* on first need (issue #41 moved the download out of `postinstall`), so on a fresh install the
|
|
535
|
-
* honest answer for the first minute is "a download is running" — a state that used to exist only
|
|
536
|
-
* in a log line. Everything shown here comes from `GET /runtime-status`; the button starts the
|
|
537
|
-
* same one background attempt the plugin makes on its own, which is why pressing it is never
|
|
538
|
-
* harmful and never starts a second download.
|
|
539
|
-
*/
|
|
540
|
-
const hostPatchNoticeEvent = "dsh-builtin-browser:host-patch-notice"
|
|
541
|
-
function readHostPatchNotice() {
|
|
542
|
-
try {
|
|
543
|
-
const saved = JSON.parse(sessionStorage.getItem(hostPatchNoticeEvent))
|
|
544
|
-
return saved?.page === performance.timeOrigin ? saved.key : ""
|
|
545
|
-
} catch { return "" /* Storage may be unavailable. */ }
|
|
546
|
-
}
|
|
547
|
-
function publishHostPatchNotice(key) {
|
|
548
|
-
try { sessionStorage.setItem(hostPatchNoticeEvent, JSON.stringify({ page: performance.timeOrigin, key })) }
|
|
549
|
-
catch { /* An open panel can still show the result without storage. */ }
|
|
550
|
-
if (typeof window !== "undefined") window.dispatchEvent(new CustomEvent(hostPatchNoticeEvent, { detail: key }))
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
function HostPatchControls() {
|
|
554
|
-
useLocaleVersion()
|
|
555
|
-
const t = translate
|
|
556
|
-
const [state, setState] = useState(null)
|
|
557
|
-
const [busy, setBusy] = useState(false)
|
|
558
|
-
const [error, setError] = useState("")
|
|
559
|
-
const [notice, setNotice] = useState(readHostPatchNotice)
|
|
560
|
-
const alive = useRef(true)
|
|
561
|
-
const pending = useRef(false)
|
|
562
|
-
useEffect(() => {
|
|
563
|
-
if (typeof window === "undefined") return
|
|
564
|
-
const target = window
|
|
565
|
-
const update = event => setNotice(event.detail)
|
|
566
|
-
target.addEventListener(hostPatchNoticeEvent, update)
|
|
567
|
-
return () => target.removeEventListener(hostPatchNoticeEvent, update)
|
|
568
|
-
}, [])
|
|
569
|
-
useEffect(() => {
|
|
570
|
-
alive.current = true
|
|
571
|
-
void fetch("/dsh-builtin-browser/host-patch-maintenance", { headers: { accept: "application/json" } })
|
|
572
|
-
.then(async response => {
|
|
573
|
-
if (response.status === 404) return
|
|
574
|
-
const data = await response.json()
|
|
575
|
-
if (!response.ok) throw new Error(data.error || `HTTP ${response.status}`)
|
|
576
|
-
if (alive.current && data.hostPatch?.surface === "web") setState(data.hostPatch)
|
|
577
|
-
}).catch(failure => { if (alive.current) setError(String(failure)) })
|
|
578
|
-
return () => { alive.current = false }
|
|
579
|
-
}, [])
|
|
580
|
-
const change = async action => {
|
|
581
|
-
if (pending.current) return
|
|
582
|
-
pending.current = true
|
|
583
|
-
setBusy(true); setError(""); setNotice(""); publishHostPatchNotice("")
|
|
584
|
-
try {
|
|
585
|
-
const response = await fetch("/dsh-builtin-browser/host-patch-maintenance", {
|
|
586
|
-
method: "POST", headers: { accept: "application/json", "content-type": "application/json" },
|
|
587
|
-
body: JSON.stringify({ action }),
|
|
588
|
-
})
|
|
589
|
-
const data = await response.json()
|
|
590
|
-
if (alive.current && data.hostPatch) setState(data.hostPatch)
|
|
591
|
-
if (!response.ok || data.ok !== true) throw new Error(data.error || data.hostPatch?.reason || `HTTP ${response.status}`)
|
|
592
|
-
const noticeKey = data.hostPatch.restartRequired ? "hostPatch.restart" : "hostPatch.reload"
|
|
593
|
-
publishHostPatchNotice(noticeKey)
|
|
594
|
-
if (alive.current) setNotice(noticeKey)
|
|
595
|
-
} catch (failure) { if (alive.current) setError(String(failure)) }
|
|
596
|
-
finally { pending.current = false; if (alive.current) setBusy(false) }
|
|
597
|
-
}
|
|
598
|
-
if (state === null && error === "") return null
|
|
599
|
-
return h("div", { key: "web-host-patch", style: styles.group }, [
|
|
600
|
-
h("p", { key: "state", role: "status" }, t("readiness.hostPatch") + (state ? ": " + t("readiness.hostPatch." + state.status.replaceAll(" ", "-")) : "")),
|
|
601
|
-
state?.reason ? h("p", { key: "reason", style: styles.hint }, state.reason) : null,
|
|
602
|
-
h("div", { key: "buttons", style: styles.row }, [
|
|
603
|
-
h("button", { key: "install", type: "button", style: styles.button, disabled: busy || !state?.canInstall, onClick: () => change("install") }, t(busy ? "hostPatch.working" : "hostPatch.install")),
|
|
604
|
-
h("button", { key: "restore", type: "button", style: styles.button, disabled: busy || !state?.canRestore, onClick: () => change("restore") }, t("hostPatch.restore")),
|
|
605
|
-
]),
|
|
606
|
-
notice ? h("p", { key: "notice", role: "status", style: styles.hint }, t(notice)) : null,
|
|
607
|
-
error ? h("p", { key: "error", role: "alert", style: styles.error }, error) : null,
|
|
608
|
-
])
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
function Readiness({ channel } = {}) {
|
|
612
|
-
useLocaleVersion()
|
|
613
|
-
const t = translate
|
|
614
|
-
const [runtime, setRuntime] = useState(null)
|
|
615
|
-
const [error, setError] = useState("")
|
|
616
|
-
const [unsupported, setUnsupported] = useState(false)
|
|
617
|
-
const [busy, setBusy] = useState(false)
|
|
618
|
-
const [bridgeBusy, setBridgeBusy] = useState(null)
|
|
619
|
-
const [bridgeJob, setBridgeJob] = useState(null)
|
|
620
|
-
const [bridgePollVersion, setBridgePollVersion] = useState(0)
|
|
621
|
-
const [bridgeError, setBridgeError] = useState(null)
|
|
622
|
-
const [extensionMessage, setExtensionMessage] = useState('')
|
|
623
|
-
const bridgePending = useRef(false)
|
|
624
|
-
const bridgeSubmitting = useRef(false)
|
|
625
|
-
const bridgeJobId = useRef(null)
|
|
626
|
-
const alive = useRef(true)
|
|
627
|
-
|
|
628
|
-
const read = useCallback(async () => {
|
|
629
|
-
try {
|
|
630
|
-
const response = await fetch(RUNTIME_STATUS_ROUTE, { headers: { accept: "application/json" } })
|
|
631
|
-
// A host that predates this route answers 404, and that is a version skew rather than a
|
|
632
|
-
// fault: after an update the client bundle is read at request time while the host's code is
|
|
633
|
-
// what started with the process. Rendering "could not read readiness: HTTP 404" at a user who
|
|
634
|
-
// simply has not restarted yet would be reporting the skew as their problem — so the section
|
|
635
|
-
// stays out of the way, exactly like a document with no `actions` section.
|
|
636
|
-
if (response.status === 404) {
|
|
637
|
-
if (alive.current) { setUnsupported(true); setRuntime(null); setError("") }
|
|
638
|
-
return null
|
|
639
|
-
}
|
|
640
|
-
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
641
|
-
const data = await response.json()
|
|
642
|
-
if (data.runtime?.bridge) {
|
|
643
|
-
const extensions = typeof window === "undefined" ? undefined : window.dshDesktop?.mainExtensions
|
|
644
|
-
if (typeof extensions?.status === "function") {
|
|
645
|
-
const status = await extensions.status("dsh-builtin-browser")
|
|
646
|
-
data.runtime.bridge = { ...data.runtime.bridge, mainExtension: status, code: status.code, command: undefined,
|
|
647
|
-
state: status.state === "loaded" ? "installed" : status.state === "not-installed" ? "missing" : "stale" }
|
|
648
|
-
} else if (!data.runtime.bridge.mainExtension) {
|
|
649
|
-
data.runtime.bridge = { ...data.runtime.bridge, code: "DESKTOP_MAIN_EXTENSION_UNSUPPORTED" }
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
if (!alive.current) return null
|
|
653
|
-
setUnsupported(false)
|
|
654
|
-
setRuntime(data && data.runtime ? data.runtime : null)
|
|
655
|
-
setError("")
|
|
656
|
-
return data && data.runtime ? data.runtime : null
|
|
657
|
-
} catch (failure) {
|
|
658
|
-
if (!alive.current) return null
|
|
659
|
-
setError(String(failure && failure.message ? failure.message : failure))
|
|
660
|
-
return null
|
|
661
|
-
}
|
|
662
|
-
}, [])
|
|
663
|
-
|
|
664
|
-
const bridgeActivePhases = ["armed", "closing", "installing", "restarting", "verifying"]
|
|
665
|
-
const bridgeActive = bridgeJob !== null && bridgeActivePhases.includes(bridgeJob.phase)
|
|
666
|
-
const readBridgeJob = useCallback(async () => {
|
|
667
|
-
try {
|
|
668
|
-
const response = await fetch("/dsh-builtin-browser/bridge-maintenance", { headers: { accept: "application/json" } })
|
|
669
|
-
if (!response.ok) return
|
|
670
|
-
const data = await response.json()
|
|
671
|
-
if (!alive.current || bridgeSubmitting.current || data.ok !== true || data.protocol !== 1 || !data.job || typeof data.job.id !== "string") return
|
|
672
|
-
if (bridgePending.current && bridgeJobId.current !== null && bridgeJobId.current !== data.job.id) return
|
|
673
|
-
bridgeJobId.current = data.job.id
|
|
674
|
-
bridgePending.current = ["armed", "closing", "installing", "restarting", "verifying"].includes(data.job.phase)
|
|
675
|
-
setBridgeJob(data.job)
|
|
676
|
-
if (data.job.phase === "completed") void read()
|
|
677
|
-
} catch { /* The desktop is briefly offline while maintenance restarts it. Keep its job. */ }
|
|
678
|
-
finally { if (alive.current) setBridgePollVersion(version => version + 1) }
|
|
679
|
-
}, [read])
|
|
680
|
-
|
|
681
|
-
useEffect(() => {
|
|
682
|
-
alive.current = true
|
|
683
|
-
void read()
|
|
684
|
-
void readBridgeJob()
|
|
685
|
-
return () => { alive.current = false }
|
|
686
|
-
}, [read, readBridgeJob, channel])
|
|
687
|
-
|
|
688
|
-
useEffect(() => {
|
|
689
|
-
if (!bridgeActive) return undefined
|
|
690
|
-
const timer = setTimeout(() => { void readBridgeJob() }, 1000)
|
|
691
|
-
return () => clearTimeout(timer)
|
|
692
|
-
}, [bridgeActive, bridgeJob, bridgePollVersion, readBridgeJob])
|
|
693
|
-
|
|
694
|
-
// Poll only while a download is running: that is the one state that changes on its own, and a
|
|
695
|
-
// poll in any other state would be a background request per panel per two seconds forever.
|
|
696
|
-
const preparing = runtime !== null && runtime.electron.state === "preparing"
|
|
697
|
-
useEffect(() => {
|
|
698
|
-
if (!preparing) return undefined
|
|
699
|
-
const timer = setTimeout(() => { void read() }, 2000)
|
|
700
|
-
return () => clearTimeout(timer)
|
|
701
|
-
}, [preparing, runtime, read])
|
|
702
|
-
|
|
703
|
-
const prepare = async () => {
|
|
704
|
-
setBusy(true)
|
|
705
|
-
setError("")
|
|
706
|
-
try {
|
|
707
|
-
const response = await fetch(RUNTIME_PROVISION_ROUTE, {
|
|
708
|
-
method: "POST",
|
|
709
|
-
headers: { accept: "application/json" },
|
|
710
|
-
})
|
|
711
|
-
const data = await response.json().catch(() => ({}))
|
|
712
|
-
if (!response.ok) throw new Error((data && data.error) || `HTTP ${response.status}`)
|
|
713
|
-
if (alive.current && data && data.runtime) setRuntime(data.runtime)
|
|
714
|
-
} catch (failure) {
|
|
715
|
-
if (alive.current) setError(String(failure && failure.message ? failure.message : failure))
|
|
716
|
-
} finally {
|
|
717
|
-
if (alive.current) setBusy(false)
|
|
718
|
-
void read()
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
const bridgeAction = async () => {
|
|
723
|
-
const action = "reinstall"
|
|
724
|
-
if (bridgePending.current || busy || bridgeActive) return
|
|
725
|
-
const desktopMenu = () => typeof document.querySelector === "function"
|
|
726
|
-
? document.querySelector("[data-windows-menu]")?.shadowRoot?.querySelector("button") : null
|
|
727
|
-
// Windows Desktop draws its own menu; macOS uses the native menu bar, so its Desktop preload is the proof.
|
|
728
|
-
const inDesktop = typeof desktopMenu()?.click === "function" || (globalThis.dshDesktop !== null && typeof globalThis.dshDesktop === "object")
|
|
729
|
-
if (!inDesktop) {
|
|
730
|
-
setBridgeError({ key: "readiness.bridge.localOnly" })
|
|
731
|
-
return
|
|
732
|
-
}
|
|
733
|
-
bridgePending.current = true
|
|
734
|
-
bridgeSubmitting.current = true
|
|
735
|
-
setBridgeBusy(action)
|
|
736
|
-
setBridgeJob(null)
|
|
737
|
-
setBridgeError(null)
|
|
738
|
-
let accepted = false
|
|
739
|
-
try {
|
|
740
|
-
const response = await fetch("/dsh-builtin-browser/bridge-maintenance", {
|
|
741
|
-
method: "POST",
|
|
742
|
-
headers: { accept: "application/json", "content-type": "application/json" },
|
|
743
|
-
body: JSON.stringify({ action, locale: currentLocale }),
|
|
744
|
-
})
|
|
745
|
-
const data = await response.json().catch(() => ({}))
|
|
746
|
-
if (response.status === 404) {
|
|
747
|
-
if (alive.current) setBridgeError({ key: "readiness.bridge.unsupported" })
|
|
748
|
-
return
|
|
749
|
-
}
|
|
750
|
-
if (!response.ok || data.ok !== true) throw new Error(data.error || data.output || `HTTP ${response.status}`)
|
|
751
|
-
if (data.protocol !== 1 || data.accepted !== true || typeof data.job?.id !== "string" || data.job.phase !== "armed" || data.job.action !== action) throw new Error("invalid bridge maintenance acknowledgement")
|
|
752
|
-
accepted = true
|
|
753
|
-
bridgeJobId.current = data.job.id
|
|
754
|
-
if (alive.current) setBridgeJob(data.job)
|
|
755
|
-
if (data.quit === "self") return
|
|
756
|
-
const menu = desktopMenu()
|
|
757
|
-
if (typeof menu?.click !== "function") throw new Error(t("readiness.bridge.localOnly"))
|
|
758
|
-
// The armed worker selects Exit in this official native menu. This opens that menu only
|
|
759
|
-
// after the new maintenance endpoint has acknowledged the handoff.
|
|
760
|
-
menu.click()
|
|
761
|
-
} catch (failure) {
|
|
762
|
-
if (alive.current) setBridgeError({ key: "readiness.bridge.actionFailed", detail: String(failure && failure.message ? failure.message : failure) })
|
|
763
|
-
} finally {
|
|
764
|
-
bridgeSubmitting.current = false
|
|
765
|
-
if (!accepted) bridgePending.current = false
|
|
766
|
-
if (alive.current) setBridgeBusy(null)
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
if (unsupported) return null
|
|
771
|
-
if (runtime === null) {
|
|
772
|
-
return h("div", { style: styles.wrap }, [
|
|
773
|
-
h("p", { key: "l", style: styles.lead }, error === "" ? t("readiness.loading") : `${t("readiness.failed")} ${error}`),
|
|
774
|
-
])
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
const tone = runtime.readiness === "ready" ? styles.badgeOk
|
|
778
|
-
: runtime.readiness === "blocked" ? styles.badgeWarn : styles.badgeUnknown
|
|
779
|
-
const row = (key, label, value) => [
|
|
780
|
-
h("span", { key: `${key}-k`, style: styles.kvKey }, label),
|
|
781
|
-
h("span", { key: `${key}-v`, style: styles.kvVal }, value),
|
|
782
|
-
]
|
|
783
|
-
// "Installed" and "running" are different facts, and the gap between them is the most common
|
|
784
|
-
// broken state there is (the desktop app is simply closed). The row says which one it means —
|
|
785
|
-
// and when the host does not report the running half at all, it says the plain truth rather
|
|
786
|
-
// than inferring "not running" from an absent field.
|
|
787
|
-
const bridgeLabel = runtime.bridge.state !== "installed"
|
|
788
|
-
? t(`readiness.bridge.${runtime.bridge.state}`)
|
|
789
|
-
: runtime.bridge.running === true
|
|
790
|
-
? t("readiness.bridge.installedRunning")
|
|
791
|
-
: runtime.bridge.running === false
|
|
792
|
-
? t("readiness.bridge.installedNotRunning")
|
|
793
|
-
: t("readiness.bridge.installed")
|
|
794
|
-
const resolvedCarrier = runtime.resolvedCarrier ?? (runtime.carrier === "auto"
|
|
795
|
-
? runtime.bridge.state === "installed" && runtime.bridge.running === true ? "sidebar"
|
|
796
|
-
: runtime.systemBrowser?.present === true ? "system" : "bundled"
|
|
797
|
-
: runtime.carrier)
|
|
798
|
-
const systemName = ({ chrome: "Chrome", edge: "Edge", brave: "Brave" })[runtime.systemBrowser?.kind ?? runtime.channel] ?? t("readiness.system")
|
|
799
|
-
const systemLabel = runtime.systemBrowser?.checked === true
|
|
800
|
-
? t(runtime.systemBrowser.present ? "readiness.status.systemReady" : "readiness.status.systemMissing").replace("{browser}", systemName)
|
|
801
|
-
: t("readiness.status.checkPending")
|
|
802
|
-
const extensionDisconnected = runtime.extension?.state === 'not-connected' || runtime.extension?.state === 'extension-missing'
|
|
803
|
-
const stateLabel = resolvedCarrier === "extension" ? extensionDisconnected ? t('extension.notConnected') : runtime.extension?.detail ?? t("readiness.state.blocked")
|
|
804
|
-
: resolvedCarrier === "system" || resolvedCarrier === "cdp" ? systemLabel
|
|
805
|
-
: resolvedCarrier === "sidebar"
|
|
806
|
-
? t(runtime.bridge.state === "installed"
|
|
807
|
-
? runtime.bridge.running === true ? "readiness.status.bridgeReady"
|
|
808
|
-
: runtime.bridge.running === false ? "readiness.status.bridgeStopped" : "readiness.status.bridgeInstalled"
|
|
809
|
-
: runtime.bridge.state === "stale" ? "readiness.status.bridgeStale"
|
|
810
|
-
: runtime.bridge.state === "missing" ? "readiness.status.bridgeMissing" : "readiness.status.desktopMissing")
|
|
811
|
-
: t(runtime.electron.state === "present" || runtime.electron.state === "ready" ? "readiness.status.bundledReady"
|
|
812
|
-
: runtime.electron.state === "preparing" ? "readiness.status.bundledPreparing"
|
|
813
|
-
: runtime.electron.state === "failed" ? "readiness.status.bundledFailed" : "readiness.status.bundledMissing")
|
|
814
|
-
const controlsBusy = busy || bridgeBusy !== null || bridgeActive
|
|
815
|
-
const extensionAction = async () => {
|
|
816
|
-
setBusy(true)
|
|
817
|
-
try {
|
|
818
|
-
const result = await requestExtensionSetup()
|
|
819
|
-
setExtensionMessage(t(result.connected ? 'extension.connected' : result.store ? 'extension.storeHint' : 'extension.loadHint'))
|
|
820
|
-
} catch (failure) { setExtensionMessage(String(failure.message ?? failure)) }
|
|
821
|
-
finally { setBusy(false); void read() }
|
|
822
|
-
}
|
|
823
|
-
const extensionButton = h("button", { key: "install-extension", type: "button", style: styles.button, disabled: controlsBusy, onClick: extensionAction }, t('extension.button'))
|
|
824
|
-
const canManageBridge = runtime.bridge.present === true && runtime.bridge.state !== "absent"
|
|
825
|
-
const extensionUnsupported = runtime.bridge.code === "DESKTOP_MAIN_EXTENSION_UNSUPPORTED"
|
|
826
|
-
const bridgeButtonBusy = bridgeBusy !== null || bridgeActive
|
|
827
|
-
const bridgeButtonStyle = controlsBusy || preparing ? { ...styles.button, cursor: "default", opacity: .6 } : styles.button
|
|
828
|
-
const bridgeJobError = typeof bridgeJob?.error === "string" ? bridgeJob.error : ""
|
|
829
|
-
const bridgeJobOutput = typeof bridgeJob?.output === "string" ? bridgeJob.output : ""
|
|
830
|
-
const bridgeJobDiagnostic = bridgeJobOutput !== "" && bridgeJobError.includes(bridgeJobOutput)
|
|
831
|
-
? bridgeJobError : [bridgeJobError, bridgeJobOutput].filter(Boolean).join("\n")
|
|
832
|
-
|
|
833
|
-
return h("div", { style: styles.group }, [
|
|
834
|
-
h("div", { key: "head", className: "dsh-bb-row", style: styles.row }, [
|
|
835
|
-
h("span", { key: "title" }, t("readiness.title")),
|
|
836
|
-
h("span", { key: "state", role: "status", style: { ...styles.badge, ...tone } }, stateLabel),
|
|
837
|
-
]),
|
|
838
|
-
runtime.extension ? h("div", { key: "extension" }, [
|
|
839
|
-
resolvedCarrier !== 'extension' && extensionDisconnected ? h('p', { key: 'fallback-hint', role: 'status', style: styles.hint }, t('extension.notConnected')) : null,
|
|
840
|
-
h("p", { key: "profile", role: "status", style: styles.hint }, [runtime.extension.browser, runtime.extension.profile, runtime.extension.connectionId, runtime.extension.state].filter(Boolean).join(" · ")),
|
|
841
|
-
h("p", { key: "quiet", style: styles.hint }, t("extension.quiet")),
|
|
842
|
-
h('p', { key: 'hint', style: styles.hint }, t('extension.loadHint')),
|
|
843
|
-
]) : null,
|
|
844
|
-
canManageBridge ? h("div", { key: "bridge-controls" }, [
|
|
845
|
-
extensionUnsupported ? h("p", { key: "extension-unsupported", role: "status", style: styles.hint }, t("readiness.bridge.extensionUnsupported"))
|
|
846
|
-
: runtime.bridge.mainExtension ? h("p", { key: "extension-status", role: "status", style: styles.hint },
|
|
847
|
-
`${t("readiness.bridge.extension." + runtime.bridge.mainExtension.state)}${runtime.bridge.mainExtension.version ? " · " + runtime.bridge.mainExtension.version : ""}${runtime.bridge.mainExtension.code ? " · " + runtime.bridge.mainExtension.code : ""}`) : null,
|
|
848
|
-
h("div", { key: "row", className: "dsh-bb-row", style: styles.row }, [
|
|
849
|
-
h("span", { key: "title" }, t("readiness.bridge")),
|
|
850
|
-
h("button", { key: "reinstall", type: "button", style: bridgeButtonStyle, disabled: controlsBusy || preparing, "aria-busy": bridgeButtonBusy ? "true" : undefined, onClick: bridgeAction }, t("readiness.bridge.reinstall")),
|
|
851
|
-
extensionButton,
|
|
852
|
-
]),
|
|
853
|
-
h("p", { key: "hint", role: bridgeBusy !== null || bridgeActive ? "status" : undefined, style: styles.hint }, t(bridgeBusy !== null ? "readiness.bridge.working" : bridgeActive ? "readiness.bridge.progressHint" : "readiness.bridge.maintenanceHint")),
|
|
854
|
-
]) : null,
|
|
855
|
-
!canManageBridge ? extensionButton : null,
|
|
856
|
-
extensionMessage ? h('p', { key: 'extension-message', role: 'status', style: styles.hint }, extensionMessage) : null,
|
|
857
|
-
h('p', { key: 'active-carrier', role: 'status', style: styles.hint }, [runtime.resolvedCarrier, runtime.controlledProfile, runtime.fallbackReason, runtime.extension?.registration?.detail].filter(Boolean).join(' · ')),
|
|
858
|
-
...Object.entries(runtime.nativeHostRegistration ?? {}).filter(([, status]) => !status.registered).map(([browser, status]) => h('p', { key: 'registration-' + browser, role: 'status', style: styles.hint }, browser + ': ' + status.detail)),
|
|
859
|
-
bridgeActive ? h("p", { key: "bridge-progress", role: "status", style: styles.hint }, t(`readiness.bridge.phase.${bridgeJob.phase}`)) : null,
|
|
860
|
-
bridgeJob?.phase === "completed" ? h("p", { key: "bridge-result", role: "status", style: styles.hint }, t("readiness.bridge.installedDone")) : null,
|
|
861
|
-
bridgeJob?.hostPatch ? h("p", { key: "host-patch", role: "status", style: styles.hint },
|
|
862
|
-
`${t("readiness.hostPatch")}: ${t("readiness.hostPatch." + bridgeJob.hostPatch.status.replaceAll(" ", "-"))}`) : null,
|
|
863
|
-
bridgeJob?.phase === "failed" || bridgeJob?.phase === "cancelled" ? h("p", { key: "bridge-job-error", role: "alert", style: styles.error }, t(`readiness.bridge.${bridgeJob.phase}`)) : null,
|
|
864
|
-
bridgeError !== null ? h("p", { key: "bridge-error", role: "alert", style: styles.error }, t(bridgeError.key)) : null,
|
|
865
|
-
runtime.bridge.state === "stale" ? h("p", { key: "bridge-compatibility-error", role: "alert", style: styles.error }, runtime.bridge.detail) : null,
|
|
866
|
-
h("details", { key: "diagnostics", className: "dsh-bb-diagnostics" }, [
|
|
867
|
-
h("summary", { key: "title", style: styles.hint }, t("readiness.details")),
|
|
868
|
-
h("div", { key: "kv", style: styles.kv }, [
|
|
869
|
-
...row("carrier", t("readiness.channel"), t(`readiness.carrier.${runtime.carrier}`)),
|
|
870
|
-
runtime.resolvedCarrier ? row("resolved-carrier", t("readiness.resolvedCarrier"), t(`readiness.carrier.${runtime.resolvedCarrier}`)) : null,
|
|
871
|
-
runtime.systemBrowser?.checked === true ? row("system", t("readiness.system"), systemLabel) : null,
|
|
872
|
-
...row("electron", t("readiness.electron"), t(`readiness.electron.${runtime.electron.state}`)),
|
|
873
|
-
...row("bridge", t("readiness.bridge"), bridgeLabel),
|
|
874
|
-
]),
|
|
875
|
-
runtime.systemBrowser?.path ? h("code", { key: "system-path", style: styles.mono }, runtime.systemBrowser.path) : null,
|
|
876
|
-
bridgeError?.detail ? h("code", { key: "bridge-error-detail", style: styles.mono }, bridgeError.detail) : null,
|
|
877
|
-
bridgeJobDiagnostic !== "" ? h("code", { key: "bridge-job-detail", style: styles.mono }, bridgeJobDiagnostic) : null,
|
|
878
|
-
runtime.electron.state === "failed" || runtime.electron.state === "skipped"
|
|
879
|
-
? h("p", { key: "edetail", style: styles.hint }, runtime.electron.detail) : null,
|
|
880
|
-
runtime.bridge.state === "installed" && runtime.bridge.running === false
|
|
881
|
-
? h("p", { key: "bdetail", style: styles.hint }, runtime.bridge.runningDetail ?? runtime.bridge.detail) : null,
|
|
882
|
-
runtime.bridge.command
|
|
883
|
-
? h("p", { key: "command", style: styles.hint }, [
|
|
884
|
-
h("span", { key: "label" }, t("readiness.fix")),
|
|
885
|
-
h("code", { key: "value", style: styles.mono }, runtime.bridge.command),
|
|
886
|
-
]) : null,
|
|
887
|
-
h("button", {
|
|
888
|
-
key: "recheck",
|
|
889
|
-
type: "button",
|
|
890
|
-
style: styles.button,
|
|
891
|
-
disabled: controlsBusy || preparing,
|
|
892
|
-
onClick: () => { void read() },
|
|
893
|
-
}, t("readiness.recheck")),
|
|
894
|
-
]),
|
|
895
|
-
runtime.canProvision || preparing
|
|
896
|
-
? h("div", { key: "buttons", style: styles.buttons }, [
|
|
897
|
-
preparing ? h("span", { key: "progress", role: "status", style: styles.hint }, t("readiness.preparing")) : null,
|
|
898
|
-
runtime.canProvision ? h("button", { key: "prepare", type: "button", style: styles.button, disabled: controlsBusy, onClick: () => { void prepare() } }, t("readiness.prepare")) : null,
|
|
899
|
-
]) : null,
|
|
900
|
-
error !== "" ? h("p", { key: "error", role: "alert", style: styles.error }, t("readiness.failed") + " " + error) : null,
|
|
901
|
-
])
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
/** Save the delivery fields together so moving focus never writes a partial template. */
|
|
905
|
-
function DeliverySettings({ delivery, busy, onSave }) {
|
|
906
|
-
const t = translate
|
|
907
|
-
const [invalid, setInvalid] = useState(false)
|
|
908
|
-
const toolPattern = /^[A-Za-z0-9_.-]+$/
|
|
909
|
-
const submit = event => {
|
|
910
|
-
event.preventDefault()
|
|
911
|
-
const fields = event.currentTarget.elements
|
|
912
|
-
const tool = fields.namedItem("tool").value.trim()
|
|
913
|
-
const onFail = fields.namedItem("onFail").value
|
|
914
|
-
const rules = fields.namedItem("sites").value.split("\n").filter(line => line.trim() !== "")
|
|
915
|
-
const entries = rules.map(line => line.split("=").map(value => value.trim()))
|
|
916
|
-
let args
|
|
917
|
-
try {
|
|
918
|
-
args = JSON.parse(fields.namedItem("args").value)
|
|
919
|
-
} catch {
|
|
920
|
-
setInvalid(true)
|
|
921
|
-
return
|
|
922
|
-
}
|
|
923
|
-
if ((tool !== "" && !toolPattern.test(tool))
|
|
924
|
-
|| args === null || typeof args !== "object" || Array.isArray(args)
|
|
925
|
-
|| Object.values(args).some(value => typeof value !== "string")
|
|
926
|
-
|| entries.some(entry => entry.length !== 2 || !/^[A-Za-z0-9.-]+$/.test(entry[0]) || !toolPattern.test(entry[1]))) {
|
|
927
|
-
setInvalid(true)
|
|
928
|
-
return
|
|
929
|
-
}
|
|
930
|
-
const sites = Object.fromEntries(entries.map(([host, name]) => [host.toLowerCase(), name]))
|
|
931
|
-
if (Object.keys(sites).length !== entries.length) {
|
|
932
|
-
setInvalid(true)
|
|
933
|
-
return
|
|
934
|
-
}
|
|
935
|
-
setInvalid(false)
|
|
936
|
-
onSave({ tool, args, onFail, sites })
|
|
937
|
-
}
|
|
938
|
-
const field = (name, control) => h("label", { key: name, style: styles.label }, [
|
|
939
|
-
h("span", { key: "label" }, t("delivery." + name)),
|
|
940
|
-
control,
|
|
941
|
-
name === "args" ? h("span", { key: "hint", style: styles.hint }, t("delivery.args.hint")) : null,
|
|
942
|
-
])
|
|
943
|
-
return h("form", { onSubmit: submit }, [
|
|
944
|
-
h("fieldset", { key: "fields", disabled: busy, style: { border: 0, margin: 0, padding: 0, display: "grid", gap: "10px" } }, [
|
|
945
|
-
field("tool", h("input", { key: "control", name: "tool", className: "dsh-bb-input", defaultValue: delivery?.tool ?? "", placeholder: "lark_drive_upload" })),
|
|
946
|
-
field("args", h("textarea", { key: "control", name: "args", className: "dsh-bb-input", rows: 3, defaultValue: JSON.stringify(delivery?.args ?? { file_path: "{path}" }, null, 2) })),
|
|
947
|
-
field("onFail", h("select", { key: "control", name: "onFail", className: "dsh-bb-input", defaultValue: delivery?.onFail ?? "keep-local" }, [
|
|
948
|
-
h("option", { key: "keep", value: "keep-local" }, t("delivery.onFail.keep")),
|
|
949
|
-
h("option", { key: "stop", value: "stop" }, t("delivery.onFail.stop")),
|
|
950
|
-
])),
|
|
951
|
-
field("sites", h("textarea", { key: "control", name: "sites", className: "dsh-bb-input", rows: 3, defaultValue: Object.entries(delivery?.sites ?? {}).map(([host, tool]) => host + "=" + tool).join("\n") })),
|
|
952
|
-
h("div", { key: "actions" }, h("button", { type: "submit", style: styles.button }, t("delivery.save"))),
|
|
953
|
-
]),
|
|
954
|
-
invalid ? h("p", { key: "error", role: "alert", style: styles.error }, t("delivery.invalid")) : null,
|
|
955
|
-
])
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
/** The settings page section. */
|
|
959
|
-
/**
|
|
960
|
-
* The references section: what was selected in a page earlier, and the way back.
|
|
961
|
-
*
|
|
962
|
-
* It lists and reveals only. A capture starts from the page — the assistant's
|
|
963
|
-
* tool, or a browser menu once one exists — because a selection lives in the
|
|
964
|
-
* page, not in this panel. A host without the reference routes makes the list
|
|
965
|
-
* request fail, and the section then renders nothing, exactly like a settings
|
|
966
|
-
* row an older host does not serve.
|
|
967
|
-
*/
|
|
968
|
-
function References(props) {
|
|
969
|
-
useLocaleVersion()
|
|
970
|
-
const t = translate
|
|
971
|
-
const [rows, setRows] = useState([])
|
|
972
|
-
const [status, setStatus] = useState("loading")
|
|
973
|
-
const [pending, setPending] = useState("")
|
|
974
|
-
const [outcome, setOutcome] = useState(null)
|
|
975
|
-
const [exporting, setExporting] = useState("")
|
|
976
|
-
const [importing, setImporting] = useState(false)
|
|
977
|
-
const [importNote, setImportNote] = useState("")
|
|
978
|
-
const fileInput = useRef(null)
|
|
979
|
-
const alive = useRef(true)
|
|
980
|
-
const loadRevision = useRef(0)
|
|
981
|
-
|
|
982
|
-
useEffect(() => {
|
|
983
|
-
alive.current = true
|
|
984
|
-
return () => { alive.current = false; loadRevision.current += 1 }
|
|
985
|
-
}, [])
|
|
986
|
-
|
|
987
|
-
const load = useCallback(() => {
|
|
988
|
-
const revision = ++loadRevision.current
|
|
989
|
-
setStatus("loading")
|
|
990
|
-
fetch("/dsh-builtin-browser/reference/list?limit=10", { headers: { accept: "application/json" } })
|
|
991
|
-
.then(response => response.ok ? response.json() : Promise.reject(new Error(`HTTP ${response.status}`)))
|
|
992
|
-
.then(data => {
|
|
993
|
-
if (!alive.current || loadRevision.current !== revision) return
|
|
994
|
-
setRows(Array.isArray(data.references) ? data.references : [])
|
|
995
|
-
setStatus("ready")
|
|
996
|
-
})
|
|
997
|
-
.catch(() => { if (alive.current && loadRevision.current === revision) setStatus("failed") })
|
|
998
|
-
}, [])
|
|
999
|
-
useEffect(() => { load() }, [load])
|
|
1000
|
-
|
|
1001
|
-
const label = state => {
|
|
1002
|
-
if (state === "revealed") return t("refs.revealed")
|
|
1003
|
-
if (state === "ambiguous") return t("refs.ambiguous")
|
|
1004
|
-
if (state === "missing") return t("refs.missing")
|
|
1005
|
-
if (state === "page-mismatch") return t("refs.pageMismatch")
|
|
1006
|
-
if (state === "session-unavailable") return t("refs.sessionUnavailable")
|
|
1007
|
-
if (state === "not-found") return t("refs.notFound")
|
|
1008
|
-
if (state === "added") return t("refs.added")
|
|
1009
|
-
if (state === "addFailed") return t("refs.addFailed")
|
|
1010
|
-
if (state === "removed") return t("refs.removed")
|
|
1011
|
-
if (state === "removeFailed") return t("refs.removeFailed")
|
|
1012
|
-
return t("refs.failed")
|
|
1013
|
-
}
|
|
1014
|
-
const reveal = referenceId => {
|
|
1015
|
-
setPending(referenceId)
|
|
1016
|
-
setOutcome(null)
|
|
1017
|
-
fetch(REFERENCE_REVEAL_ROUTE, {
|
|
1018
|
-
method: "POST",
|
|
1019
|
-
headers: { "content-type": "application/json" },
|
|
1020
|
-
body: JSON.stringify({ referenceId }),
|
|
1021
|
-
}).then(async response => {
|
|
1022
|
-
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
1023
|
-
return response.json()
|
|
1024
|
-
})
|
|
1025
|
-
.then(data => { if (alive.current) setOutcome({ referenceId, status: data.status || "unavailable" }) })
|
|
1026
|
-
.catch(() => { if (alive.current) setOutcome({ referenceId, status: "failed" }) })
|
|
1027
|
-
.finally(() => { if (alive.current) setPending("") })
|
|
1028
|
-
}
|
|
1029
|
-
const exportAs = format => {
|
|
1030
|
-
setExporting(format)
|
|
1031
|
-
setOutcome(null)
|
|
1032
|
-
fetch(`/dsh-builtin-browser/reference/export?format=${encodeURIComponent(format)}`, { headers: { accept: "*/*" } })
|
|
1033
|
-
.then(async response => {
|
|
1034
|
-
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
1035
|
-
const blob = await response.blob()
|
|
1036
|
-
if (!alive.current) return
|
|
1037
|
-
const disposition = response.headers.get("content-disposition") || ""
|
|
1038
|
-
const named = /filename="([^"]+)"/.exec(disposition)
|
|
1039
|
-
const fallback = { jsonl: "browser-references.jsonl", markdown: "browser-references.md", zip: "browser-references.zip" }[format] || "browser-references.zip"
|
|
1040
|
-
const url = URL.createObjectURL(blob)
|
|
1041
|
-
const link = document.createElement("a")
|
|
1042
|
-
link.href = url
|
|
1043
|
-
link.download = named ? named[1] : fallback
|
|
1044
|
-
link.click()
|
|
1045
|
-
setTimeout(() => URL.revokeObjectURL(url), 0)
|
|
1046
|
-
})
|
|
1047
|
-
.catch(() => { if (alive.current) setOutcome({ referenceId: "", status: "failed" }) })
|
|
1048
|
-
.finally(() => { if (alive.current) setExporting("") })
|
|
1049
|
-
}
|
|
1050
|
-
/**
|
|
1051
|
-
* Restore a `format=zip` export. The route re-verifies every hash and reports per-record
|
|
1052
|
-
* rejections; a partial import is shown as such rather than as a clean success.
|
|
1053
|
-
* @param file - the user-picked archive.
|
|
1054
|
-
*/
|
|
1055
|
-
const importFrom = file => {
|
|
1056
|
-
if (!file) return
|
|
1057
|
-
setImporting(true)
|
|
1058
|
-
setImportNote("")
|
|
1059
|
-
setOutcome(null)
|
|
1060
|
-
fetch(REFERENCE_IMPORT_ROUTE, {
|
|
1061
|
-
method: "POST",
|
|
1062
|
-
headers: { "content-type": "application/zip" },
|
|
1063
|
-
body: file,
|
|
1064
|
-
})
|
|
1065
|
-
.then(async response => {
|
|
1066
|
-
const data = await response.json().catch(() => ({}))
|
|
1067
|
-
if (!response.ok || data.ok !== true) throw new Error(String(data.error || `HTTP ${response.status}`))
|
|
1068
|
-
return data
|
|
1069
|
-
})
|
|
1070
|
-
.then(data => {
|
|
1071
|
-
if (!alive.current) return
|
|
1072
|
-
const rejected = Array.isArray(data.rejected) ? data.rejected.length : 0
|
|
1073
|
-
setImportNote(`${t("refs.importDone")} ${String(data.added)}/${String(data.references)}`
|
|
1074
|
-
+ (rejected > 0 ? ` · ${String(rejected)} ${t("refs.importPartial")}` : ""))
|
|
1075
|
-
load()
|
|
1076
|
-
})
|
|
1077
|
-
.catch(() => { if (alive.current) setImportNote(t("refs.importFailed")) })
|
|
1078
|
-
.finally(() => {
|
|
1079
|
-
if (!alive.current) return
|
|
1080
|
-
setImporting(false)
|
|
1081
|
-
if (fileInput.current) fileInput.current.value = ""
|
|
1082
|
-
})
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
/**
|
|
1086
|
-
* "Add to conversation" feeds the durable delivery queue; the DSH client
|
|
1087
|
-
* drains that queue into the real draft. The record itself is untouched, so
|
|
1088
|
-
* a failed add can be retried without re-capturing the page.
|
|
1089
|
-
*/
|
|
1090
|
-
const postDelivery = (path, body, okStatus, failStatus, referenceId) => {
|
|
1091
|
-
setPending(referenceId)
|
|
1092
|
-
setOutcome(null)
|
|
1093
|
-
fetch(path, {
|
|
1094
|
-
method: "POST",
|
|
1095
|
-
headers: { "content-type": "application/json" },
|
|
1096
|
-
body: JSON.stringify(body),
|
|
1097
|
-
})
|
|
1098
|
-
.then(async response => ({ ok: response.ok, data: await response.json().catch(() => ({})) }))
|
|
1099
|
-
.then(({ ok, data }) => {
|
|
1100
|
-
if (alive.current) setOutcome({ referenceId, status: ok && data.ok !== false ? okStatus : failStatus })
|
|
1101
|
-
})
|
|
1102
|
-
.catch(() => { if (alive.current) setOutcome({ referenceId, status: failStatus }) })
|
|
1103
|
-
.finally(() => { if (alive.current) setPending("") })
|
|
1104
|
-
}
|
|
1105
|
-
const addToDraft = referenceId => postDelivery(
|
|
1106
|
-
REFERENCE_INSERT_ROUTE, { referenceId }, "added", "addFailed", referenceId,
|
|
1107
|
-
)
|
|
1108
|
-
const removeFromDraft = referenceId => postDelivery(
|
|
1109
|
-
REFERENCE_DELIVERY_REMOVE_ROUTE, { referenceId }, "removed", "removeFailed", referenceId,
|
|
1110
|
-
)
|
|
1111
|
-
const withActions = props && props.withActions === true
|
|
1112
|
-
|
|
1113
|
-
const transferring = exporting !== "" || importing
|
|
1114
|
-
const sourceLabel = url => {
|
|
1115
|
-
try { return new URL(url).host } catch { return "" }
|
|
1116
|
-
}
|
|
1117
|
-
const preview = item => (Array.isArray(item.parts) ? item.parts : []).map(part =>
|
|
1118
|
-
part.type === "image" ? `${t("refs.image")}${part.preview ? ` · ${part.preview}` : ""}`
|
|
1119
|
-
: part.type === "table" ? `${t("refs.table")}${part.preview ? ` · ${part.preview}` : ""}`
|
|
1120
|
-
: String(part.preview || "")).filter(Boolean).join(" · ")
|
|
1121
|
-
|
|
1122
|
-
return h("details", { style: styles.group, className: "dsh-bb-references" }, [
|
|
1123
|
-
h("summary", { key: "head", style: { ...styles.groupTitle, fontWeight: 500 } }, [
|
|
1124
|
-
t("refs.title"),
|
|
1125
|
-
rows.length > 0 ? h("span", { key: "count", className: "dsh-bb-ref-count" }, `${rows.length} ${t("refs.records")}`) : null,
|
|
1126
|
-
]),
|
|
1127
|
-
h("div", { key: "toolbar", className: "dsh-bb-ref-toolbar" }, [
|
|
1128
|
-
h("button", { key: "refresh", type: "button", style: styles.button, disabled: status === "loading", onClick: load }, t("refs.refresh")),
|
|
1129
|
-
]),
|
|
1130
|
-
status === "failed" ? h("p", { key: "error", role: "alert", style: styles.error }, t("refs.loadFailed")) : null,
|
|
1131
|
-
status === "loading" && rows.length === 0 ? h("p", { key: "loading", role: "status", style: styles.hint }, t("refs.reading")) : null,
|
|
1132
|
-
status === "ready" && rows.length === 0 ? h("p", { key: "empty", style: styles.hint }, t("refs.empty")) : null,
|
|
1133
|
-
h("ul", { key: "list", className: "dsh-bb-ref-list", "aria-busy": status === "loading" }, rows.map(item => h("li", {
|
|
1134
|
-
key: item.referenceId, className: "dsh-bb-ref-item",
|
|
1135
|
-
}, [
|
|
1136
|
-
h("div", { key: "text", className: "dsh-bb-ref-content" }, [
|
|
1137
|
-
h("span", { key: "title", className: "dsh-bb-ref-title", title: item.title || item.pageUrl }, item.title || sourceLabel(item.pageUrl) || t("refs.untitled")),
|
|
1138
|
-
preview(item) ? h("p", { key: "preview", className: "dsh-bb-ref-preview" }, preview(item)) : null,
|
|
1139
|
-
h("div", { key: "meta", className: "dsh-bb-ref-meta" }, [
|
|
1140
|
-
h("span", { key: "source", className: "dsh-bb-ref-source", title: item.pageUrl }, sourceLabel(item.pageUrl)),
|
|
1141
|
-
h("time", { key: "date", dateTime: item.capturedAt }, new Date(item.capturedAt).toLocaleDateString(currentLocale === "en" ? "en" : "zh-CN")),
|
|
1142
|
-
h("span", { key: "parts" }, `${item.partCount} ${t("refs.parts")}`),
|
|
1143
|
-
]),
|
|
1144
|
-
outcome !== null && outcome.referenceId === item.referenceId
|
|
1145
|
-
? h("p", { key: "outcome", role: "status", className: "dsh-bb-ref-outcome", style: outcome.status === "revealed" || outcome.status === "added" || outcome.status === "removed" ? styles.hint : styles.error }, label(outcome.status))
|
|
1146
|
-
: null,
|
|
1147
|
-
]),
|
|
1148
|
-
h("div", { key: "actions", className: "dsh-bb-ref-actions" }, [
|
|
1149
|
-
withActions ? h("button", {
|
|
1150
|
-
key: "add", type: "button", style: styles.button,
|
|
1151
|
-
disabled: pending !== "", onClick: () => addToDraft(item.referenceId),
|
|
1152
|
-
}, t("refs.addToDraft")) : null,
|
|
1153
|
-
withActions ? h("button", {
|
|
1154
|
-
key: "remove", type: "button", style: styles.button,
|
|
1155
|
-
disabled: pending !== "", onClick: () => removeFromDraft(item.referenceId),
|
|
1156
|
-
}, t("refs.remove")) : null,
|
|
1157
|
-
h("button", {
|
|
1158
|
-
key: "reveal", type: "button", style: styles.button,
|
|
1159
|
-
disabled: pending !== "", onClick: () => reveal(item.referenceId),
|
|
1160
|
-
"aria-label": `${t("refs.reveal")} · ${item.title || sourceLabel(item.pageUrl)}`,
|
|
1161
|
-
}, pending === item.referenceId ? t("refs.loading") : t("refs.reveal")),
|
|
1162
|
-
]),
|
|
1163
|
-
]))),
|
|
1164
|
-
h("details", { key: "transfer", className: "dsh-bb-ref-transfer" }, [
|
|
1165
|
-
h("summary", { key: "label", style: styles.hint }, t("refs.transfer")),
|
|
1166
|
-
h("div", { key: "exports", className: "dsh-bb-ref-transfer-actions" }, [
|
|
1167
|
-
...["jsonl", "markdown", "zip"].map(format => h("button", {
|
|
1168
|
-
key: format,
|
|
1169
|
-
type: "button",
|
|
1170
|
-
style: styles.button,
|
|
1171
|
-
disabled: transferring,
|
|
1172
|
-
onClick: () => exportAs(format),
|
|
1173
|
-
}, `${t("refs.export")} ${t(format === "jsonl" ? "refs.exportJsonl" : format === "markdown" ? "refs.exportMarkdown" : "refs.exportZip")}`)),
|
|
1174
|
-
]),
|
|
1175
|
-
h("div", { key: "imports", className: "dsh-bb-ref-transfer-actions" }, [
|
|
1176
|
-
h("input", {
|
|
1177
|
-
key: "file",
|
|
1178
|
-
type: "file",
|
|
1179
|
-
accept: ".zip,application/zip",
|
|
1180
|
-
ref: fileInput,
|
|
1181
|
-
style: { display: "none" },
|
|
1182
|
-
onChange: event => importFrom(event.target.files && event.target.files[0]),
|
|
1183
|
-
}),
|
|
1184
|
-
h("button", {
|
|
1185
|
-
key: "importButton",
|
|
1186
|
-
type: "button",
|
|
1187
|
-
style: styles.button,
|
|
1188
|
-
disabled: transferring,
|
|
1189
|
-
onClick: () => { if (fileInput.current) fileInput.current.click() },
|
|
1190
|
-
}, importing ? t("refs.importBusy") : t("refs.import")),
|
|
1191
|
-
]),
|
|
1192
|
-
]),
|
|
1193
|
-
importNote !== "" ? h("p", { key: "importNote", role: "status", style: styles.hint }, importNote) : null,
|
|
1194
|
-
outcome !== null && outcome.referenceId === "" ? h("p", { key: "transfer-error", role: "alert", style: styles.error }, t("refs.failed")) : null,
|
|
1195
|
-
])
|
|
1196
|
-
}
|
|
1197
|
-
|
|
1198
|
-
/**
|
|
1199
|
-
* The record list is kept for the test seam only. The user-facing entry was
|
|
1200
|
-
* removed: the conversation input now renders one card per reference, so a
|
|
1201
|
-
* separate aggregate history menu duplicated the same content.
|
|
1202
|
-
*/
|
|
1203
|
-
function SettingsRoot() {
|
|
1204
|
-
useLocaleVersion()
|
|
1205
|
-
const t = translate
|
|
1206
|
-
const [rawSettings, setSettings] = useState(null)
|
|
1207
|
-
const [meta, setMeta] = useState({ path: "" })
|
|
1208
|
-
const [error, setError] = useState("")
|
|
1209
|
-
const [busy, setBusy] = useState(false)
|
|
1210
|
-
const [saved, setSaved] = useState(false)
|
|
1211
|
-
const saving = useRef(false)
|
|
1212
|
-
const savedTimer = useRef(null)
|
|
1213
|
-
const alive = useRef(true)
|
|
1214
|
-
|
|
1215
|
-
const load = useCallback(() => {
|
|
1216
|
-
setError("")
|
|
1217
|
-
callSettings().then(data => {
|
|
1218
|
-
if (!alive.current) return
|
|
1219
|
-
setSettings(data.settings)
|
|
1220
|
-
setMeta({ path: data.path || "" })
|
|
1221
|
-
}).catch(failure => { if (alive.current) setError(String(failure && failure.message ? failure.message : failure)) })
|
|
1222
|
-
}, [])
|
|
1223
|
-
|
|
1224
|
-
useEffect(() => {
|
|
1225
|
-
alive.current = true
|
|
1226
|
-
load()
|
|
1227
|
-
return () => { alive.current = false }
|
|
1228
|
-
}, [load])
|
|
1229
|
-
useEffect(() => () => clearTimeout(savedTimer.current), [])
|
|
1230
|
-
|
|
1231
|
-
const patch = useCallback(next => {
|
|
1232
|
-
if (saving.current) return
|
|
1233
|
-
saving.current = true
|
|
1234
|
-
clearTimeout(savedTimer.current)
|
|
1235
|
-
setSaved(false)
|
|
1236
|
-
setBusy(true)
|
|
1237
|
-
setError("")
|
|
1238
|
-
callSettings(next).then(data => {
|
|
1239
|
-
if (!alive.current) return
|
|
1240
|
-
setSettings(data.settings)
|
|
1241
|
-
setSaved(true)
|
|
1242
|
-
savedTimer.current = setTimeout(() => setSaved(false), 1800)
|
|
1243
|
-
}).catch(failure => { if (alive.current) setError(String(failure && failure.message ? failure.message : failure)) })
|
|
1244
|
-
.finally(() => {
|
|
1245
|
-
saving.current = false
|
|
1246
|
-
if (alive.current) setBusy(false)
|
|
1247
|
-
})
|
|
1248
|
-
}, [])
|
|
1249
|
-
|
|
1250
|
-
if (rawSettings === null) {
|
|
1251
|
-
return h("div", { style: styles.wrap }, [
|
|
1252
|
-
error === "" ? h("p", { key: "l", role: "status", style: styles.lead }, t("loading")) : null,
|
|
1253
|
-
error !== "" ? h("p", { key: "e", style: styles.error }, `${t("failed")} ${error}`) : null,
|
|
1254
|
-
error !== "" ? h("button", { key: "retry", type: "button", style: styles.button, onClick: load }, t("retry")) : null,
|
|
1255
|
-
])
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
// A document served by an OLDER host has no `actions` section — which is exactly the state
|
|
1259
|
-
// an update leaves behind when the host has not been restarted yet (the client bundle is
|
|
1260
|
-
// read at request time, the host's code at startup). Rendering `settings.actions.allowExecute`
|
|
1261
|
-
// off that threw, and the throw took the whole panel with it: the section did not merely show
|
|
1262
|
-
// stale values, it refused to open. Fill the gap with the defaults an older host behaves by,
|
|
1263
|
-
// which is also the honest reading — it has no such switch, so "on" is what it does.
|
|
1264
|
-
const settings = rawSettings.actions === undefined
|
|
1265
|
-
? { ...rawSettings, actions: { allowExecute: true, allowDownload: true, allowCredentialWrite: true } }
|
|
1266
|
-
: rawSettings
|
|
1267
|
-
|
|
1268
|
-
const toggle = (group, key, labelKey = group + "." + key, hintKey) => h(Toggle, {
|
|
1269
|
-
key,
|
|
1270
|
-
labelKey,
|
|
1271
|
-
hintKey,
|
|
1272
|
-
checked: settings[group]?.[key] ?? (group === "cookies" && key === "persist"),
|
|
1273
|
-
busy,
|
|
1274
|
-
onChange: value => patch({ [group]: { [key]: value } }),
|
|
1275
|
-
})
|
|
1276
|
-
const selector = (labelKey, value, options, onChange, hintKey) => h("div", {
|
|
1277
|
-
key: labelKey,
|
|
1278
|
-
className: "dsh-bb-row",
|
|
1279
|
-
style: styles.row,
|
|
1280
|
-
}, [
|
|
1281
|
-
h("span", { key: "text", style: styles.label }, [
|
|
1282
|
-
h("span", { key: "label" }, t(labelKey)),
|
|
1283
|
-
hintKey ? h("span", { key: "hint", style: styles.hint }, t(hintKey)) : null,
|
|
1284
|
-
]),
|
|
1285
|
-
h(Dropdown, { key: "select", label: t(labelKey), value, options, disabled: busy, onChange }),
|
|
1286
|
-
])
|
|
1287
|
-
const options = (prefix, values) => values.map(value => ({ value, label: t(prefix + value) }))
|
|
1288
|
-
const section = (titleKey, children) => h("section", { key: titleKey, style: styles.group }, [
|
|
1289
|
-
h("h3", { key: "title", style: styles.groupTitle }, t(titleKey)),
|
|
1290
|
-
...children,
|
|
1291
|
-
])
|
|
1292
|
-
const systemBrowser = ["chrome", "edge"].includes(settings.browser.channel)
|
|
1293
|
-
|
|
1294
|
-
return h("div", { style: styles.wrap, className: "dsh-bb-settings" }, [
|
|
1295
|
-
selector("browser.channel", settings.browser.channel,
|
|
1296
|
-
options("browser.", ["bundled", "sidebar", "auto", "chrome", "edge"]),
|
|
1297
|
-
channel => patch({ browser: { channel } })),
|
|
1298
|
-
systemBrowser ? selector("browser.systemProfile", settings.browser.systemProfile ?? "plugin",
|
|
1299
|
-
options("browser.mode.", ["plugin", "user"]), systemProfile => patch({ browser: { systemProfile } })) : null,
|
|
1300
|
-
h(Readiness, { key: "readiness-" + settings.browser.channel + "-" + settings.browser.systemProfile, channel: settings.browser.channel }),
|
|
1301
|
-
h(HostPatchControls, { key: "host-patch" }),
|
|
1302
|
-
section("ui.title", [
|
|
1303
|
-
toggle("ui", "quiet", "ui.quiet", "ui.quiet.hint"),
|
|
1304
|
-
toggle("ui", "autoExpandOnce"),
|
|
1305
|
-
toggle("ui", "closeWithSession"),
|
|
1306
|
-
toggle("ui", "virtualCursor"),
|
|
1307
|
-
toggle("remoteView", "enabled", "remoteView.enabled", "remoteView.enabled.hint"),
|
|
1308
|
-
]),
|
|
1309
|
-
section("actions.title", [
|
|
1310
|
-
toggle("actions", "allowExecute"),
|
|
1311
|
-
toggle("actions", "allowDownload"),
|
|
1312
|
-
toggle("credentials", "allowRead"),
|
|
1313
|
-
toggle("actions", "allowCredentialWrite", "actions.allowCredentialWrite", "actions.allowCredentialWrite.hint"),
|
|
1314
|
-
]),
|
|
1315
|
-
h("details", { key: "advanced", style: styles.group }, [
|
|
1316
|
-
h("summary", { key: "title", style: styles.groupTitle }, t("settings.advanced")),
|
|
1317
|
-
toggle("history", "enabled"),
|
|
1318
|
-
selector("vision.strategy", settings.vision.strategy, [
|
|
1319
|
-
{ value: "auto", label: t("vision.auto") },
|
|
1320
|
-
{ value: "nonVisual", label: t("vision.nonVisual") },
|
|
1321
|
-
], strategy => patch({ vision: { strategy } })),
|
|
1322
|
-
systemBrowser && settings.browser.systemProfile !== "user" ? toggle("cookies", "persist", "browser.profile", "browser.profile.hint") : null,
|
|
1323
|
-
systemBrowser && settings.browser.systemProfile !== "user" ? selector("browser.headless", settings.browser.headless ?? "auto",
|
|
1324
|
-
options("browser.headless.", ["auto", "windowed", "headless"]),
|
|
1325
|
-
headless => patch({ browser: { headless } }), "browser.headless.hint") : null,
|
|
1326
|
-
settings.delivery ? section("delivery.title", [
|
|
1327
|
-
h(DeliverySettings, {
|
|
1328
|
-
key: JSON.stringify(settings.delivery),
|
|
1329
|
-
delivery: settings.delivery,
|
|
1330
|
-
busy,
|
|
1331
|
-
onSave: delivery => patch({ delivery }),
|
|
1332
|
-
}),
|
|
1333
|
-
]) : null,
|
|
1334
|
-
meta.path !== "" ? h("p", { key: "path", style: styles.pathLine }, t("settings.details") + " · " + meta.path) : null,
|
|
1335
|
-
]),
|
|
1336
|
-
h("div", { key: "status", style: styles.status, role: "status" }, [
|
|
1337
|
-
busy || saved ? h("span", { key: "s" }, t(busy ? "settings.saving" : "saved")) : null,
|
|
1338
|
-
error !== "" ? h("span", { key: "e", style: styles.error }, ` ${t("failed")} ${error} `) : null,
|
|
1339
|
-
error !== "" ? h("button", { key: "r", type: "button", style: styles.button, onClick: load }, t("retry")) : null,
|
|
1340
|
-
]),
|
|
1341
|
-
])
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
|
-
// ===========================================================================
|
|
1345
|
-
// Conversation panel service: the one place a sidebar panel is opened.
|
|
1346
|
-
//
|
|
1347
|
-
// The shell mounts one right sidebar per conversation, and DSH's own sidebar
|
|
1348
|
-
// browser keeps that conversation's tabs and its webview guest inside it.
|
|
1349
|
-
// `ctx.sidebarRight.openTab` acts on the conversation the shell is SHOWING
|
|
1350
|
-
// (`mounted`), so every path that simulated a shortcut or clicked a card put
|
|
1351
|
-
// the page into whichever conversation the human happened to be reading —
|
|
1352
|
-
// that is the cross-conversation bleed, and it is a property of the path, not
|
|
1353
|
-
// an accident of it.
|
|
1354
|
-
//
|
|
1355
|
-
// `openTabIn(sessionId, …)` is the same navigation aimed at a NAMED
|
|
1356
|
-
// conversation, and it works for one that is not on screen. This service is
|
|
1357
|
-
// the only caller; the plugin's host half reaches it by evaluating
|
|
1358
|
-
// `globalThis.__dshBuiltinBrowser.openPanel(...)` inside the shell window, so
|
|
1359
|
-
// no input event, no key dispatch and no element click is involved.
|
|
1360
|
-
//
|
|
1361
|
-
// Guest identity is read from the panel's own `<webview>` and only inside the
|
|
1362
|
-
// subtree found for THAT conversation — never from the first match in the
|
|
1363
|
-
// document, which belongs to somebody else's panel.
|
|
1364
|
-
// ===========================================================================
|
|
1365
|
-
|
|
1366
|
-
/** The conversation a sidebar element belongs to, read off its React fiber. */
|
|
1367
|
-
function sessionIdOfElement(element) {
|
|
1368
|
-
const key = Object.keys(element).find(
|
|
1369
|
-
name => name.startsWith("__reactFiber$") || name.startsWith("__reactInternalInstance$"),
|
|
1370
|
-
)
|
|
1371
|
-
if (key === undefined) return null
|
|
1372
|
-
let fiber = element[key]
|
|
1373
|
-
let depth = 0
|
|
1374
|
-
while (fiber !== null && fiber !== undefined && depth < 60) {
|
|
1375
|
-
const props = fiber.memoizedProps
|
|
1376
|
-
if (props !== null && typeof props === "object" && typeof props.sessionId === "string") return props.sessionId
|
|
1377
|
-
fiber = fiber.return
|
|
1378
|
-
depth += 1
|
|
1379
|
-
}
|
|
1380
|
-
return null
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
/**
|
|
1384
|
-
* This conversation's own sidebar strip, or null when the shell has not mounted it.
|
|
1385
|
-
*
|
|
1386
|
-
* Its presence is the precondition `openTabIn` needs: it is minted together with the
|
|
1387
|
-
* conversation's surface store, and a call for a conversation whose store was never
|
|
1388
|
-
* minted silently does nothing. Detecting it here turns that silence into a reason
|
|
1389
|
-
* the caller can report, instead of a page that never appears.
|
|
1390
|
-
*/
|
|
1391
|
-
function tabStripFor(sessionId) {
|
|
1392
|
-
for (const strip of Array.from(document.querySelectorAll("[class*=_tabStrip]"))) {
|
|
1393
|
-
if (sessionIdOfElement(strip) === sessionId) return strip
|
|
1394
|
-
}
|
|
1395
|
-
return null
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
/** rc.5 marks both SessionView and its nested SidebarPanel, including floating panes. */
|
|
1399
|
-
function panelRootsFor(sessionId) {
|
|
1400
|
-
const roots = Array.from(document.querySelectorAll("[data-sidebar-right-session]"))
|
|
1401
|
-
// Only shells without DOM ownership markers may use the legacy React adapter.
|
|
1402
|
-
return roots.length === 0 ? undefined : roots.filter(root => root.getAttribute("data-sidebar-right-session") === sessionId)
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
/**
|
|
1406
|
-
* Every live `<webview>` guest inside this conversation's panel subtree.
|
|
1407
|
-
*
|
|
1408
|
-
* The walk up stops the moment an ancestor carries ANOTHER conversation's sidebar, and that stop
|
|
1409
|
-
* condition is the whole point of this function. The shell mounts every conversation's panel in
|
|
1410
|
-
* the same document — hidden ones included — so one step too far lands on a subtree that holds
|
|
1411
|
-
* all of them, and the first guest found there belongs to whichever conversation the shell
|
|
1412
|
-
* happens to render first. Measured: a GitHub login page opened in a different conversation was
|
|
1413
|
-
* reported as this one's guest, which is the cross-conversation bleed this service exists to
|
|
1414
|
-
* prevent. A sibling strip is the exact, class-name-independent signature of having stepped
|
|
1415
|
-
* outside; a conversation may legitimately own more than one strip of its own, so the test is
|
|
1416
|
-
* "is there one that is NOT mine", never a count.
|
|
1417
|
-
*/
|
|
1418
|
-
function guestsInPanel(sessionId) {
|
|
1419
|
-
const roots = panelRootsFor(sessionId)
|
|
1420
|
-
if (roots !== undefined) {
|
|
1421
|
-
// The nested markers can enumerate a guest twice. Its closest owner must still
|
|
1422
|
-
// name this session, so an embedded foreign session never enters the result.
|
|
1423
|
-
return Array.from(new Set(roots.flatMap(root => Array.from(root.querySelectorAll("webview"))))).filter(view => {
|
|
1424
|
-
try {
|
|
1425
|
-
return roots.includes(view.closest("[data-sidebar-right-session]"))
|
|
1426
|
-
&& typeof view.getWebContentsId === "function" && view.getWebContentsId() > 0
|
|
1427
|
-
} catch { return false }
|
|
1428
|
-
})
|
|
1429
|
-
}
|
|
1430
|
-
const strip = tabStripFor(sessionId)
|
|
1431
|
-
if (strip === null) return []
|
|
1432
|
-
// Start at the strip itself: it is by construction this conversation's own, so the foreign test
|
|
1433
|
-
// below cannot trip on it, and a shell that renders the guest as a sibling of the strip is
|
|
1434
|
-
// still reached.
|
|
1435
|
-
let node = strip
|
|
1436
|
-
while (node !== null && node !== undefined && node !== document.body) {
|
|
1437
|
-
const foreign = Array.from(node.querySelectorAll("[class*=_tabStrip]"))
|
|
1438
|
-
.some(el => sessionIdOfElement(el) !== sessionId)
|
|
1439
|
-
if (foreign) break
|
|
1440
|
-
const found = Array.from(node.querySelectorAll("webview")).filter(view => {
|
|
1441
|
-
try { return typeof view.getWebContentsId === "function" && view.getWebContentsId() > 0 }
|
|
1442
|
-
catch (error) { return false }
|
|
1443
|
-
})
|
|
1444
|
-
if (found.length > 0) return found
|
|
1445
|
-
node = node.parentElement
|
|
1446
|
-
}
|
|
1447
|
-
return []
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
/** Read this conversation's current guest, preferring the one actually drawn. */
|
|
1451
|
-
function guestStateFor(sessionId, tabId, initializationReader) {
|
|
1452
|
-
const roots = panelRootsFor(sessionId)
|
|
1453
|
-
if (roots === undefined ? tabStripFor(sessionId) === null : roots.length === 0) return { panel: false, guestId: null, url: "" }
|
|
1454
|
-
if (globalThis.dshDesktop?.browser?.nativeViews?.protocolVersion === 1 && typeof tabId === "string") {
|
|
1455
|
-
const page = initializationReader?.current({ sessionId, tabId })
|
|
1456
|
-
return { panel: true, guestId: page?.guestId ?? null, url: page?.url ?? "", ...page?.generation === undefined ? {} : { nativeState: page } }
|
|
1457
|
-
}
|
|
1458
|
-
const guests = guestsInPanel(sessionId).filter(view => tabId === undefined
|
|
1459
|
-
|| tabIdOfElement(view, new Set([tabId]), roots) === tabId)
|
|
1460
|
-
if (guests.length === 0) return { panel: true, guestId: null, url: "" }
|
|
1461
|
-
// A sidebar keeps every tab mounted (`keepMounted`), so a background tab's guest is
|
|
1462
|
-
// in the tree too. Prefer the one with a drawn box; fall back to the newest.
|
|
1463
|
-
const drawn = guests.find(view => {
|
|
1464
|
-
const rect = view.getBoundingClientRect()
|
|
1465
|
-
return rect.width > 0 && rect.height > 0
|
|
1466
|
-
})
|
|
1467
|
-
const chosen = drawn === undefined ? guests[guests.length - 1] : drawn
|
|
1468
|
-
let url = ""
|
|
1469
|
-
try { url = String(chosen.getURL ? chosen.getURL() : "") } catch (error) { url = "" }
|
|
1470
|
-
try { return { panel: true, guestId: chosen.getWebContentsId(), url } }
|
|
1471
|
-
catch (error) { return { panel: true, guestId: null, url: "" } }
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
/** Resolve a shell tab by its stable id, never by the page's displayed title. */
|
|
1475
|
-
function tabIdOfElement(element, allowed, roots) {
|
|
1476
|
-
if (roots !== undefined) {
|
|
1477
|
-
const owner = element.closest("[data-sidebar-right-session]")
|
|
1478
|
-
if (!roots.includes(owner)) return null
|
|
1479
|
-
let id = null
|
|
1480
|
-
for (let node = element; node && node !== owner; node = node.parentElement) {
|
|
1481
|
-
for (const value of [node.getAttribute("data-sidebar-right-tab"), node.getAttribute("data-dockkit-tab")]) {
|
|
1482
|
-
if (value === null) continue
|
|
1483
|
-
if (id !== null && id !== value) return null
|
|
1484
|
-
id = value
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
return allowed.has(id) ? id : null
|
|
1488
|
-
}
|
|
1489
|
-
const key = Object.keys(element).find(name => name.startsWith("__reactFiber$") || name.startsWith("__reactInternalInstance$"))
|
|
1490
|
-
let fiber = key === undefined ? null : element[key]
|
|
1491
|
-
for (let depth = 0; fiber && depth < 60; depth += 1, fiber = fiber.return) {
|
|
1492
|
-
const props = fiber.memoizedProps
|
|
1493
|
-
if (!props || typeof props !== "object") continue
|
|
1494
|
-
for (const id of [props.tabId, props.tab && props.tab.id]) {
|
|
1495
|
-
if (typeof id === "string" && allowed.has(id)) return id
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
return null
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
/**
|
|
1502
|
-
* Publish the service every host-side panel request goes through.
|
|
1503
|
-
*
|
|
1504
|
-
* The binding is separate from the publication so the API exists from the first
|
|
1505
|
-
* apply — a request arriving before `sidebarRight` is ready gets a named reason
|
|
1506
|
-
* rather than a missing global, which is indistinguishable from a bridge that
|
|
1507
|
-
* never loaded.
|
|
1508
|
-
*/
|
|
1509
|
-
function installPanelService(ctx) {
|
|
1510
|
-
let sidebarRight = null
|
|
1511
|
-
let initializationReader = null
|
|
1512
|
-
const pendingTabs = new Map()
|
|
1513
|
-
const renderingHolds = new Map()
|
|
1514
|
-
function releaseRendering(token) {
|
|
1515
|
-
const hold = renderingHolds.get(token)
|
|
1516
|
-
if (hold === undefined) return
|
|
1517
|
-
renderingHolds.delete(token)
|
|
1518
|
-
clearTimeout(hold.timer)
|
|
1519
|
-
hold.release()
|
|
1520
|
-
}
|
|
1521
|
-
function releaseAllRendering() {
|
|
1522
|
-
for (const token of renderingHolds.keys()) releaseRendering(token)
|
|
1523
|
-
}
|
|
1524
|
-
function hasRenderingHold(sessionId) {
|
|
1525
|
-
return Array.from(renderingHolds.values()).some(hold => hold.sessionId === sessionId)
|
|
1526
|
-
}
|
|
1527
|
-
const initializing = new Map()
|
|
1528
|
-
/** The shell's own navigation service: `openSession` is how it is asked to DISPLAY a conversation. */
|
|
1529
|
-
let uiWorkspace = null
|
|
1530
|
-
// `inject` is how a client plugin waits for a service to appear. A host that does not offer it
|
|
1531
|
-
// — an older composition, or a harness that mounted this bundle for its settings panel alone —
|
|
1532
|
-
// must still get the panel, so the wait is skipped and the published API names the missing
|
|
1533
|
-
// service when it is called. Failing the whole apply here would take the settings panel down
|
|
1534
|
-
// with it, which is exactly the shape of regression this file has been bitten by before.
|
|
1535
|
-
if (typeof ctx.inject === "function") {
|
|
1536
|
-
ctx.inject(["sidebarBrowserInitialization"], (scope) => {
|
|
1537
|
-
const reader = scope.sidebarBrowserInitialization
|
|
1538
|
-
if (reader?.protocolVersion !== 1 || typeof reader.read !== "function") return
|
|
1539
|
-
initializationReader = reader
|
|
1540
|
-
scope.effect(() => () => {
|
|
1541
|
-
if (initializationReader === reader) initializationReader = null
|
|
1542
|
-
}, "dsh-builtin-browser: initialization receipt reader")
|
|
1543
|
-
})
|
|
1544
|
-
ctx.inject(["sidebarRight"], (scope) => {
|
|
1545
|
-
if (sidebarRight !== scope.sidebarRight) {
|
|
1546
|
-
releaseAllRendering()
|
|
1547
|
-
pendingTabs.clear()
|
|
1548
|
-
}
|
|
1549
|
-
sidebarRight = scope.sidebarRight
|
|
1550
|
-
scope.effect(() => () => {
|
|
1551
|
-
if (sidebarRight === scope.sidebarRight) {
|
|
1552
|
-
releaseAllRendering()
|
|
1553
|
-
sidebarRight = null
|
|
1554
|
-
pendingTabs.clear()
|
|
1555
|
-
for (const transaction of initializing.values()) transaction.controller.abort(new Error("the sidebar service was released"))
|
|
1556
|
-
initializing.clear()
|
|
1557
|
-
}
|
|
1558
|
-
}, "dsh-builtin-browser: conversation panel binding")
|
|
1559
|
-
})
|
|
1560
|
-
// A separate inject, deliberately: waiting for both services in one call would take the
|
|
1561
|
-
// panel down on a host that has the sidebar but not the workspace service (an older
|
|
1562
|
-
// composition), and the panel is the part that must keep working.
|
|
1563
|
-
ctx.inject(["uiWorkspace"], (scope) => {
|
|
1564
|
-
uiWorkspace = scope.uiWorkspace
|
|
1565
|
-
scope.effect(() => () => {
|
|
1566
|
-
if (uiWorkspace === scope.uiWorkspace) uiWorkspace = null
|
|
1567
|
-
}, "dsh-builtin-browser: workspace binding")
|
|
1568
|
-
})
|
|
1569
|
-
}
|
|
1570
|
-
/**
|
|
1571
|
-
* Place a tool-opened page into the Web sidebar.
|
|
1572
|
-
*
|
|
1573
|
-
* The desktop shell is told to place a tab through the bridge; the Web shell has no such channel, so
|
|
1574
|
-
* a page opened by a tool stayed inside the plugin's own browser while the panel showed nothing.
|
|
1575
|
-
* The host keeps the last open request in one slot; this poll turns it into a sidebar tab, which is
|
|
1576
|
-
* what makes "open it" a single call again.
|
|
1577
|
-
*/
|
|
1578
|
-
/**
|
|
1579
|
-
* Which surface this shell should drive.
|
|
1580
|
-
*
|
|
1581
|
-
* Default "panel": the sidebar is the browsing surface. Appending ?browser-surface=builtin to the DSH
|
|
1582
|
-
* URL switches this window to the built-in browser for debugging DSH itself — no restart, no settings
|
|
1583
|
-
* file, and it cannot affect another window.
|
|
1584
|
-
* @returns the surface to declare.
|
|
1585
|
-
*/
|
|
1586
|
-
function declaredSurface() {
|
|
1587
|
-
try {
|
|
1588
|
-
const wanted = new URLSearchParams(location.search).get("browser-surface")
|
|
1589
|
-
return wanted === "builtin" ? "builtin" : "panel"
|
|
1590
|
-
} catch { return "panel" }
|
|
1591
|
-
}
|
|
1592
|
-
/**
|
|
1593
|
-
* 已经摆放过的 open 记录时间戳。
|
|
1594
|
-
*
|
|
1595
|
-
* 这份状态以前只在内存里,**刷新页面即归零**:宿主那边仍留着上一次 open 记录,于是页面一刷新就把
|
|
1596
|
-
* 用户已经关掉的侧栏与网页重新打开。写进 sessionStorage 后,同一次浏览会话内的刷新不会再重放;
|
|
1597
|
-
* 换新标签页也不会因为宿主里那条旧记录而凭空冒出侧栏。
|
|
1598
|
-
* @returns 已处理过的最晚 open 时间(毫秒)。
|
|
1599
|
-
*/
|
|
1600
|
-
let lastOpenHandled = (() => {
|
|
1601
|
-
try {
|
|
1602
|
-
const raw = sessionStorage.getItem("dsh-builtin-browser:last-open-handled")
|
|
1603
|
-
const value = raw === null ? 0 : Number(raw)
|
|
1604
|
-
return Number.isFinite(value) ? value : 0
|
|
1605
|
-
} catch { return 0 }
|
|
1606
|
-
})()
|
|
1607
|
-
|
|
1608
|
-
/**
|
|
1609
|
-
* 记住已处理的 open,供刷新后继续沿用。
|
|
1610
|
-
* @param at - 该条 open 记录的时间戳(毫秒)。
|
|
1611
|
-
*/
|
|
1612
|
-
function rememberOpenHandled(at) {
|
|
1613
|
-
lastOpenHandled = at
|
|
1614
|
-
try { sessionStorage.setItem("dsh-builtin-browser:last-open-handled", String(at)) } catch { /* 隐私模式忽略 */ }
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
function drainOpenRequest() {
|
|
1618
|
-
const sessionId = guestSession()
|
|
1619
|
-
if (typeof sessionId !== "string" || sessionId === "") return
|
|
1620
|
-
fetch("/dsh-builtin-browser/browser/open-request", { headers: { accept: "application/json" } })
|
|
1621
|
-
.then(response => (response.ok ? response.json() : undefined))
|
|
1622
|
-
.then(body => {
|
|
1623
|
-
const open = body && body.open
|
|
1624
|
-
if (!open || typeof open.url !== "string" || typeof open.at !== "number") return
|
|
1625
|
-
if (typeof open.owner === "string" && open.owner.replace(/^session-/, "") !== sessionId) return
|
|
1626
|
-
// Only act when the HOST says it is in panel mode. A host that predates the single-surface
|
|
1627
|
-
// switch still opens its own browser for every call, so placing a tab here as well produced TWO
|
|
1628
|
-
// live views of one page (the reported double-open). No echo, no tab.
|
|
1629
|
-
if (body.surface !== "panel") return
|
|
1630
|
-
if (open.at <= lastOpenHandled) return
|
|
1631
|
-
const frame = document.querySelector('iframe[data-sidebar-browser-frame]')
|
|
1632
|
-
const already = frame !== null && decodeURIComponent(frame.getAttribute("src") || "").includes(encodeURIComponent(open.url).slice(0, 24))
|
|
1633
|
-
if (already) { rememberOpenHandled(open.at); return }
|
|
1634
|
-
rememberOpenHandled(open.at)
|
|
1635
|
-
const api = globalThis.__dshBuiltinBrowser
|
|
1636
|
-
if (api && typeof api.openPanel === "function") api.openPanel("session-" + sessionId, open.url)
|
|
1637
|
-
})
|
|
1638
|
-
.catch(() => {})
|
|
1639
|
-
}
|
|
1640
|
-
// 轮询节奏:页面不可见时完全不发请求,回来时立刻补一次。
|
|
1641
|
-
// Web 端没有宿主→客户端的推送通道(桌面端有 bridge),这条「工具打开了某页」的通知只能由客户端来问;
|
|
1642
|
-
// 但没必要在后台标签页里一直问:DSH 自身常驻,一个隐藏窗口每秒一次的请求纯属浪费。
|
|
1643
|
-
if (typeof setInterval === "function") setInterval(() => {
|
|
1644
|
-
if (typeof document !== "undefined" && document.visibilityState === "hidden") return
|
|
1645
|
-
drainOpenRequest()
|
|
1646
|
-
}, 2000)
|
|
1647
|
-
if (typeof document !== "undefined" && typeof document.addEventListener === "function") {
|
|
1648
|
-
document.addEventListener("visibilitychange", () => {
|
|
1649
|
-
if (document.visibilityState !== "hidden") drainOpenRequest()
|
|
1650
|
-
})
|
|
1651
|
-
}
|
|
1652
|
-
/**
|
|
1653
|
-
* The conversation a proxied guest should attribute its quote to.
|
|
1654
|
-
*
|
|
1655
|
-
* \`screen()\` is empty for a brand-new conversation, but the shell already stamps the Session on its
|
|
1656
|
-
* own DOM; without this fallback the FIRST reference of a fresh conversation was silently dropped.
|
|
1657
|
-
* @returns the session id, or null when the shell exposes none.
|
|
1658
|
-
*/
|
|
1659
|
-
function guestSession() {
|
|
1660
|
-
const normalise = (value) => (value.startsWith("session-") ? value.slice(8) : value)
|
|
1661
|
-
const direct = onScreenSession()
|
|
1662
|
-
if (typeof direct === "string" && direct !== "") return normalise(direct)
|
|
1663
|
-
try {
|
|
1664
|
-
const node = document.querySelector("[data-sidebar-right-session], [data-conversation-session]")
|
|
1665
|
-
const stamped = node === null ? null
|
|
1666
|
-
: node.getAttribute("data-sidebar-right-session") ?? node.getAttribute("data-conversation-session")
|
|
1667
|
-
// The shell stamps its DOM with a "session-<uuid>" prefix; the host's own registry (and the
|
|
1668
|
-
// capture route) key on the bare id, and an un-stripped value is refused as session-unavailable.
|
|
1669
|
-
if (typeof stamped === "string" && stamped !== "") return normalise(stamped)
|
|
1670
|
-
} catch { /* no DOM */ }
|
|
1671
|
-
return null
|
|
1672
|
-
}
|
|
1673
|
-
function onScreenSession() {
|
|
1674
|
-
try {
|
|
1675
|
-
const screen = sidebarRight === null || typeof sidebarRight.screen !== "function" ? undefined : sidebarRight.screen()
|
|
1676
|
-
return screen !== undefined && screen !== null && typeof screen.sessionId === "string" ? screen.sessionId : null
|
|
1677
|
-
} catch (error) {
|
|
1678
|
-
return null
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
|
|
1682
|
-
/** Display the owner of an explicit open request, including an already mounted hidden guest. */
|
|
1683
|
-
function claimConversation(sessionId) {
|
|
1684
|
-
if (hasRenderingHold(sessionId)) return false
|
|
1685
|
-
if (uiWorkspace === null || typeof uiWorkspace.openSession !== "function") return false
|
|
1686
|
-
// Already displayed? Then the shell needs no navigation: the panel simply has not been opened
|
|
1687
|
-
// yet, and `revealPlacedPanel` opens it. Re-opening the conversation a human is reading would
|
|
1688
|
-
// be a no-op at best and a view reset at worst.
|
|
1689
|
-
if (onScreenSession() === sessionId) return false
|
|
1690
|
-
try {
|
|
1691
|
-
uiWorkspace.openSession(sessionId)
|
|
1692
|
-
return true
|
|
1693
|
-
} catch (error) {
|
|
1694
|
-
return false
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
|
|
1698
|
-
/**
|
|
1699
|
-
* Make a page that has been PLACED actually appear: expand the column, focus its tab.
|
|
1700
|
-
*
|
|
1701
|
-
* A placed tab is not a shown page. The shell renders the body of the ACTIVE tab, and only
|
|
1702
|
-
* while the column is expanded. A collapsed column keeps the strip — so the read side still
|
|
1703
|
-
* reports `panel: true` — while no `<webview>` is ever created, and every guest read comes
|
|
1704
|
-
* back empty. That is the state that used to sit here for 20 s and then get reported as an
|
|
1705
|
-
* unusable panel: measured on the running shell as `panel: true`, `guestId: null` in the
|
|
1706
|
-
* renderer and `sidebar: []` from the bridge, with no carrier-side step that could have
|
|
1707
|
-
* fixed it, because nobody had ever asked the column to open.
|
|
1708
|
-
*
|
|
1709
|
-
* Both calls are layout commands on a conversation's own surface store — no input event, no
|
|
1710
|
-
* key dispatch, no element click. Two guards keep them from touching a conversation the
|
|
1711
|
-
* human is not reading:
|
|
1712
|
-
* - only when `screen()` names THIS conversation. `screen()` is the shell's own answer to
|
|
1713
|
-
* "which conversation is displayed", and `toggleExpanded` acts on exactly that one, so
|
|
1714
|
-
* without this check an expand could fold the column a human is reading. A conversation
|
|
1715
|
-
* that is displayed but was never opened (a fresh window has no right sidebar at all until
|
|
1716
|
-
* something asks for it) passes this check — that case is why the DOM alone is not enough;
|
|
1717
|
-
* - `focus` is scoped by the shell itself (a tab outside the mounted surface is ignored),
|
|
1718
|
-
* so passing it a tab id from another conversation's list cannot move that view.
|
|
1719
|
-
*
|
|
1720
|
-
* @param sessionId - the conversation whose page was just placed.
|
|
1721
|
-
* A live guest may remain mounted while its column is folded, so it still needs this step.
|
|
1722
|
-
* @returns what was asked for, so a caller can tell "expanded" from "already visible", and
|
|
1723
|
-
* `displayed` so it can tell "the shell is showing this conversation" from "it is not".
|
|
1724
|
-
*/
|
|
1725
|
-
function revealPlacedPanel(sessionId, tabId) {
|
|
1726
|
-
if (sidebarRight === null) return {}
|
|
1727
|
-
const done = {}
|
|
1728
|
-
// Which conversation is the shell DISPLAYING? `screen()` answers it, and it is the question
|
|
1729
|
-
// that decides whether an expand call is safe: `toggleExpanded()` acts on the on-screen
|
|
1730
|
-
// session, so calling it for any other conversation would fold the column a human is reading.
|
|
1731
|
-
//
|
|
1732
|
-
// It also separates two states that the DOM alone cannot:
|
|
1733
|
-
// - this conversation is displayed but its column has never been opened (a fresh window
|
|
1734
|
-
// starts with no right sidebar at all) — expand, and the panel mounts;
|
|
1735
|
-
// - another conversation is displayed — nothing here may touch the column; the claim step
|
|
1736
|
-
// is what moves the shell, and the caller retries one render later.
|
|
1737
|
-
let onScreen = null
|
|
1738
|
-
try {
|
|
1739
|
-
onScreen = onScreenSession()
|
|
1740
|
-
} catch (error) {
|
|
1741
|
-
onScreen = null
|
|
1742
|
-
}
|
|
1743
|
-
if (onScreen !== sessionId) {
|
|
1744
|
-
done.displayed = false
|
|
1745
|
-
return done
|
|
1746
|
-
}
|
|
1747
|
-
done.displayed = true
|
|
1748
|
-
// Expansion happens before any screen() verdict: a side panel that was never opened has no
|
|
1749
|
-
// column to match, and bailing early there is exactly what left the page in a floating window.
|
|
1750
|
-
try {
|
|
1751
|
-
if (typeof sidebarRight.isExpanded === "function" && typeof sidebarRight.toggleExpanded === "function") {
|
|
1752
|
-
// `isExpanded()` is false both for "folded" and for "never opened". Both want the same
|
|
1753
|
-
// thing here, and `screen()` above has already established that the column being toggled
|
|
1754
|
-
// is THIS conversation's, so expanding cannot touch anybody else's.
|
|
1755
|
-
if (sidebarRight.isExpanded() === false) {
|
|
1756
|
-
sidebarRight.toggleExpanded()
|
|
1757
|
-
done.expanded = true
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
} catch (error) {
|
|
1761
|
-
done.expandError = String(error?.message ?? error)
|
|
1762
|
-
}
|
|
1763
|
-
try {
|
|
1764
|
-
const tabs = typeof sidebarRight.tabsIn === "function" ? sidebarRight.tabsIn(sessionId) : []
|
|
1765
|
-
const page = Array.isArray(tabs) ? tabs.find(entry => entry !== null && typeof entry === "object" && entry.kind === "browser" && entry.id === tabId) : undefined
|
|
1766
|
-
if (page !== undefined && typeof sidebarRight.focus === "function") {
|
|
1767
|
-
sidebarRight.focus(page.id)
|
|
1768
|
-
done.focused = String(page.id)
|
|
1769
|
-
}
|
|
1770
|
-
} catch (error) {
|
|
1771
|
-
done.focusError = String(error?.message ?? error)
|
|
1772
|
-
}
|
|
1773
|
-
return done
|
|
1774
|
-
}
|
|
1775
|
-
|
|
1776
|
-
function viewKey(sessionId, viewId) {
|
|
1777
|
-
return JSON.stringify([sessionId, viewId])
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
/**
|
|
1781
|
-
* Aim an already placed tab at one address through the shell's own
|
|
1782
|
-
* navigation face. This is the only way a bound tab showing the start page
|
|
1783
|
-
* can acquire a guest: the tab exists, but its body has never navigated.
|
|
1784
|
-
* @returns true when the shell accepted the target.
|
|
1785
|
-
*/
|
|
1786
|
-
function navigatePlacedTab(sessionId, tabId, address) {
|
|
1787
|
-
try {
|
|
1788
|
-
if (typeof sidebarRight.navigateTabIn === "function") {
|
|
1789
|
-
return sidebarRight.navigateTabIn(sessionId, tabId, { params: { url: address } }) === true
|
|
1790
|
-
}
|
|
1791
|
-
const tab = Array.from(sidebarRight.tabsIn(sessionId)).find(tab => tab.id === tabId && tab.kind === "browser")
|
|
1792
|
-
if (typeof tab?.contentId === "string" && typeof sidebarRight.tabDomain?.navigate === "function") {
|
|
1793
|
-
sidebarRight.tabDomain.navigate(sessionId, tabId, { address: tab.contentId, params: { url: address } })
|
|
1794
|
-
return true
|
|
1795
|
-
}
|
|
1796
|
-
} catch (error) {
|
|
1797
|
-
return false
|
|
1798
|
-
}
|
|
1799
|
-
return false
|
|
1800
|
-
}
|
|
1801
|
-
|
|
1802
|
-
/** Bind each logical view to one native tab; URLs can change without changing that identity. */
|
|
1803
|
-
function openViewPanel(sessionId, address, viewId, guestId) {
|
|
1804
|
-
const key = viewKey(sessionId, viewId)
|
|
1805
|
-
const switched = claimConversation(sessionId)
|
|
1806
|
-
let tabs
|
|
1807
|
-
try { tabs = Array.from(sidebarRight.tabsIn(sessionId)) }
|
|
1808
|
-
catch { return { ok: false, reason: "the shell cannot list this conversation's tabs", panel: false, guestId: null, ...switched ? { switched: true } : {} } }
|
|
1809
|
-
const browsers = tabs.filter(tab => tab !== null && typeof tab === "object" && tab.kind === "browser" && typeof tab.id === "string")
|
|
1810
|
-
const allowed = new Set(browsers.map(tab => tab.id))
|
|
1811
|
-
const roots = panelRootsFor(sessionId)
|
|
1812
|
-
const owned = new Set(Array.from(pendingTabs.entries())
|
|
1813
|
-
.filter(([otherKey, binding]) => otherKey !== key && binding.sessionId === sessionId)
|
|
1814
|
-
.map(([, binding]) => binding.id))
|
|
1815
|
-
let binding = pendingTabs.get(key)
|
|
1816
|
-
if (binding !== undefined && !allowed.has(binding.id)) {
|
|
1817
|
-
// A missing store while the conversation mounts is temporary. Keep its identity until the
|
|
1818
|
-
// store is readable again; a nonempty store proves that the original tab actually closed.
|
|
1819
|
-
if (tabs.length === 0 && onScreenSession() !== sessionId) {
|
|
1820
|
-
return { ok: false, reason: "this conversation's sidebar is not mounted", panel: false, guestId: null, ...switched ? { switched: true } : {} }
|
|
1821
|
-
}
|
|
1822
|
-
return { ok: false, code: "BROWSER_GUEST_CLOSED", reason: "the native tab for this browser view was closed; close or reset the view before retrying", panel: true, guestId: null }
|
|
1823
|
-
}
|
|
1824
|
-
const guests = guestsInPanel(sessionId)
|
|
1825
|
-
const hasNativeGuest = globalThis.dshDesktop?.browser?.nativeViews?.protocolVersion === 1 && typeof guestId === "string"
|
|
1826
|
-
const hasCachedGuest = (Number.isInteger(guestId) && guestId > 0) || hasNativeGuest
|
|
1827
|
-
if (binding === undefined && hasNativeGuest) {
|
|
1828
|
-
const cached = browsers.find(tab => initializationReader?.current({ sessionId, tabId: tab.id })?.guestId === guestId)
|
|
1829
|
-
if (cached === undefined || owned.has(cached.id)) return { ok: false, code: "BROWSER_GUEST_CLOSED", reason: "the native guest is not in this conversation", panel: true, guestId: null }
|
|
1830
|
-
binding = { sessionId, id: cached.id, url: address, scoped: true }
|
|
1831
|
-
}
|
|
1832
|
-
if (binding === undefined && hasCachedGuest) {
|
|
1833
|
-
const cached = guests.find(view => view.getWebContentsId() === guestId)
|
|
1834
|
-
if (cached !== undefined) {
|
|
1835
|
-
const id = tabIdOfElement(cached, allowed, roots)
|
|
1836
|
-
if (id === null || owned.has(id)) {
|
|
1837
|
-
return { ok: false, reason: "the requested guest cannot be assigned to this browser view", panel: true, guestId: null }
|
|
1838
|
-
}
|
|
1839
|
-
binding = { sessionId, id, url: address, scoped: true }
|
|
1840
|
-
}
|
|
1841
|
-
if (binding === undefined) return { ok: false, code: "BROWSER_GUEST_CLOSED", reason: "the native guest for this browser view is gone", panel: true, guestId: null }
|
|
1842
|
-
}
|
|
1843
|
-
if (binding === undefined && !hasCachedGuest) {
|
|
1844
|
-
// Adopt only an unclaimed guest whose native tab can be proved. Multiple visible guests
|
|
1845
|
-
// are ambiguous (split panes); creating a tab is safer than choosing by list order.
|
|
1846
|
-
const candidates = guests.map(view => ({ view, id: tabIdOfElement(view, allowed, roots) }))
|
|
1847
|
-
.filter(candidate => candidate.id !== null && !owned.has(candidate.id))
|
|
1848
|
-
const drawn = candidates.filter(({ view }) => {
|
|
1849
|
-
const rect = view.getBoundingClientRect()
|
|
1850
|
-
return rect.width > 0 && rect.height > 0
|
|
1851
|
-
})
|
|
1852
|
-
const candidate = drawn.length === 1 ? drawn[0] : candidates.length === 1 ? candidates[0] : undefined
|
|
1853
|
-
if (candidate !== undefined) binding = { sessionId, id: candidate.id, url: address, scoped: true }
|
|
1854
|
-
}
|
|
1855
|
-
const placeTab = (url) => {
|
|
1856
|
-
// The Web panel serves pages through the same-origin guest proxy; it needs to know which
|
|
1857
|
-
// conversation the tab belongs to so a quote can be handed back to the right draft.
|
|
1858
|
-
try { globalThis.__dshSidebarSessionId = sessionId } catch { /* non-writable global */ }
|
|
1859
|
-
const before = new Set(tabs.map(tab => tab.id))
|
|
1860
|
-
try {
|
|
1861
|
-
if (globalThis.dshDesktop?.browser?.nativeViews?.protocolVersion === 1
|
|
1862
|
-
&& typeof sidebarRight.openReservedTab === "function") {
|
|
1863
|
-
const id = globalThis.crypto.randomUUID()
|
|
1864
|
-
if (!sidebarRight.openReservedTab(sessionId, "browser", id)) return { ok: false, reason: "the shell refused this browser tab reservation" }
|
|
1865
|
-
if (url && !navigatePlacedTab(sessionId, id, url)) {
|
|
1866
|
-
sidebarRight.closeIn?.(sessionId, id)
|
|
1867
|
-
return { ok: false, reason: "the shell refused this browser tab navigation" }
|
|
1868
|
-
}
|
|
1869
|
-
} else sidebarRight.openTabIn(sessionId, "browser", url ? { params: { url } } : {})
|
|
1870
|
-
}
|
|
1871
|
-
catch (error) { return { ok: false, reason: String(error?.message ?? error) } }
|
|
1872
|
-
let placed
|
|
1873
|
-
try { placed = Array.from(sidebarRight.tabsIn(sessionId)) }
|
|
1874
|
-
catch { placed = [] }
|
|
1875
|
-
const added = placed.filter(tab => tab !== null && typeof tab === "object" && tab.kind === "browser"
|
|
1876
|
-
&& typeof tab.id === "string" && !before.has(tab.id) && !owned.has(tab.id))
|
|
1877
|
-
if (added.length !== 1) {
|
|
1878
|
-
return { ok: false, reason: placed.length === 0 ? "this conversation's sidebar is not mounted" : "the shell did not identify a new browser tab for this view" }
|
|
1879
|
-
}
|
|
1880
|
-
return { ok: true, id: added[0].id }
|
|
1881
|
-
}
|
|
1882
|
-
let created = false
|
|
1883
|
-
if (binding === undefined) {
|
|
1884
|
-
const placed = placeTab(address)
|
|
1885
|
-
if (!placed.ok) {
|
|
1886
|
-
return { ok: false, reason: placed.reason, panel: roots === undefined ? tabStripFor(sessionId) !== null : roots.length > 0, guestId: null, ...switched ? { switched: true } : {} }
|
|
1887
|
-
}
|
|
1888
|
-
binding = { sessionId, id: placed.id, url: address, scoped: true }
|
|
1889
|
-
created = true
|
|
1890
|
-
}
|
|
1891
|
-
pendingTabs.set(key, binding)
|
|
1892
|
-
const state = guestStateFor(sessionId, binding.id, initializationReader)
|
|
1893
|
-
// A bound tab that still shows the start page has no guest to reveal.
|
|
1894
|
-
// Revealing it can never produce one, so ask the shell to aim that exact
|
|
1895
|
-
// tab at the requested address; the host body turns the new navigation
|
|
1896
|
-
// revision into the one real page load. Tabs created above already carry
|
|
1897
|
-
// the address as their initial URL and need no second navigation.
|
|
1898
|
-
let navigating = false
|
|
1899
|
-
if (!created && state.guestId === null && address !== "") {
|
|
1900
|
-
navigating = navigatePlacedTab(sessionId, binding.id, address)
|
|
1901
|
-
if (!navigating) {
|
|
1902
|
-
return {
|
|
1903
|
-
ok: false,
|
|
1904
|
-
reason: "this DSH shell cannot initialize a bound start-page tab; update DSH and retry",
|
|
1905
|
-
panel: state.panel,
|
|
1906
|
-
guestId: null,
|
|
1907
|
-
tabId: binding.id,
|
|
1908
|
-
...switched ? { switched: true } : {},
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
return {
|
|
1913
|
-
ok: true,
|
|
1914
|
-
created,
|
|
1915
|
-
navigating,
|
|
1916
|
-
panel: state.panel,
|
|
1917
|
-
guestId: state.guestId,
|
|
1918
|
-
url: state.url,
|
|
1919
|
-
tabId: binding.id,
|
|
1920
|
-
...switched ? { switched: true } : {},
|
|
1921
|
-
...revealPlacedPanel(sessionId, binding.id),
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
|
|
1925
|
-
const api = {
|
|
1926
|
-
holdRendering(sessionId, token, deadline = Date.now() + 30_000) {
|
|
1927
|
-
if (typeof sessionId !== "string" || !sessionId.startsWith("session-") || typeof token !== "string") return false
|
|
1928
|
-
if (!Number.isFinite(deadline) || deadline <= Date.now()) return false
|
|
1929
|
-
if (renderingHolds.has(token)) return true
|
|
1930
|
-
if (onScreenSession() === sessionId || typeof sidebarRight?.holdRendering !== "function") return false
|
|
1931
|
-
const release = sidebarRight.holdRendering(sessionId)
|
|
1932
|
-
const timer = setTimeout(() => releaseRendering(token), Math.min(30_000, deadline - Date.now()))
|
|
1933
|
-
renderingHolds.set(token, { sessionId, release, timer })
|
|
1934
|
-
return true
|
|
1935
|
-
},
|
|
1936
|
-
releaseRendering,
|
|
1937
|
-
isBackgroundRendering(sessionId) {
|
|
1938
|
-
return hasRenderingHold(sessionId) && Array.from(document.querySelectorAll("[data-sidebar-right-background-rendering]"))
|
|
1939
|
-
.some(element => element.getAttribute("data-sidebar-right-session") === sessionId)
|
|
1940
|
-
},
|
|
1941
|
-
panelProtocol: 5,
|
|
1942
|
-
cancelPanelInitialization(sessionId, viewId, transactionId) {
|
|
1943
|
-
const pending = initializing.get(viewKey(sessionId, viewId))
|
|
1944
|
-
if (!pending || pending.transactionId !== transactionId) return false
|
|
1945
|
-
pending.controller.abort(Object.assign(new Error("sidebar initialization was cancelled"), { code: "BROWSER_NAVIGATION_CANCELLED" }))
|
|
1946
|
-
return true
|
|
1947
|
-
},
|
|
1948
|
-
async initializePanel(sessionId, url, options) {
|
|
1949
|
-
const refuse = (code, reason) => ({ ok: false, code, reason, panel: false, guestId: null })
|
|
1950
|
-
if (typeof options?.viewId !== "string" || options.viewId === "") return refuse("panel-initialization-failed", "a logical view identity is required")
|
|
1951
|
-
if (onScreenSession() !== sessionId && !api.isBackgroundRendering(sessionId)) return refuse("panel-not-displayed", "the requested conversation is not displayed; select it before opening its browser")
|
|
1952
|
-
const reader = initializationReader
|
|
1953
|
-
if (reader === null || typeof reader.wait !== "function") return refuse("panel-initialization-failed", "the browser initialization subscription is unavailable; reload the plugin client")
|
|
1954
|
-
const deadline = options.deadline
|
|
1955
|
-
if (!Number.isFinite(deadline) || deadline <= Date.now()) return refuse("BROWSER_DOCUMENT_TIMEOUT", "sidebar initialization deadline expired")
|
|
1956
|
-
const key = viewKey(sessionId, options.viewId)
|
|
1957
|
-
const previous = initializing.get(key)
|
|
1958
|
-
const controller = new AbortController()
|
|
1959
|
-
const transaction = { controller, transactionId: options.transactionId }
|
|
1960
|
-
let placed
|
|
1961
|
-
const closeNative = () => {
|
|
1962
|
-
if (globalThis.dshDesktop?.browser?.nativeViews?.protocolVersion !== 1 || typeof placed?.tabId !== "string") return
|
|
1963
|
-
sidebarRight.closeIn?.(sessionId, placed.tabId)
|
|
1964
|
-
if (pendingTabs.get(key)?.id === placed.tabId) pendingTabs.delete(key)
|
|
1965
|
-
}
|
|
1966
|
-
controller.signal.addEventListener("abort", closeNative, { once: true })
|
|
1967
|
-
initializing.set(key, transaction)
|
|
1968
|
-
previous?.controller.abort(Object.assign(new Error("a newer sidebar initialization was requested"), { code: "panel-navigation-superseded" }))
|
|
1969
|
-
const timer = setTimeout(() => controller.abort(Object.assign(new Error("sidebar initialization deadline expired"), { code: "BROWSER_DOCUMENT_TIMEOUT" })), deadline - Date.now())
|
|
1970
|
-
try {
|
|
1971
|
-
const answer = api.openPanel(sessionId, url, options)
|
|
1972
|
-
placed = answer
|
|
1973
|
-
if (controller.signal.aborted) { closeNative(); controller.signal.throwIfAborted() }
|
|
1974
|
-
if (!answer.ok) return answer
|
|
1975
|
-
const rendererNavigation = url !== "" && (answer.created || answer.navigating)
|
|
1976
|
-
if (!rendererNavigation && answer.guestId !== null) return globalThis.dshDesktop?.browser?.nativeViews?.protocolVersion === 1
|
|
1977
|
-
? { ...answer, nativeState: reader.current({ sessionId, tabId: answer.tabId }) } : answer
|
|
1978
|
-
if (typeof answer.tabId !== "string") return refuse("panel-initialization-failed", "the shell did not acknowledge its native tab identity")
|
|
1979
|
-
const receipt = await reader.wait({ sessionId, tabId: answer.tabId, url }, controller.signal)
|
|
1980
|
-
controller.signal.throwIfAborted()
|
|
1981
|
-
const state = api.panelGuest(sessionId, answer.tabId, options)
|
|
1982
|
-
const observed = reader.current({ sessionId, tabId: answer.tabId })
|
|
1983
|
-
if (state.guestId === null || String(state.guestId) !== receipt.guestId || observed?.guestId !== receipt.guestId) {
|
|
1984
|
-
return refuse("panel-initialization-failed", "the mounted native guest did not acknowledge its initialization identity")
|
|
1985
|
-
}
|
|
1986
|
-
return { ...answer, ...state, url: observed.url, initialization: receipt, rendererNavigation,
|
|
1987
|
-
...observed.generation === undefined ? {} : { nativeState: observed } }
|
|
1988
|
-
} catch (error) {
|
|
1989
|
-
closeNative()
|
|
1990
|
-
return refuse(error?.code ?? "panel-initialization-failed", String(error?.message ?? error))
|
|
1991
|
-
} finally {
|
|
1992
|
-
clearTimeout(timer)
|
|
1993
|
-
controller.signal.removeEventListener("abort", closeNative)
|
|
1994
|
-
if (initializing.get(key) === transaction) initializing.delete(key)
|
|
1995
|
-
}
|
|
1996
|
-
},
|
|
1997
|
-
get initializationProtocol() { return initializationReader?.protocolVersion ?? 0 },
|
|
1998
|
-
panelInitialization(sessionId, tabId, url, requestId) {
|
|
1999
|
-
if (initializationReader === null || typeof sessionId !== "string" || !sessionId.startsWith("session-")
|
|
2000
|
-
|| typeof tabId !== "string" || typeof url !== "string") return undefined
|
|
2001
|
-
const binding = Array.from(pendingTabs.values()).find(value => value.sessionId === sessionId && value.id === tabId)
|
|
2002
|
-
if (binding === undefined) return undefined
|
|
2003
|
-
return initializationReader.read({ sessionId, tabId, url,
|
|
2004
|
-
...typeof requestId === "string" ? { requestId } : {} })
|
|
2005
|
-
},
|
|
2006
|
-
/** @returns what happened: an existing guest, a newly opened tab, or a named refusal. */
|
|
2007
|
-
openPanel(sessionId, url, options) {
|
|
2008
|
-
const wanted = typeof sessionId === "string" ? sessionId : ""
|
|
2009
|
-
if (!/^session-/.test(wanted)) {
|
|
2010
|
-
return { ok: false, reason: "not a conversation id: " + JSON.stringify(sessionId), panel: false, guestId: null }
|
|
2011
|
-
}
|
|
2012
|
-
if (sidebarRight === null || typeof sidebarRight.openTabIn !== "function") {
|
|
2013
|
-
return { ok: false, reason: "the shell's sidebar service is not available", panel: false, guestId: null }
|
|
2014
|
-
}
|
|
2015
|
-
const address = url ? String(url) : ""
|
|
2016
|
-
if (typeof options?.viewId === "string" && options.viewId !== "") {
|
|
2017
|
-
return openViewPanel(wanted, address, options.viewId, options.guestId)
|
|
2018
|
-
}
|
|
2019
|
-
const pending = pendingTabs.get(wanted)
|
|
2020
|
-
const state = guestStateFor(wanted, pending?.url === address && pending.scoped ? pending.id : undefined, initializationReader)
|
|
2021
|
-
// Explicit opening also reveals a guest kept mounted in a collapsed or hidden sidebar.
|
|
2022
|
-
// Passive panelGuest/panelGuests reads never call either presentation helper.
|
|
2023
|
-
const switched = claimConversation(wanted)
|
|
2024
|
-
if (state.guestId !== null) {
|
|
2025
|
-
const revealed = revealPlacedPanel(wanted, pending?.url === address ? pending.id : undefined)
|
|
2026
|
-
return {
|
|
2027
|
-
ok: true,
|
|
2028
|
-
created: false,
|
|
2029
|
-
panel: true,
|
|
2030
|
-
guestId: state.guestId,
|
|
2031
|
-
url: state.url,
|
|
2032
|
-
...switched ? { switched: true } : {},
|
|
2033
|
-
...revealed,
|
|
2034
|
-
}
|
|
2035
|
-
}
|
|
2036
|
-
// No panel DOM for this conversation means the shell is not DISPLAYING it, and no tab placed
|
|
2037
|
-
// here can ever grow a webview: the shell renders one sidebar, for the conversation it shows.
|
|
2038
|
-
// Asking the human to click over was the old answer, and it made a working carrier depend on
|
|
2039
|
-
// their timing. Ask the shell instead — `openSession` is its own navigation, one call on its
|
|
2040
|
-
// own workspace service, no input events — and report `switched` so the caller can retry one
|
|
2041
|
-
// render later instead of reporting a dead carrier.
|
|
2042
|
-
// A mounted panel is NOT required to place a tab.
|
|
2043
|
-
//
|
|
2044
|
-
// `openTabIn` acts on the conversation's own surface store, and the sidebar-right service
|
|
2045
|
-
// keeps one for every conversation the shell has shown — "reaches any session's store by
|
|
2046
|
-
// id … on screen or not". What a DISPLAYED conversation adds is the DOM to read the guest
|
|
2047
|
-
// back out of, which is a separate question. So the tab is placed either way, and `tabsIn`
|
|
2048
|
-
// (a public method) is what says whether it actually landed: `openTabIn` SILENTLY ignores a
|
|
2049
|
-
// conversation whose store was never minted, and a silent no-op must never be reported as
|
|
2050
|
-
// success.
|
|
2051
|
-
let beforeTabs = []
|
|
2052
|
-
try { beforeTabs = Array.from(sidebarRight.tabsIn(wanted)) } catch {}
|
|
2053
|
-
const before = beforeTabs.length
|
|
2054
|
-
const beforeIds = new Set(beforeTabs.map(tab => tab.id))
|
|
2055
|
-
const remembered = pending?.url === address
|
|
2056
|
-
? beforeTabs.find(tab => tab.kind === "browser" && tab.id === pending.id)
|
|
2057
|
-
: undefined
|
|
2058
|
-
if (remembered === undefined) {
|
|
2059
|
-
try {
|
|
2060
|
-
sidebarRight.openTabIn(wanted, "browser", address ? { params: { url: address } } : {})
|
|
2061
|
-
} catch (error) {
|
|
2062
|
-
return { ok: false, reason: String((error && error.message) || error), panel: state.panel, guestId: null }
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
let placedTabs = beforeTabs
|
|
2066
|
-
try { placedTabs = Array.from(sidebarRight.tabsIn(wanted)) } catch {}
|
|
2067
|
-
const placed = placedTabs.length
|
|
2068
|
-
const browserTabs = placedTabs.filter(tab => tab !== null && typeof tab === "object" && tab.kind === "browser")
|
|
2069
|
-
const added = browserTabs.filter(tab => !beforeIds.has(tab.id))
|
|
2070
|
-
const matching = browserTabs.filter(tab => address !== "" && (tab.params?.url === address || tab.url === address))
|
|
2071
|
-
// Multiple browser tabs use separate ids. Correlate this placement before revealing it.
|
|
2072
|
-
// Older shells deduplicate the browser kind, so their sole browser is unambiguous.
|
|
2073
|
-
const page = remembered
|
|
2074
|
-
?? (added.length === 1 ? added[0] : undefined)
|
|
2075
|
-
?? (matching.length === 1 ? matching[0] : undefined)
|
|
2076
|
-
?? (browserTabs.length === 1 ? browserTabs[0] : undefined)
|
|
2077
|
-
const scoped = browserTabs.length > 1 || panelRootsFor(wanted) !== undefined
|
|
2078
|
-
if (page !== undefined) pendingTabs.set(wanted, { id: page.id, url: address, scoped })
|
|
2079
|
-
if (page === undefined && browserTabs.length > 1) {
|
|
2080
|
-
return { ok: false, reason: "the shell did not identify which browser tab was placed", panel: state.panel, guestId: null }
|
|
2081
|
-
}
|
|
2082
|
-
// `openTabIn` DEDUPLICATES, so "the count grew" is the wrong test for "is this
|
|
2083
|
-
// conversation's surface mounted".
|
|
2084
|
-
//
|
|
2085
|
-
// Placing a page kind the conversation already holds leaves the count unchanged — the shell
|
|
2086
|
-
// reveals the tab it has. Testing for growth therefore reported a conversation that already
|
|
2087
|
-
// held the page as UNMOUNTED, and refused to drive a page that was right there: that is the
|
|
2088
|
-
// "it will not reopen what it already opened" behaviour, and it bites hardest on the second
|
|
2089
|
-
// open of an address, which is exactly when a human expects a fast answer.
|
|
2090
|
-
//
|
|
2091
|
-
// A count that started at zero and stayed there is the real signature of a surface the
|
|
2092
|
-
// shell has never minted, because that is the only case where `openTabIn` is a silent no-op.
|
|
2093
|
-
if (placed <= before && before === 0) {
|
|
2094
|
-
// Name what was FOUND, not just what was missing: "no panel" has two very different
|
|
2095
|
-
// causes — the shell has mounted no sidebar for this conversation (nothing this side can
|
|
2096
|
-
// do), or it writes its session id somewhere this lookup does not read (fixable) — and a
|
|
2097
|
-
// refusal that says only "not mounted" cannot tell them apart.
|
|
2098
|
-
const strips = Array.from(document.querySelectorAll("[class*=_tabStrip]"))
|
|
2099
|
-
return {
|
|
2100
|
-
ok: false,
|
|
2101
|
-
reason: "this conversation's sidebar is not mounted, so a panel cannot be opened in it",
|
|
2102
|
-
panel: state.panel,
|
|
2103
|
-
guestId: null,
|
|
2104
|
-
...switched ? { switched: true } : {},
|
|
2105
|
-
found: {
|
|
2106
|
-
wanted: wanted,
|
|
2107
|
-
strips: strips.length,
|
|
2108
|
-
owners: strips.slice(0, 8).map(strip => sessionIdOfElement(strip)),
|
|
2109
|
-
reactKeys: strips.length === 0 ? [] : Object.keys(strips[0]).filter(key => key.startsWith("__react")).slice(0, 4),
|
|
2110
|
-
},
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
// Placing is not showing: ask the shell to expand the column and focus that tab, so the
|
|
2114
|
-
// body (and with it the `<webview>`) actually gets created. Without this the caller polls
|
|
2115
|
-
// a panel that can never answer, which is exactly what "produced no page" used to mean.
|
|
2116
|
-
const revealed = revealPlacedPanel(wanted, page?.id)
|
|
2117
|
-
return {
|
|
2118
|
-
ok: true,
|
|
2119
|
-
created: placed > before,
|
|
2120
|
-
panel: state.panel,
|
|
2121
|
-
guestId: null,
|
|
2122
|
-
tabs: placed,
|
|
2123
|
-
...page === undefined || !scoped ? {} : { tabId: String(page.id) },
|
|
2124
|
-
...switched ? { switched: true } : {},
|
|
2125
|
-
...revealed,
|
|
2126
|
-
}
|
|
2127
|
-
},
|
|
2128
|
-
/** Read-only: this conversation's current guest, if it has one. */
|
|
2129
|
-
panelGuest(sessionId, tabId, options) {
|
|
2130
|
-
if (typeof options?.viewId === "string" && options.viewId !== "") {
|
|
2131
|
-
const bound = pendingTabs.get(viewKey(sessionId, options.viewId))
|
|
2132
|
-
const intended = typeof tabId === "string" && tabId !== "" ? tabId : bound?.id
|
|
2133
|
-
if (intended === undefined || (bound !== undefined && bound.id !== intended)) {
|
|
2134
|
-
const roots = panelRootsFor(sessionId)
|
|
2135
|
-
return { panel: roots === undefined ? tabStripFor(sessionId) !== null : roots.length > 0, guestId: null, url: "" }
|
|
2136
|
-
}
|
|
2137
|
-
return guestStateFor(sessionId, intended, initializationReader)
|
|
2138
|
-
}
|
|
2139
|
-
return guestStateFor(
|
|
2140
|
-
typeof sessionId === "string" ? sessionId : "",
|
|
2141
|
-
typeof tabId === "string" && tabId !== "" ? tabId : undefined,
|
|
2142
|
-
initializationReader,
|
|
2143
|
-
)
|
|
2144
|
-
},
|
|
2145
|
-
/** All guest ids verified inside this conversation, including shell-created popup tabs. */
|
|
2146
|
-
panelGuests(sessionId) {
|
|
2147
|
-
if (typeof sessionId !== "string" || !/^session-/.test(sessionId)) return []
|
|
2148
|
-
return guestsInPanel(sessionId).map(view => view.getWebContentsId())
|
|
2149
|
-
},
|
|
2150
|
-
/** Close exactly the tab hosting this guest. An unknown shell shape must fail closed. */
|
|
2151
|
-
closePanelGuest(sessionId, guestId) {
|
|
2152
|
-
const refuse = reason => ({ ok: false, reason, closed: 0 })
|
|
2153
|
-
if (typeof sessionId !== "string" || !/^session-/.test(sessionId)) return refuse("a conversation id is required")
|
|
2154
|
-
if (typeof guestId === "string" && globalThis.dshDesktop?.browser?.nativeViews?.protocolVersion === 1) {
|
|
2155
|
-
const tabs = sidebarRight.tabsIn(sessionId)
|
|
2156
|
-
const tab = tabs.find(tab => tab.kind === "browser" && initializationReader?.current({ sessionId, tabId: tab.id })?.guestId === guestId)
|
|
2157
|
-
if (tab === undefined || typeof sidebarRight.closeIn !== "function") return refuse("the native guest does not belong to this conversation")
|
|
2158
|
-
sidebarRight.closeIn(sessionId, tab.id)
|
|
2159
|
-
return { ok: true, closed: 1 }
|
|
2160
|
-
}
|
|
2161
|
-
const view = guestsInPanel(sessionId).find(candidate => candidate.getWebContentsId() === guestId)
|
|
2162
|
-
if (view === undefined) return refuse("the guest does not belong to this conversation panel")
|
|
2163
|
-
const roots = panelRootsFor(sessionId)
|
|
2164
|
-
const containers = roots === undefined ? [tabStripFor(sessionId)].filter(Boolean) : roots
|
|
2165
|
-
if (containers.length === 0 || sidebarRight === null || typeof sidebarRight.tabsIn !== "function") {
|
|
2166
|
-
return refuse("the shell cannot identify its tabs; refresh or upgrade the browser plugin client")
|
|
2167
|
-
}
|
|
2168
|
-
let tabs
|
|
2169
|
-
try { tabs = sidebarRight.tabsIn(sessionId) } catch { return refuse("the conversation tabs are unavailable") }
|
|
2170
|
-
const allowed = new Set(tabs.map(tab => tab.id))
|
|
2171
|
-
const id = tabIdOfElement(view, allowed, roots)
|
|
2172
|
-
if (id === null) return refuse("the shell does not expose this guest's tab identity; refresh or upgrade the desktop")
|
|
2173
|
-
// rc.5's scoped controller runs registered cleanup and removes the shell tab as one action.
|
|
2174
|
-
if (typeof sidebarRight.closeIn === "function") {
|
|
2175
|
-
try {
|
|
2176
|
-
sidebarRight.closeIn(sessionId, id)
|
|
2177
|
-
if (sidebarRight.tabsIn(sessionId).some(tab => tab.id === id)) return refuse("the shell did not remove the requested conversation tab")
|
|
2178
|
-
return { ok: true, closed: 1 }
|
|
2179
|
-
} catch (error) { return refuse("the shell could not close the conversation tab: " + String(error?.message ?? error)) }
|
|
2180
|
-
}
|
|
2181
|
-
const headers = Array.from(new Set(containers.flatMap(container => Array.from(container.querySelectorAll("[role=tab]")))))
|
|
2182
|
-
.filter(tab => tabIdOfElement(tab, allowed, roots) === id)
|
|
2183
|
-
if (headers.length !== 1) return refuse("the shell does not expose one matching tab control; refresh or upgrade the desktop")
|
|
2184
|
-
const buttons = Array.from(headers[0].querySelectorAll("button"))
|
|
2185
|
-
.filter(button => /关闭|close/i.test((button.getAttribute("aria-label") || "") + " " + (button.getAttribute("title") || "")))
|
|
2186
|
-
if (buttons.length !== 1) return refuse("the shell does not expose one matching close control; refresh or upgrade the desktop")
|
|
2187
|
-
buttons[0].click()
|
|
2188
|
-
return { ok: true, closed: 1 }
|
|
2189
|
-
},
|
|
2190
|
-
}
|
|
2191
|
-
ctx.effect(() => {
|
|
2192
|
-
globalThis.__dshBuiltinBrowser = api
|
|
2193
|
-
return () => {
|
|
2194
|
-
for (const transaction of initializing.values()) transaction.controller.abort(new Error("the panel service was disposed"))
|
|
2195
|
-
initializing.clear()
|
|
2196
|
-
releaseAllRendering()
|
|
2197
|
-
if (globalThis.__dshBuiltinBrowser === api) delete globalThis.__dshBuiltinBrowser
|
|
2198
|
-
}
|
|
2199
|
-
}, "dsh-builtin-browser: conversation panel service")
|
|
2200
|
-
}
|
|
2201
|
-
|
|
2202
|
-
/**
|
|
2203
|
-
* The live-view panel: one frame at a time, for an operator who is not sitting at this machine.
|
|
2204
|
-
*
|
|
2205
|
-
* A plain floating layer rather than a slot registration, deliberately. The host's layout has no
|
|
2206
|
-
* stable slot for "an extra surface over the conversation", and inventing one would tie this
|
|
2207
|
-
* panel to a layout that changes; a fixed layer works in every layout including a phone. It is
|
|
2208
|
-
* also entirely inert until the host turns `remoteView.enabled` on, which the sessions probe
|
|
2209
|
-
* reports.
|
|
2210
|
-
*
|
|
2211
|
-
* Pulls one frame per request and waits for it to paint before asking for the next, so a slow
|
|
2212
|
-
* link shows fewer frames instead of queueing them. Nothing here retries in a tight loop: a
|
|
2213
|
-
* refusal or a 503 moves the panel to a paused state, and it resumes on the next user action.
|
|
2214
|
-
* @param ctx - the plugin context, for the disposal hook.
|
|
2215
|
-
*/
|
|
2216
|
-
function installWatchPanel(ctx) {
|
|
2217
|
-
if (typeof document === "undefined") return
|
|
2218
|
-
const SESSIONS = PREVIEW_SESSIONS_ROUTE
|
|
2219
|
-
const FRAME = PREVIEW_ROUTE
|
|
2220
|
-
const MIN_INTERVAL_MS = 500
|
|
2221
|
-
|
|
2222
|
-
// Built element by element and referenced directly, never through innerHTML + querySelector.
|
|
2223
|
-
// Two reasons: the host's test sandbox provides a minimal `createElement`, and re-parsing markup
|
|
2224
|
-
// to find elements this code just made is work without a purpose.
|
|
2225
|
-
const make = (tag, className, text) => {
|
|
2226
|
-
const node = document.createElement(tag)
|
|
2227
|
-
if (className !== undefined) node.className = className
|
|
2228
|
-
if (text !== undefined) node.textContent = text
|
|
2229
|
-
return node
|
|
2230
|
-
}
|
|
2231
|
-
|
|
2232
|
-
const layer = make("div", "dsh-bw-watch")
|
|
2233
|
-
layer.setAttribute("data-dsh-bw-watch", "")
|
|
2234
|
-
|
|
2235
|
-
const openButton = make("button", "dsh-bw-watch-open")
|
|
2236
|
-
openButton.setAttribute("type", "button")
|
|
2237
|
-
const dot = make("span", "dsh-bw-watch-dot")
|
|
2238
|
-
const openLabel = make("span", "dsh-bw-watch-label")
|
|
2239
|
-
openButton.appendChild(dot)
|
|
2240
|
-
openButton.appendChild(openLabel)
|
|
2241
|
-
|
|
2242
|
-
const panel = make("section", "dsh-bw-watch-panel")
|
|
2243
|
-
panel.hidden = true
|
|
2244
|
-
|
|
2245
|
-
const head = make("header", "dsh-bw-watch-head")
|
|
2246
|
-
const title = make("span", "dsh-bw-watch-title")
|
|
2247
|
-
const state = make("span", "dsh-bw-watch-state")
|
|
2248
|
-
/** Only visible when the host reports more than one session to watch. */
|
|
2249
|
-
const sessionSelect = make("select", "dsh-bw-watch-session")
|
|
2250
|
-
sessionSelect.hidden = true
|
|
2251
|
-
const closeButton = make("button", "dsh-bw-watch-close", "×")
|
|
2252
|
-
closeButton.setAttribute("type", "button")
|
|
2253
|
-
head.appendChild(title)
|
|
2254
|
-
head.appendChild(sessionSelect)
|
|
2255
|
-
head.appendChild(state)
|
|
2256
|
-
head.appendChild(closeButton)
|
|
2257
|
-
|
|
2258
|
-
const stage = make("div", "dsh-bw-watch-stage")
|
|
2259
|
-
const img = make("img", "dsh-bw-watch-img")
|
|
2260
|
-
img.hidden = true
|
|
2261
|
-
const note = make("p", "dsh-bw-watch-note")
|
|
2262
|
-
stage.appendChild(img)
|
|
2263
|
-
stage.appendChild(note)
|
|
2264
|
-
|
|
2265
|
-
const foot = make("footer", "dsh-bw-watch-foot")
|
|
2266
|
-
const readonlyLabel = make("span", "dsh-bw-watch-readonly")
|
|
2267
|
-
const stopButton = make("button", "dsh-bw-watch-stop")
|
|
2268
|
-
stopButton.setAttribute("type", "button")
|
|
2269
|
-
foot.appendChild(readonlyLabel)
|
|
2270
|
-
foot.appendChild(stopButton)
|
|
2271
|
-
|
|
2272
|
-
panel.appendChild(head)
|
|
2273
|
-
panel.appendChild(stage)
|
|
2274
|
-
panel.appendChild(foot)
|
|
2275
|
-
layer.appendChild(openButton)
|
|
2276
|
-
layer.appendChild(panel)
|
|
2277
|
-
// Deliberately NOT appended here. The entry is mounted only when the host reports that watching
|
|
2278
|
-
// is on — reported as issue #40: with the feature off, the button still sat on every page and
|
|
2279
|
-
// the bridge-status request fired at startup, so a setting nobody turned on produced a permanent
|
|
2280
|
-
// control and a permanent diagnostic call.
|
|
2281
|
-
|
|
2282
|
-
/** Localized text, falling back to the key so a missing entry is visible rather than blank. */
|
|
2283
|
-
// Localized text.
|
|
2284
|
-
//
|
|
2285
|
-
// The try/catch that used to sit here was dead code, as Mzy123l pointed out on #40: the locale
|
|
2286
|
-
// service does not throw on a missing entry — it returns the key. So a miss shows the key, which
|
|
2287
|
-
// is diagnostic, and an empty answer is the only case worth substituting.
|
|
2288
|
-
const say = key => {
|
|
2289
|
-
const text = translate(key)
|
|
2290
|
-
return typeof text === "string" && text !== "" ? text : key
|
|
2291
|
-
}
|
|
2292
|
-
|
|
2293
|
-
/**
|
|
2294
|
-
* Apply the current locale to every static label.
|
|
2295
|
-
*
|
|
2296
|
-
* Called at mount, after a locale change, and again once the dictionaries are bound. The panel
|
|
2297
|
-
* used to set these exactly once, inside `apply()`, *before* `locale.register` had run — so the
|
|
2298
|
-
* shipped build showed `watch.title` as its title and the key was never replaced (issue #40).
|
|
2299
|
-
*/
|
|
2300
|
-
const relabel = () => {
|
|
2301
|
-
openLabel.textContent = say("watch.open")
|
|
2302
|
-
title.textContent = say("watch.title")
|
|
2303
|
-
readonlyLabel.textContent = say("watch.readOnly")
|
|
2304
|
-
stopButton.textContent = say("watch.stop")
|
|
2305
|
-
openButton.title = say("watch.open")
|
|
2306
|
-
sessionSelect.title = say("watch.session")
|
|
2307
|
-
sessionSelect.setAttribute("aria-label", say("watch.session"))
|
|
2308
|
-
}
|
|
2309
|
-
relabel()
|
|
2310
|
-
// A runtime language switch must reach labels that are already on screen. `subscribe` fires on
|
|
2311
|
-
// every locale snapshot change — a switch, and also a late dictionary registration — which is
|
|
2312
|
-
// exactly the set of moments these four strings can go stale.
|
|
2313
|
-
refreshWatchLabels = () => { relabel() }
|
|
2314
|
-
|
|
2315
|
-
let mounted = false
|
|
2316
|
-
/** Put the entry on the page. Idempotent, so a second enable cannot stack copies. */
|
|
2317
|
-
const mount = () => {
|
|
2318
|
-
if (mounted) return
|
|
2319
|
-
mounted = true
|
|
2320
|
-
document.body.appendChild(layer)
|
|
2321
|
-
relabel()
|
|
2322
|
-
}
|
|
2323
|
-
/** Take it off again — the host turned the feature off after it had been on. */
|
|
2324
|
-
const unmount = () => {
|
|
2325
|
-
if (!mounted) return
|
|
2326
|
-
mounted = false
|
|
2327
|
-
layer.remove()
|
|
2328
|
-
}
|
|
2329
|
-
|
|
2330
|
-
/**
|
|
2331
|
-
* One running view. `generation` is the identity of a single watching run: a stop, a session
|
|
2332
|
-
* switch and a reopen all advance it, so a request already in flight can never paint into the
|
|
2333
|
-
* new run or resurrect a second scheduling chain.
|
|
2334
|
-
*/
|
|
2335
|
-
const view = {
|
|
2336
|
-
session: undefined, timer: undefined, running: false, lastAt: 0, objectUrl: undefined,
|
|
2337
|
-
generation: 0, controller: undefined,
|
|
2338
|
-
}
|
|
2339
|
-
/** Guards the async probe: two clicks in the same tick must not both reach start(). */
|
|
2340
|
-
let starting = false
|
|
2341
|
-
|
|
2342
|
-
const setState = text => { state.textContent = text }
|
|
2343
|
-
const showNote = text => {
|
|
2344
|
-
note.textContent = text
|
|
2345
|
-
note.hidden = false
|
|
2346
|
-
img.hidden = true
|
|
2347
|
-
}
|
|
2348
|
-
/** Release the previous frame. A viewer that keeps every frame is a memory leak in a phone browser. */
|
|
2349
|
-
const dropFrame = () => {
|
|
2350
|
-
if (view.objectUrl !== undefined) {
|
|
2351
|
-
URL.revokeObjectURL(view.objectUrl)
|
|
2352
|
-
view.objectUrl = undefined
|
|
2353
|
-
}
|
|
2354
|
-
}
|
|
2355
|
-
/** End one generation: cancel its request, timer and frame, without touching the panel chrome. */
|
|
2356
|
-
const cancelLoop = () => {
|
|
2357
|
-
view.running = false
|
|
2358
|
-
view.generation += 1
|
|
2359
|
-
if (view.controller !== undefined) {
|
|
2360
|
-
try { view.controller.abort() } catch { /* an already settled controller is harmless */ }
|
|
2361
|
-
view.controller = undefined
|
|
2362
|
-
}
|
|
2363
|
-
if (view.timer !== undefined) { clearTimeout(view.timer); view.timer = undefined }
|
|
2364
|
-
dropFrame()
|
|
2365
|
-
img.removeAttribute("src")
|
|
2366
|
-
img.hidden = true
|
|
2367
|
-
}
|
|
2368
|
-
const stop = () => {
|
|
2369
|
-
cancelLoop()
|
|
2370
|
-
setState(say("watch.stopped"))
|
|
2371
|
-
showNote(say("watch.stopped"))
|
|
2372
|
-
panel.hidden = true
|
|
2373
|
-
}
|
|
2374
|
-
|
|
2375
|
-
/** Ask which sessions exist; returns whether watching is enabled at all. */
|
|
2376
|
-
const probe = async () => {
|
|
2377
|
-
try {
|
|
2378
|
-
const response = await fetch(SESSIONS, { headers: { accept: "application/json" } })
|
|
2379
|
-
if (!response.ok) return { enabled: false, sessions: [] }
|
|
2380
|
-
const data = await response.json()
|
|
2381
|
-
return { enabled: data?.enabled === true, sessions: Array.isArray(data?.sessions) ? data.sessions : [] }
|
|
2382
|
-
} catch {
|
|
2383
|
-
return { enabled: false, sessions: [] }
|
|
2384
|
-
}
|
|
2385
|
-
}
|
|
2386
|
-
|
|
2387
|
-
/** Show the sessions the host handed out, so a later-created one can actually be chosen. */
|
|
2388
|
-
const fillSessions = sessions => {
|
|
2389
|
-
// Clearing via innerHTML is the one exception to "build element by element": it removes
|
|
2390
|
-
// options, it does not parse markup, and a stale option list would keep a dead session on screen.
|
|
2391
|
-
sessionSelect.innerHTML = ""
|
|
2392
|
-
for (let index = 0; index < sessions.length; index += 1) {
|
|
2393
|
-
const id = String(sessions[index])
|
|
2394
|
-
const option = make("option")
|
|
2395
|
-
option.setAttribute("value", id)
|
|
2396
|
-
const short = id.length > 24 ? `${id.slice(0, 15)}…${id.slice(-6)}` : id
|
|
2397
|
-
option.textContent = `#${index + 1} ${short}`
|
|
2398
|
-
sessionSelect.appendChild(option)
|
|
2399
|
-
}
|
|
2400
|
-
sessionSelect.hidden = sessions.length < 2
|
|
2401
|
-
}
|
|
2402
|
-
|
|
2403
|
-
/**
|
|
2404
|
-
* Pull frames until stopped. One request in flight at a time, and the next one is scheduled only
|
|
2405
|
-
* after the current image has painted — that is what makes a slow link degrade into fewer
|
|
2406
|
-
* frames rather than a growing queue. `gen` is captured once per run and re-checked after every
|
|
2407
|
-
* await: a frame belonging to a superseded run is dropped instead of painted.
|
|
2408
|
-
*/
|
|
2409
|
-
const pump = async gen => {
|
|
2410
|
-
if (!view.running || gen !== view.generation) return
|
|
2411
|
-
if (document.visibilityState === "hidden") {
|
|
2412
|
-
// The design's rule: a hidden panel stops pulling immediately. Resuming is the user's
|
|
2413
|
-
// action, not a timer's.
|
|
2414
|
-
setState(say("watch.paused"))
|
|
2415
|
-
showNote(say("watch.paused"))
|
|
2416
|
-
view.timer = setTimeout(() => pump(gen), MIN_INTERVAL_MS * 4)
|
|
2417
|
-
return
|
|
2418
|
-
}
|
|
2419
|
-
const waited = Date.now() - view.lastAt
|
|
2420
|
-
if (waited < MIN_INTERVAL_MS) {
|
|
2421
|
-
view.timer = setTimeout(() => pump(gen), MIN_INTERVAL_MS - waited)
|
|
2422
|
-
return
|
|
2423
|
-
}
|
|
2424
|
-
view.lastAt = Date.now()
|
|
2425
|
-
let nextDelay = MIN_INTERVAL_MS
|
|
2426
|
-
const controller = view.controller
|
|
2427
|
-
try {
|
|
2428
|
-
const url = `${FRAME}?session=${encodeURIComponent(String(view.session))}`
|
|
2429
|
-
const init = { headers: { accept: "image/jpeg" } }
|
|
2430
|
-
if (controller !== undefined) init.signal = controller.signal
|
|
2431
|
-
const response = await fetch(url, init)
|
|
2432
|
-
if (!view.running || gen !== view.generation) return
|
|
2433
|
-
if (!response.ok) {
|
|
2434
|
-
const body = await response.json().catch(() => undefined)
|
|
2435
|
-
if (!view.running || gen !== view.generation) return
|
|
2436
|
-
setState(say("watch.paused"))
|
|
2437
|
-
showNote(body?.error === "remote-view-disabled"
|
|
2438
|
-
? say("watch.disabled")
|
|
2439
|
-
: body?.error === "no-such-session"
|
|
2440
|
-
? say("watch.noPage")
|
|
2441
|
-
: say("watch.paused"))
|
|
2442
|
-
// Slower polling while paused: a paused view must not turn into a hot loop.
|
|
2443
|
-
nextDelay = MIN_INTERVAL_MS * 4
|
|
2444
|
-
} else {
|
|
2445
|
-
const blob = await response.blob()
|
|
2446
|
-
if (!view.running || gen !== view.generation) return
|
|
2447
|
-
const painted = new Promise(resolve => {
|
|
2448
|
-
img.onload = () => resolve()
|
|
2449
|
-
img.onerror = () => resolve()
|
|
2450
|
-
})
|
|
2451
|
-
dropFrame()
|
|
2452
|
-
view.objectUrl = URL.createObjectURL(blob)
|
|
2453
|
-
img.src = view.objectUrl
|
|
2454
|
-
img.hidden = false
|
|
2455
|
-
note.hidden = true
|
|
2456
|
-
await painted
|
|
2457
|
-
if (!view.running || gen !== view.generation) return
|
|
2458
|
-
setState(say("watch.live"))
|
|
2459
|
-
}
|
|
2460
|
-
} catch {
|
|
2461
|
-
if (!view.running || gen !== view.generation) return
|
|
2462
|
-
setState(say("watch.disconnected"))
|
|
2463
|
-
showNote(say("watch.disconnected"))
|
|
2464
|
-
nextDelay = MIN_INTERVAL_MS * 4
|
|
2465
|
-
}
|
|
2466
|
-
if (view.running && gen === view.generation) view.timer = setTimeout(() => pump(gen), nextDelay)
|
|
2467
|
-
}
|
|
2468
|
-
|
|
2469
|
-
const start = async session => {
|
|
2470
|
-
cancelLoop()
|
|
2471
|
-
view.session = session
|
|
2472
|
-
view.running = true
|
|
2473
|
-
view.lastAt = 0
|
|
2474
|
-
view.controller = typeof AbortController === "function" ? new AbortController() : undefined
|
|
2475
|
-
const gen = view.generation
|
|
2476
|
-
panel.hidden = false
|
|
2477
|
-
setState(say("watch.connecting"))
|
|
2478
|
-
showNote(say("watch.connecting"))
|
|
2479
|
-
await pump(gen)
|
|
2480
|
-
}
|
|
2481
|
-
|
|
2482
|
-
/**
|
|
2483
|
-
* The session a viewer most likely means when the host cannot name the current conversation:
|
|
2484
|
-
* the newest session it created, rather than always the first entry of the map.
|
|
2485
|
-
*/
|
|
2486
|
-
const preferredSession = sessions => sessions[sessions.length - 1]
|
|
2487
|
-
|
|
2488
|
-
openButton.addEventListener("click", () => {
|
|
2489
|
-
void (async () => {
|
|
2490
|
-
if (view.running || starting) return
|
|
2491
|
-
starting = true
|
|
2492
|
-
try {
|
|
2493
|
-
const found = await probe()
|
|
2494
|
-
if (!found.enabled) { showNote(say("watch.disabled")); panel.hidden = false; return }
|
|
2495
|
-
if (found.sessions.length === 0) { showNote(say("watch.noPage")); panel.hidden = false; return }
|
|
2496
|
-
fillSessions(found.sessions)
|
|
2497
|
-
sessionSelect.value = String(preferredSession(found.sessions))
|
|
2498
|
-
const chosen = sessionSelect.value
|
|
2499
|
-
// Release before start(): the first frame may take a long time (or never arrive), and
|
|
2500
|
-
// holding the guard until then would also block a legitimate stop-then-reopen.
|
|
2501
|
-
// There is no await between here and start(), whose synchronous part sets view.running.
|
|
2502
|
-
starting = false
|
|
2503
|
-
await start(chosen)
|
|
2504
|
-
} finally { starting = false }
|
|
2505
|
-
})()
|
|
2506
|
-
})
|
|
2507
|
-
// Switching sessions replaces the run; it never adds a second loop alongside the live one.
|
|
2508
|
-
sessionSelect.addEventListener("change", () => {
|
|
2509
|
-
if (!view.running) return
|
|
2510
|
-
const chosen = sessionSelect.value
|
|
2511
|
-
if (typeof chosen === "string" && chosen !== "") void start(chosen)
|
|
2512
|
-
})
|
|
2513
|
-
closeButton.addEventListener("click", stop)
|
|
2514
|
-
stopButton.addEventListener("click", stop)
|
|
2515
|
-
// A panel hidden by a closed button must not keep pulling frames.
|
|
2516
|
-
document.addEventListener("visibilitychange", () => {
|
|
2517
|
-
if (document.visibilityState === "hidden" && view.running) {
|
|
2518
|
-
if (view.timer !== undefined) { clearTimeout(view.timer); view.timer = undefined }
|
|
2519
|
-
const gen = view.generation
|
|
2520
|
-
view.timer = setTimeout(() => pump(gen), MIN_INTERVAL_MS)
|
|
2521
|
-
}
|
|
2522
|
-
})
|
|
2523
|
-
|
|
2524
|
-
ctx.effect(() => () => {
|
|
2525
|
-
stop()
|
|
2526
|
-
unmount()
|
|
2527
|
-
refreshWatchEntry = () => {}
|
|
2528
|
-
refreshWatchLabels = () => {}
|
|
2529
|
-
}, "dsh-builtin-browser: live view panel")
|
|
2530
|
-
|
|
2531
|
-
/**
|
|
2532
|
-
* Report the sidebar bridge's install state next to the entry button.
|
|
2533
|
-
*
|
|
2534
|
-
* A missing bridge used to be a log line and nothing else, so a user on `channel: sidebar` saw
|
|
2535
|
-
* "another window opened again" with no way to connect that to the actual cause (issue #36).
|
|
2536
|
-
* The reading comes from the install tree, so it is true even before anything has been watched.
|
|
2537
|
-
*
|
|
2538
|
-
* The repair command is shown, never run: a page that could decide to close the desktop shell
|
|
2539
|
-
* would be a worse problem than the one this line solves.
|
|
2540
|
-
*/
|
|
2541
|
-
const showBridgeStatus = async () => {
|
|
2542
|
-
let status
|
|
2543
|
-
try {
|
|
2544
|
-
const response = await fetch(BRIDGE_STATUS_ROUTE, { headers: { accept: "application/json" } })
|
|
2545
|
-
if (!response.ok) return
|
|
2546
|
-
const data = await response.json()
|
|
2547
|
-
status = data?.bridge
|
|
2548
|
-
} catch {
|
|
2549
|
-
return
|
|
2550
|
-
}
|
|
2551
|
-
if (status === undefined) return
|
|
2552
|
-
// Only the two states a user can act on: an installed bridge needs no notice, and a host
|
|
2553
|
-
// without a desktop install has nothing to repair here.
|
|
2554
|
-
if (status.state === "installed" || status.present !== true) return
|
|
2555
|
-
const notice = make("div", "dsh-bw-watch-bridge")
|
|
2556
|
-
const line = make("div", "dsh-bw-watch-bridge-line",
|
|
2557
|
-
status.state === "stale" ? say("watch.bridgeStale") : say("watch.bridgeMissing"))
|
|
2558
|
-
notice.appendChild(line)
|
|
2559
|
-
if (typeof status.command === "string" && status.command !== "" && typeof window.dshDesktop?.mainExtensions?.status !== "function") {
|
|
2560
|
-
const code = make("code", "dsh-bw-watch-bridge-cmd", status.command)
|
|
2561
|
-
notice.appendChild(code)
|
|
2562
|
-
}
|
|
2563
|
-
panel.insertBefore(notice, panel.firstChild)
|
|
2564
|
-
}
|
|
2565
|
-
|
|
2566
|
-
/**
|
|
2567
|
-
* Mount the entry only if the host says viewing is enabled, and only then ask about the bridge.
|
|
2568
|
-
*
|
|
2569
|
-
* Both halves are the point of the ordering: the probe answers "is this feature on", and the
|
|
2570
|
-
* bridge-status request is a diagnostic for a feature that is on. Issuing it for a feature that
|
|
2571
|
-
* is off is what the review called a default entry manufacturing a call (issue #40).
|
|
2572
|
-
*
|
|
2573
|
-
* A host that does not serve the sessions endpoint answers `enabled: false`, so the fallback is
|
|
2574
|
-
* "no entry" rather than "an entry that cannot work".
|
|
2575
|
-
*/
|
|
2576
|
-
const mountIfEnabled = async () => {
|
|
2577
|
-
const found = await probe()
|
|
2578
|
-
if (!found.enabled) {
|
|
2579
|
-
// Turning the feature off must also stop what it started: a running stream outliving its own
|
|
2580
|
-
// switch is the sort of state that looks like a ghost later.
|
|
2581
|
-
stop()
|
|
2582
|
-
unmount()
|
|
2583
|
-
return
|
|
2584
|
-
}
|
|
2585
|
-
mount()
|
|
2586
|
-
await showBridgeStatus()
|
|
2587
|
-
}
|
|
2588
|
-
// The settings switch calls this after writing `remoteView.enabled` (issue #46): no page reload,
|
|
2589
|
-
// which is the difference between usable and useless on a phone.
|
|
2590
|
-
refreshWatchEntry = () => { void mountIfEnabled() }
|
|
2591
|
-
void mountIfEnabled()
|
|
2592
|
-
}
|
|
2593
|
-
|
|
2594
|
-
function apply(ctx) {
|
|
2595
|
-
// Before anything renders: the rows need a hover state, and inline styles cannot express
|
|
2596
|
-
// one. Idempotent, so a re-apply does not stack copies.
|
|
2597
|
-
installStyles()
|
|
2598
|
-
installPanelService(ctx)
|
|
2599
|
-
// Dictionaries and the bound `t` come BEFORE anything that sets text from them. The watch panel
|
|
2600
|
-
// used to be installed first, so its static labels were written while `translate` still returned
|
|
2601
|
-
// the key and were never rewritten — the panel shipped with `watch.title` as its title
|
|
2602
|
-
// (issue #40).
|
|
2603
|
-
ctx.effect(() => ctx.locale.register(NS, { zh, en }), "dsh-builtin-browser: dictionaries")
|
|
2604
|
-
const t = ctx.locale.bind(NS)
|
|
2605
|
-
translate = t
|
|
2606
|
-
updateCurrentLocale(ctx.locale)
|
|
2607
|
-
// A language switch has to reach text that is already on screen. `subscribe` fires on every
|
|
2608
|
-
// locale snapshot change (switch, and late dictionary registration); guarded, because a host
|
|
2609
|
-
// without it must still get the panel — the labels then simply keep their first language.
|
|
2610
|
-
if (typeof ctx.locale.subscribe === "function") {
|
|
2611
|
-
ctx.effect(() => {
|
|
2612
|
-
const off = ctx.locale.subscribe(() => {
|
|
2613
|
-
translate = ctx.locale.bind(NS)
|
|
2614
|
-
updateCurrentLocale(ctx.locale)
|
|
2615
|
-
// Two audiences, one notification: the vanilla watch panel rewrites its own text, and the
|
|
2616
|
-
// React settings section re-renders (see `useLocaleVersion`). Bumping the counter here is
|
|
2617
|
-
// what makes `t()` inside a mounted component return the new language at all.
|
|
2618
|
-
localeVersion += 1
|
|
2619
|
-
for (const update of localeWatchers) update()
|
|
2620
|
-
refreshWatchLabels()
|
|
2621
|
-
})
|
|
2622
|
-
return () => { if (typeof off === "function") off() }
|
|
2623
|
-
}, "dsh-builtin-browser: locale changes")
|
|
2624
|
-
}
|
|
2625
|
-
installWatchPanel(ctx)
|
|
2626
|
-
// Test seam. The readiness section is composed by the settings component, so a harness that
|
|
2627
|
-
// renders that component can see the element but never run it — and running it is what proves a
|
|
2628
|
-
// user reads a state label rather than `readiness.electron.failed`. Exported on the module rather
|
|
2629
|
-
// than published on `globalThis` (where the product's own `__dshBuiltinBrowser` lives, for the
|
|
2630
|
-
// shell's benefit): nothing in the product reads this name, and a page-level global would be a
|
|
2631
|
-
// side effect of shipping a test.
|
|
2632
|
-
exports.__readinessSection = Readiness
|
|
2633
|
-
// Same seam, same reason: the record list is now composed inside the
|
|
2634
|
-
// on-demand menu, so a harness must be able to render it without driving
|
|
2635
|
-
// the popover's own state.
|
|
2636
|
-
exports.__references = References
|
|
2637
|
-
exports.__hostPatchSection = HostPatchControls
|
|
2638
|
-
ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
2639
|
-
name: "settings.section",
|
|
2640
|
-
id: "dsh-builtin-browser",
|
|
2641
|
-
// Above the rows the host ships (its furthest sits at 40), so this panel
|
|
2642
|
-
// lands beneath them in the settings page.
|
|
2643
|
-
order: 60,
|
|
2644
|
-
label: () => t("nav"),
|
|
2645
|
-
locale: NS,
|
|
2646
|
-
inject: () => ({ t }),
|
|
2647
|
-
}, SettingsRoot))
|
|
2648
|
-
// No `conversation.input.left` entry: references are rendered one card per
|
|
2649
|
-
// selection inside the composer dock, so an aggregate record menu beside
|
|
2650
|
-
// the input only duplicated it.
|
|
2651
|
-
}
|
|
2652
|
-
|
|
2653
|
-
exports.name = name
|
|
2654
|
-
exports.inject = inject
|
|
2655
|
-
exports.apply = apply
|
|
2656
|
-
return module.exports as unknown as LegacyClientModule
|
|
2657
|
-
}
|