@dimina-kit/devtools 0.4.0-dev.20260803105710 → 0.4.0-dev.20260828092243

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/dist/main/api.d.ts +1 -1
  2. package/dist/main/app/app.js +66 -2
  3. package/dist/main/index.bundle.js +1454 -540
  4. package/dist/main/ipc/index.d.ts +3 -0
  5. package/dist/main/ipc/index.js +3 -0
  6. package/dist/main/ipc/popover.js +1 -1
  7. package/dist/main/ipc/project-create.d.ts +15 -0
  8. package/dist/main/ipc/project-create.js +26 -0
  9. package/dist/main/ipc/projects.d.ts +1 -1
  10. package/dist/main/ipc/projects.js +11 -0
  11. package/dist/main/ipc/session.js +11 -0
  12. package/dist/main/ipc/settings.js +2 -1
  13. package/dist/main/ipc/simulator-module.d.ts +4 -3
  14. package/dist/main/ipc/simulator-module.js +4 -5
  15. package/dist/main/ipc/tooltip.d.ts +13 -0
  16. package/dist/main/ipc/tooltip.js +28 -0
  17. package/dist/main/ipc/views.d.ts +15 -1
  18. package/dist/main/ipc/views.js +61 -4
  19. package/dist/main/runtime/miniapp-runtime.d.ts +87 -19
  20. package/dist/main/services/layout/index.d.ts +11 -0
  21. package/dist/main/services/layout/index.js +23 -0
  22. package/dist/main/services/network-forward/frontend-dispatch.js +2 -1
  23. package/dist/main/services/notifications/renderer-notifier.d.ts +32 -1
  24. package/dist/main/services/notifications/renderer-notifier.js +29 -1
  25. package/dist/main/services/projects/project-repository.d.ts +4 -1
  26. package/dist/main/services/projects/project-repository.js +63 -5
  27. package/dist/main/services/simulator-current-page/index.d.ts +5 -3
  28. package/dist/main/services/simulator-current-page/index.js +8 -1
  29. package/dist/main/services/update/update-manager.d.ts +17 -3
  30. package/dist/main/services/update/update-manager.js +25 -6
  31. package/dist/main/services/views/clear-console-filter.d.ts +44 -0
  32. package/dist/main/services/views/clear-console-filter.js +86 -0
  33. package/dist/main/services/views/console-filter-test-fixtures.d.ts +94 -0
  34. package/dist/main/services/views/console-filter-test-fixtures.js +82 -0
  35. package/dist/main/services/views/console-filter.d.ts +79 -130
  36. package/dist/main/services/views/console-filter.js +140 -183
  37. package/dist/main/services/views/devtools-tabs.d.ts +24 -4
  38. package/dist/main/services/views/devtools-tabs.js +40 -21
  39. package/dist/main/services/views/host-dialog-port-channel.d.ts +18 -0
  40. package/dist/main/services/views/host-dialog-port-channel.js +15 -0
  41. package/dist/main/services/views/host-dialog-session-runtime.d.ts +10 -0
  42. package/dist/main/services/views/host-dialog-session-runtime.js +17 -0
  43. package/dist/main/services/views/host-dialog-view.d.ts +95 -0
  44. package/dist/main/services/views/host-dialog-view.js +147 -0
  45. package/dist/main/services/views/host-sidebar-port-channel.d.ts +18 -0
  46. package/dist/main/services/views/host-sidebar-port-channel.js +15 -0
  47. package/dist/main/services/views/host-sidebar-session-runtime.d.ts +10 -0
  48. package/dist/main/services/views/host-sidebar-session-runtime.js +17 -0
  49. package/dist/main/services/views/host-sidebar-view.d.ts +59 -0
  50. package/dist/main/services/views/host-sidebar-view.js +44 -0
  51. package/dist/main/services/views/host-slot-port-channel.d.ts +107 -0
  52. package/dist/main/services/views/host-slot-port-channel.js +261 -0
  53. package/dist/main/services/views/host-slot-session-runtime.d.ts +40 -0
  54. package/dist/main/services/views/host-slot-session-runtime.js +50 -0
  55. package/dist/main/services/views/host-slot-view.d.ts +109 -0
  56. package/dist/main/services/views/host-slot-view.js +147 -0
  57. package/dist/main/services/views/host-toolbar-port-channel.d.ts +6 -91
  58. package/dist/main/services/views/host-toolbar-port-channel.js +10 -243
  59. package/dist/main/services/views/host-toolbar-session-runtime.d.ts +5 -30
  60. package/dist/main/services/views/host-toolbar-session-runtime.js +9 -47
  61. package/dist/main/services/views/host-toolbar-view.d.ts +34 -7
  62. package/dist/main/services/views/host-toolbar-view.js +30 -237
  63. package/dist/main/services/views/managed-web-contents-view.d.ts +48 -0
  64. package/dist/main/services/views/managed-web-contents-view.js +123 -0
  65. package/dist/main/services/views/native-simulator-devtools-host.js +64 -45
  66. package/dist/main/services/views/native-simulator-view.js +6 -24
  67. package/dist/main/services/views/native-view-tree.d.ts +25 -0
  68. package/dist/main/services/views/native-view-tree.js +69 -0
  69. package/dist/main/services/views/overlay-panels-view.d.ts +50 -4
  70. package/dist/main/services/views/overlay-panels-view.js +226 -108
  71. package/dist/main/services/views/placement-reconciler.d.ts +18 -18
  72. package/dist/main/services/views/placement-reconciler.js +91 -29
  73. package/dist/main/services/views/placement-test-driver.d.ts +27 -0
  74. package/dist/main/services/views/placement-test-driver.js +29 -0
  75. package/dist/main/services/views/view-manager-devtools-host-test-fixtures.js +3 -1
  76. package/dist/main/services/views/view-manager.d.ts +14 -86
  77. package/dist/main/services/views/view-manager.js +41 -4
  78. package/dist/main/services/views/workbench-view.js +27 -20
  79. package/dist/main/services/workbench-coi-server.d.ts +11 -0
  80. package/dist/main/services/workbench-coi-server.js +32 -0
  81. package/dist/main/services/workspace/rebuild-status.d.ts +21 -8
  82. package/dist/main/services/workspace/rebuild-status.js +24 -8
  83. package/dist/main/utils/paths.d.ts +4 -0
  84. package/dist/main/utils/paths.js +4 -0
  85. package/dist/main/utils/sender-policy.d.ts +1 -1
  86. package/dist/main/utils/sender-policy.js +16 -1
  87. package/dist/main/utils/theme.d.ts +7 -2
  88. package/dist/main/utils/theme.js +8 -3
  89. package/dist/native-host/common/common.js +65 -62
  90. package/dist/native-host/container/pageFrame.css +1 -1
  91. package/dist/native-host/render/render.js +3226 -2898
  92. package/dist/native-host/service/service.js +2 -2
  93. package/dist/preload/runtime/host-dialog-advertiser.d.ts +22 -0
  94. package/dist/preload/runtime/host-dialog-advertiser.js +37 -0
  95. package/dist/preload/runtime/host-dialog-port.d.ts +44 -0
  96. package/dist/preload/runtime/host-dialog-port.js +53 -0
  97. package/dist/preload/runtime/host-dialog-runtime.d.ts +28 -0
  98. package/dist/preload/runtime/host-dialog-runtime.js +36 -0
  99. package/dist/preload/runtime/host-sidebar-advertiser.d.ts +19 -0
  100. package/dist/preload/runtime/host-sidebar-advertiser.js +35 -0
  101. package/dist/preload/runtime/host-sidebar-port.d.ts +44 -0
  102. package/dist/preload/runtime/host-sidebar-port.js +53 -0
  103. package/dist/preload/runtime/host-sidebar-runtime.d.ts +28 -0
  104. package/dist/preload/runtime/host-sidebar-runtime.js +36 -0
  105. package/dist/preload/runtime/host-slot-port-bridge.d.ts +18 -0
  106. package/dist/preload/runtime/host-slot-port-bridge.js +112 -0
  107. package/dist/preload/runtime/host-toolbar-advertiser.d.ts +5 -13
  108. package/dist/preload/runtime/host-toolbar-advertiser.js +18 -38
  109. package/dist/preload/runtime/host-toolbar-port.d.ts +9 -0
  110. package/dist/preload/runtime/host-toolbar-port.js +11 -95
  111. package/dist/preload/runtime/wait-for-slot-root.d.ts +20 -0
  112. package/dist/preload/runtime/wait-for-slot-root.js +52 -0
  113. package/dist/preload/windows/host-dialog-runtime.cjs +353 -0
  114. package/dist/preload/windows/host-dialog-runtime.cjs.map +7 -0
  115. package/dist/preload/windows/host-dialog-runtime.d.ts +2 -0
  116. package/dist/preload/windows/host-dialog-runtime.js +13 -0
  117. package/dist/preload/windows/host-sidebar-runtime.cjs +354 -0
  118. package/dist/preload/windows/host-sidebar-runtime.cjs.map +7 -0
  119. package/dist/preload/windows/host-sidebar-runtime.d.ts +2 -0
  120. package/dist/preload/windows/host-sidebar-runtime.js +13 -0
  121. package/dist/preload/windows/host-toolbar-runtime.cjs +134 -51
  122. package/dist/preload/windows/host-toolbar-runtime.cjs.map +3 -3
  123. package/dist/preload/windows/main.cjs +3176 -14
  124. package/dist/preload/windows/main.cjs.map +4 -4
  125. package/dist/preload/windows/main.css +428 -0
  126. package/dist/preload/windows/main.css.map +7 -0
  127. package/dist/preload/windows/simulator.cjs +5 -2
  128. package/dist/preload/windows/simulator.cjs.map +2 -2
  129. package/dist/preload/windows/simulator.js +5 -2
  130. package/dist/renderer/assets/button-DsNqZm7o.js +2 -0
  131. package/dist/renderer/assets/constants-D7DfVqMp.js +2 -0
  132. package/dist/renderer/assets/constants-D8zsejFq.js +2 -0
  133. package/dist/renderer/assets/createLucideIcon-CYJeT1ji.js +2 -0
  134. package/dist/renderer/assets/dialog-pT4qWmka.js +46 -0
  135. package/dist/renderer/assets/dist-o70xmpc1.js +2 -0
  136. package/dist/renderer/assets/hostSidebarDefault-NvGZlE9O.js +2 -0
  137. package/dist/renderer/assets/index-zErhG3ta.js +5 -0
  138. package/dist/renderer/assets/input-4QxTXMZN.js +2 -0
  139. package/dist/renderer/assets/ipc-channels-overlays-Blr5TNoB.js +2 -0
  140. package/dist/renderer/assets/jsx-runtime-B-3rq1y5.css +1 -0
  141. package/dist/renderer/assets/jsx-runtime-CqVdW3eg.js +9 -0
  142. package/dist/renderer/assets/popover-CJiSWwuE.js +2 -0
  143. package/dist/renderer/assets/project-api-DZ1Zi6EC.js +2 -0
  144. package/dist/renderer/assets/projectCreateDialog-DMWNhw_1.js +2 -0
  145. package/dist/renderer/assets/select-C86pNcsu.js +2 -0
  146. package/dist/renderer/assets/settings-BoI8mLT1.js +2 -0
  147. package/dist/renderer/assets/settings-api-Bs_g4NHs.js +2 -0
  148. package/dist/renderer/assets/settings-tab-bar-DHLLygqv.js +2 -0
  149. package/dist/renderer/assets/tooltip-BhAyY0T4.js +2 -0
  150. package/dist/renderer/assets/types-YYjkvane.js +2 -0
  151. package/dist/renderer/assets/updateDialog-DPum3wx1.js +2 -0
  152. package/dist/renderer/assets/utils-kfQov6Pa.js +2 -0
  153. package/dist/renderer/assets/view-api-DFhb2R8-.js +2 -0
  154. package/dist/renderer/assets/workbenchSettings-DrajRQUk.js +8 -0
  155. package/dist/renderer/entries/host-sidebar-default/index.html +21 -0
  156. package/dist/renderer/entries/main/index.html +15 -7
  157. package/dist/renderer/entries/popover/index.html +10 -6
  158. package/dist/renderer/entries/project-create-dialog/index.html +27 -0
  159. package/dist/renderer/entries/settings/index.html +10 -5
  160. package/dist/renderer/entries/tooltip/index.html +21 -0
  161. package/dist/renderer/entries/update-dialog/index.html +25 -0
  162. package/dist/renderer/entries/workbench-settings/index.html +11 -5
  163. package/dist/service-host/preload.cjs +10 -0
  164. package/dist/service-host/sync-impls/menu-button-geometry.js +1 -0
  165. package/dist/shared/constants.d.ts +22 -0
  166. package/dist/shared/constants.js +22 -0
  167. package/dist/shared/ipc-channels-overlays.d.ts +156 -0
  168. package/dist/shared/ipc-channels-overlays.js +186 -0
  169. package/dist/shared/ipc-channels.d.ts +1 -67
  170. package/dist/shared/ipc-channels.js +9 -81
  171. package/dist/shared/ipc-schemas.d.ts +52 -0
  172. package/dist/shared/ipc-schemas.js +64 -0
  173. package/dist/shared/simulator-route.d.ts +8 -0
  174. package/dist/shared/simulator-route.js +15 -0
  175. package/dist/shared/types.d.ts +17 -0
  176. package/dist/shared/view-ids.d.ts +9 -0
  177. package/dist/shared/view-ids.js +21 -0
  178. package/dist/simulator/assets/device-shell-CmtM1QxP.js +2 -0
  179. package/dist/simulator/assets/device-shell-iFZo1igL.css +1 -0
  180. package/dist/simulator/assets/{simulator-COIE6R49.js → simulator-CIobn3Mh.js} +6 -6
  181. package/dist/simulator/assets/{simulator-mini-app-BLn7XV8e.js → simulator-mini-app-CRe6n9br.js} +2 -2
  182. package/dist/simulator/assets/simulator-ui-BupATgKo.css +1 -0
  183. package/dist/simulator/assets/simulator-ui-C_cP602X.js +2 -0
  184. package/dist/simulator/simulator.html +3 -2
  185. package/dist/vscode-workbench/assets/__vite-browser-external-Bc1vizTf.js +1 -0
  186. package/dist/vscode-workbench/assets/{dist-oHcwN53f.js → dist-CMfmHflW.js} +3 -3
  187. package/dist/vscode-workbench/assets/{iconv-lite-umd-CLMLpdGm.js → iconv-lite-umd-Bx8CgaZq.js} +1 -1
  188. package/dist/vscode-workbench/assets/{index-BE3UJdoH.js → index-CdG6YWhW.js} +436 -436
  189. package/dist/vscode-workbench/assets/{jschardet-BICW8PLJ.js → jschardet-M0qgd2lN.js} +1 -1
  190. package/dist/vscode-workbench/index.html +21 -1
  191. package/package.json +9 -8
  192. package/dist/main/services/views/destroy-child-view.d.ts +0 -9
  193. package/dist/main/services/views/destroy-child-view.js +0 -23
  194. package/dist/renderer/assets/constants-EAMiwL9_.js +0 -2
  195. package/dist/renderer/assets/index-BBg3YI5b.js +0 -49
  196. package/dist/renderer/assets/input-xdmfv-eH.js +0 -2
  197. package/dist/renderer/assets/ipc-transport-B3EpmfNS.js +0 -9
  198. package/dist/renderer/assets/ipc-transport-Blac3sOj.css +0 -1
  199. package/dist/renderer/assets/popover-B88e2hkg.js +0 -2
  200. package/dist/renderer/assets/select-CD9CJyhI.js +0 -2
  201. package/dist/renderer/assets/settings-44hf0QtO.js +0 -2
  202. package/dist/renderer/assets/settings-api-pJKPuP1M.js +0 -2
  203. package/dist/renderer/assets/workbenchSettings-DKD5U1Ql.js +0 -8
  204. package/dist/simulator/assets/device-shell-Cw7c-IkG.js +0 -2
  205. package/dist/simulator/assets/device-shell-DbC5ccs8.css +0 -1
  206. package/dist/simulator/assets/jsx-runtime-DkKmJyBb.js +0 -2
  207. package/dist/simulator/device-shell/menu-button-geometry.js +0 -18
  208. package/dist/vscode-workbench/assets/__vite-browser-external-BON7qP59.js +0 -1
@@ -1,21 +1,48 @@
1
+ import type { HostSlotControl } from './host-slot-view.js';
1
2
  import type { PlacementReconciler } from './placement-reconciler.js';
2
- import type { HostToolbarControl, ViewManagerContext } from './view-manager.js';
3
+ import type { ViewManagerContext } from './view-manager.js';
3
4
  /**
4
- * A strip above the devtools header that the downstream host loads its own
5
- * content into and fully controls. Bounds come from a renderer DOM anchor
6
- * (forward anchor, like the simulator DevTools overlay); its height is dynamic
7
- * via a reverse size-advertiser the toolbar's own renderer drives.
5
+ * Height mode for the host-toolbar placeholder strip. `'auto'` (default): the
6
+ * session-resident advertiser's reports drive the height. `{ fixed }`: the
7
+ * host pins the height; advertiser reports are ignored until `'auto'` again.
8
8
  */
9
+ export type HostToolbarHeightMode = 'auto' | {
10
+ fixed: number;
11
+ };
12
+ /**
13
+ * The control object the downstream host uses to own the toolbar
14
+ * WebContentsView. Lazily backed by the view-manager's `hostToolbarView`.
15
+ * Derives the shared members (`loadURL`, `loadFile`, `webContents`, `hide`,
16
+ * `setPreloadPath`, `onMessage`, `onReady`, `send`) from `HostSlotControl` —
17
+ * see that interface for their contract, generalized from
18
+ * `window.diminaHostToolbar` to the axis-neutral "slot page" — and adds only
19
+ * `setHeightMode` in place of the base's `setExtentMode`.
20
+ */
21
+ export interface HostToolbarControl extends Omit<HostSlotControl, 'setExtentMode'> {
22
+ /**
23
+ * Pin or unpin the toolbar strip height. `{ fixed }` notifies the renderer
24
+ * placeholder with that height immediately (so a preload-less/static toolbar
25
+ * is visible without any advertiser report) and ignores subsequent advertiser
26
+ * reports. `'auto'` (default) re-enables advertiser-driven height starting
27
+ * from the NEXT report — it does not synthesize/replay a stale height.
28
+ */
29
+ setHeightMode(mode: HostToolbarHeightMode): void;
30
+ }
9
31
  export interface HostToolbarView {
10
32
  readonly control: HostToolbarControl;
11
33
  setHostToolbarHeight(extent: number): void;
12
34
  getHostToolbarHeight(): number;
13
35
  getHostToolbarWebContentsId(): number | null;
14
- /** Teardown for `disposeAll`: sweep the port, destroy the view, release the runtime ref. */
15
36
  dispose(): void;
16
37
  }
38
+ /**
39
+ * Toolbar-specific instantiation of `createHostSlotView` (see that module for
40
+ * the full lazy-create / port-channel / extent-mode contract). Kept as its own
41
+ * named wrapper — not inlined into `view-manager.ts` — to freeze the existing
42
+ * `HostToolbarControl`/`HostToolbarHeightMode` public surface independently of
43
+ * the generic slot's neutral naming.
44
+ */
17
45
  export declare function createHostToolbarView(ctx: ViewManagerContext, reconciler: PlacementReconciler, deps: {
18
- /** Re-apply the settings/popover overlays whose height depends on the toolbar strip. */
19
46
  reapplyPresentOverlays(): void;
20
47
  }): HostToolbarView;
21
48
  //# sourceMappingURL=host-toolbar-view.d.ts.map
@@ -1,249 +1,42 @@
1
- import { WebContentsView } from 'electron';
2
- import { handleWindowOpenExternal } from '../../windows/navigation-hardening.js';
3
1
  import { HOST_TOOLBAR_RUNTIME_MARKER } from '../../../shared/constants.js';
4
2
  import { VIEW_ID, VIEW_LAYER } from '../../../shared/view-ids.js';
5
3
  import { acquireHostToolbarSessionRuntime, releaseHostToolbarSessionRuntime, } from './host-toolbar-session-runtime.js';
6
4
  import { createHostToolbarPortChannel } from './host-toolbar-port-channel.js';
7
- import { destroyChildView } from './destroy-child-view.js';
5
+ import { createHostSlotView, deriveSlotControl } from './host-slot-view.js';
6
+ /**
7
+ * Toolbar-specific instantiation of `createHostSlotView` (see that module for
8
+ * the full lazy-create / port-channel / extent-mode contract). Kept as its own
9
+ * named wrapper — not inlined into `view-manager.ts` — to freeze the existing
10
+ * `HostToolbarControl`/`HostToolbarHeightMode` public surface independently of
11
+ * the generic slot's neutral naming.
12
+ */
8
13
  export function createHostToolbarView(ctx, reconciler, deps) {
9
- let hostToolbarView = null;
10
- let hostToolbarPreloadOverride = null;
11
- let hostToolbarViewAdded = false;
12
- // Whether THIS manager holds a reference on the shared defaultSession
13
- // registration of the toolbar-runtime preload (see
14
- // host-toolbar-session-runtime.ts). Acquired on first toolbar need,
15
- // released exactly once in dispose — a manager that never used the
16
- // toolbar must not decrement a ref it never took.
17
- let hostToolbarRuntimeAcquired = false;
18
- // Placeholder height authority: 'auto' = advertiser reports forward to the
19
- // renderer; { fixed } = host-pinned, advertiser reports are dropped.
20
- let hostToolbarHeightMode = 'auto';
21
- // Last toolbar height NOTIFIED to the main-window renderer — the replay
22
- // source behind `getHostToolbarHeight()`. Updated ONLY inside
23
- // `notifyHostToolbarHeight` so the retained value can never diverge from
24
- // what the renderer was told (an advertiser report dropped by a `{ fixed }`
25
- // pin must not pollute it, and a setHeightMode validation reject leaves it
26
- // untouched).
27
- let hostToolbarLastHeight = 0;
28
- // Gated narrow channel to the toolbar PAGE (per-load MessagePort handshake;
29
- // see host-toolbar-port-channel.ts). Control-level registry — created with
30
- // the manager so onMessage() works before any toolbar view exists.
31
- const hostToolbarPort = createHostToolbarPortChannel({
32
- isCurrent: (wc) => liveHostToolbarWebContents() === wc,
14
+ const port = createHostToolbarPortChannel({
15
+ isCurrent: (wc) => slot.getWebContentsId() === wc.id,
33
16
  });
34
- // The toolbar's webContents lifecycle belongs to the HOST, which may close
35
- // it out from under us (the documented rebuild path). In real Electron a
36
- // WebContentsView whose webContents was destroyed can report `webContents`
37
- // as undefined — not merely a destroyed handle — so every access must
38
- // tolerate BOTH (observed in the R1 e2e: `.isDestroyed()` on undefined threw
39
- // inside the control surface after the host closed the wc).
40
- function liveHostToolbarWebContents() {
41
- const wc = hostToolbarView?.webContents;
42
- if (!wc || wc.isDestroyed())
43
- return null;
44
- return wc;
45
- }
46
- // Lazily create the host-toolbar view. Mirrors `showSettings` for the
47
- // webPreferences shape and the native simulator for nav hardening +
48
- // background color (the host may load arbitrary URLs / content). Idempotent.
49
- function ensureHostToolbarView() {
50
- if (hostToolbarView && liveHostToolbarWebContents()) {
51
- return hostToolbarView;
52
- }
53
- // Rebuilding after the host destroyed the underlying webContents: detach the
54
- // dead view from the contentView and reset the added-flag so the new view
55
- // gets re-mounted (otherwise the `hostToolbarViewAdded` guard would skip the
56
- // addChildView and the toolbar would silently disappear).
57
- if (hostToolbarView && hostToolbarViewAdded) {
58
- try {
59
- ctx.windows.mainWindow.contentView.removeChildView(hostToolbarView);
60
- }
61
- catch { /* already removed */ }
62
- hostToolbarViewAdded = false;
63
- }
64
- // The instance is being replaced — forget its reconciled mount state so the
65
- // rebuilt view is treated as a fresh attach (not skipped as already-attached).
66
- reconciler.forgetActual(VIEW_ID.hostToolbar);
67
- // The framework's height-advertiser runtime is SESSION-resident: register
68
- // it on session.defaultSession (ref-counted across coexisting managers)
69
- // BEFORE the view exists, so the very first load already runs it. The
70
- // toolbar WCV stays on the defaultSession (no partition/session override)
71
- // — moving it onto its own partition would silently detach it from this
72
- // registration and height advertising would die with no error.
73
- if (!hostToolbarRuntimeAcquired) {
74
- acquireHostToolbarSessionRuntime();
75
- hostToolbarRuntimeAcquired = true;
76
- }
77
- // `webPreferences.preload` is the HOST's alone (setPreloadPath); the
78
- // built-in advertiser no longer rides it (it would execute twice — the
79
- // session copy + the webPreferences copy). The additionalArguments marker
80
- // is what the session runtime's guard keys on to activate here and stay a
81
- // zero-footprint no-op in every other defaultSession renderer.
82
- const webPreferences = {
83
- nodeIntegration: false,
84
- contextIsolation: true,
85
- sandbox: false,
86
- additionalArguments: [HOST_TOOLBAR_RUNTIME_MARKER],
87
- };
88
- if (hostToolbarPreloadOverride !== null) {
89
- webPreferences.preload = hostToolbarPreloadOverride;
90
- }
91
- const view = new WebContentsView({ webPreferences });
92
- hostToolbarView = view;
93
- // Hook the per-load MessagePort handshake (did-finish-load) + dead-port
94
- // cleanup (destroyed) on the fresh wc. AFTER the assignment above so the
95
- // channel's isCurrent guard sees this wc as the live one.
96
- hostToolbarPort.attach(view.webContents);
97
- // Paint the surface a neutral color so growing the reserved strip never
98
- // flashes white before the host content paints (mirrors the native
99
- // simulator's setBackgroundColor anti-flash).
100
- try {
101
- view.setBackgroundColor('#121212');
102
- }
103
- catch { /* stub may lack it */ }
104
- // The host may load arbitrary URLs; route popups + cross-origin in-place
105
- // navigation to the OS browser (mirror the native simulator hardening).
106
- try {
107
- view.webContents.setWindowOpenHandler(({ url }) => handleWindowOpenExternal(url));
108
- }
109
- catch { /* stub may lack it */ }
110
- return view;
111
- }
112
- // Single funnel for the height notify: retain-then-push, so the retained
113
- // value is exactly the last value the renderer was told. Every height
114
- // notify site MUST go through here — the renderer pulls the retained value
115
- // on project-view mount to replay a push it missed (the toolbar's
116
- // size-advertiser deduplicates and never re-reports).
117
- function notifyHostToolbarHeight(height) {
118
- hostToolbarLastHeight = height;
119
- ctx.notify.hostToolbarHeightChanged(height);
120
- deps.reapplyPresentOverlays();
121
- }
122
- function setHostToolbarHeight(extent) {
123
- // While the host pins a fixed height, drop advertiser reports entirely —
124
- // the session-resident advertiser is always installed, so forwarding its
125
- // reports would make the strip oscillate between the pinned and measured
126
- // heights on every content resize. Dropped reports must not touch the
127
- // retained value either: retention records what was NOTIFIED, not what
128
- // was reported.
129
- if (hostToolbarHeightMode !== 'auto')
130
- return;
131
- // Push the reserved height back to the main-window renderer so its
132
- // placeholder div resizes (closing the dynamic-height loop). The notified
133
- // height IS retained in main (`getHostToolbarHeight`) so a renderer that
134
- // mounts later can pull/replay it; the renderer placeholder remains the
135
- // geometry authority — the forward anchor re-reports bounds from it.
136
- notifyHostToolbarHeight(extent);
137
- }
138
- function hideHostToolbar() {
139
- reconciler.setBaseDesired(VIEW_ID.hostToolbar, {
140
- viewId: VIEW_ID.hostToolbar,
141
- placement: { visible: false },
142
- layer: VIEW_LAYER.hostToolbar,
143
- });
144
- reconciler.reconcileNow();
145
- // Collapse the renderer placeholder to 0 too. Otherwise its anchor keeps a
146
- // non-zero reserved height and re-publishes bounds on the next window
147
- // resize, silently re-adding the view we just hid (unstable hide). Zeroing
148
- // the height flips the anchor to `present:false` so it stops re-publishing.
149
- // Through the funnel so the retained value follows to 0 — a renderer
150
- // mounting after the hide must replay 0, not the stale pre-hide height.
151
- notifyHostToolbarHeight(0);
152
- }
153
- const control = {
154
- async loadURL(url) {
155
- const view = ensureHostToolbarView();
156
- // Invalidate SYNCHRONOUSLY at initiation, before the load is issued:
157
- // the current document is about to be replaced, so a same-tick send()
158
- // must report false instead of confirming delivery into it. The channel
159
- // recovers on the new document's did-finish-load handshake. (Cannot
160
- // rely on did-start-navigation here — that only covers page-initiated
161
- // navigations once the load is actually under way.)
162
- hostToolbarPort.invalidate();
163
- await view.webContents.loadURL(url);
164
- },
165
- async loadFile(filePath) {
166
- const view = ensureHostToolbarView();
167
- // Same initiation-invalidates contract as loadURL above.
168
- hostToolbarPort.invalidate();
169
- await view.webContents.loadFile(filePath);
170
- },
171
- get webContents() {
172
- return liveHostToolbarWebContents();
173
- },
174
- hide() {
175
- hideHostToolbar();
176
- },
177
- setPreloadPath(path) {
178
- // The HOST's own webPreferences.preload, applied when the view is next
179
- // (re)created. `null` = no host preload. The framework advertiser is
180
- // session-resident and unaffected either way (see ensureHostToolbarView).
181
- hostToolbarPreloadOverride = path;
182
- },
183
- setHeightMode(mode) {
184
- // Validate BEFORE touching any state: a poisoned `{ fixed }` (NaN /
185
- // ±Infinity / negative) must neither reach the renderer placeholder
186
- // (`height: NaNpx` corrupts the strip with no error anywhere) nor
187
- // clobber the standing mode — fail-closed, not fail-corrupt.
188
- if (mode !== 'auto' && !(Number.isFinite(mode.fixed) && mode.fixed >= 0)) {
189
- throw new TypeError(`hostToolbar.setHeightMode: fixed height must be a finite, non-negative number (got ${mode.fixed})`);
190
- }
191
- hostToolbarHeightMode = mode;
192
- if (mode !== 'auto') {
193
- // Pin immediately: a preload-less/static toolbar never advertises, so
194
- // waiting for the next report would leave the strip at height 0.
195
- notifyHostToolbarHeight(mode.fixed);
196
- }
197
- // Switching back to 'auto' deliberately does NOT synthesize a notify —
198
- // replaying a stale cached height would flash the old size; the NEXT
199
- // advertiser report drives the placeholder again. The RETAINED value
200
- // survives the switch though: a freshly-mounting renderer still needs
201
- // the pinned height until that next report lands.
202
- },
203
- onMessage(channel, handler) {
204
- return hostToolbarPort.onMessage(channel, handler);
205
- },
206
- onReady(handler) {
207
- return hostToolbarPort.onReady(handler);
208
- },
209
- send(channel, payload) {
210
- return hostToolbarPort.send(channel, payload);
211
- },
212
- };
213
- reconciler.registerView(VIEW_ID.hostToolbar, {
214
- getView: () => hostToolbarView,
215
- ensureView: () => ensureHostToolbarView(),
216
- setAdded: (added) => { hostToolbarViewAdded = added; },
217
- ensureLazy: (desired) => {
218
- if (desired?.placement.visible && !liveHostToolbarWebContents())
219
- ensureHostToolbarView();
220
- },
17
+ const slot = createHostSlotView(reconciler, {
18
+ viewId: VIEW_ID.hostToolbar,
19
+ layer: VIEW_LAYER.hostToolbar,
20
+ marker: HOST_TOOLBAR_RUNTIME_MARKER,
21
+ sessionRuntime: {
22
+ acquire: acquireHostToolbarSessionRuntime,
23
+ release: releaseHostToolbarSessionRuntime,
24
+ },
25
+ portChannel: port,
26
+ setExtentModeErrorLabel: 'hostToolbar.setHeightMode',
27
+ }, {
28
+ onExtentChanged: (height) => ctx.notify.hostToolbarHeightChanged(height),
29
+ reapplyPresentOverlays: () => deps.reapplyPresentOverlays(),
30
+ });
31
+ const control = deriveSlotControl(slot.control, {
32
+ setHeightMode: (mode) => slot.control.setExtentMode(mode),
221
33
  });
222
- function dispose() {
223
- // Narrow channel first: close the live MessagePort + sweep the onMessage
224
- // registry, so a send() racing teardown reports false instead of posting
225
- // into a wc that is about to be closed.
226
- hostToolbarPort.dispose();
227
- // Host-controllable toolbar view: removed from the contentView + its
228
- // WebContents closed (the host's loaded content is torn down on app exit).
229
- destroyChildView(ctx.windows.mainWindow, hostToolbarView);
230
- hostToolbarView = null;
231
- hostToolbarViewAdded = false;
232
- // Release this manager's reference on the shared defaultSession
233
- // toolbar-runtime registration (only if it ever acquired one — a manager
234
- // that never used the toolbar must not drive the shared count to zero).
235
- // The LAST release unregisters; other coexisting managers keep theirs.
236
- if (hostToolbarRuntimeAcquired) {
237
- releaseHostToolbarSessionRuntime();
238
- hostToolbarRuntimeAcquired = false;
239
- }
240
- }
241
34
  return {
242
35
  control,
243
- setHostToolbarHeight,
244
- getHostToolbarHeight: () => hostToolbarLastHeight,
245
- getHostToolbarWebContentsId: () => liveHostToolbarWebContents()?.id ?? null,
246
- dispose,
36
+ setHostToolbarHeight: (extent) => slot.setExtent(extent),
37
+ getHostToolbarHeight: () => slot.getExtent(),
38
+ getHostToolbarWebContentsId: () => slot.getWebContentsId(),
39
+ dispose: () => slot.dispose(),
247
40
  };
248
41
  }
249
42
  //# sourceMappingURL=host-toolbar-view.js.map
@@ -0,0 +1,48 @@
1
+ import type { WebContents } from 'electron';
2
+ import { WebContentsView } from 'electron';
3
+ import type { PlacementReconciler } from './placement-reconciler.js';
4
+ import type { HostSlotPortChannel } from './host-slot-port-channel.js';
5
+ export interface ManagedWebContentsViewOptions {
6
+ reconciler: PlacementReconciler;
7
+ viewId: string;
8
+ /** `--dimina-host-*` marker passed as `additionalArguments`, self-guards the session-resident advertiser preload. */
9
+ marker: string;
10
+ sessionRuntime: {
11
+ acquire(): void;
12
+ release(): void;
13
+ };
14
+ /** The per-load handshake channel; shares this view's lazy-create/liveness/dispose lifecycle. */
15
+ port: HostSlotPortChannel;
16
+ /**
17
+ * Fires after a crashed/failed view has been torn down (see `ensureView`'s
18
+ * `render-process-gone`/`did-fail-load` handling below). The base slots
19
+ * (host-toolbar/host-sidebar) don't need this — their `ensureLazy` already
20
+ * rebuilds a fresh view on the next reconcile pass once `liveWebContents()`
21
+ * correctly reports the crash. host-dialog does: its on-demand placement
22
+ * (`visible` flag, `overlayDesired`) isn't reconciler-driven the same way,
23
+ * so without this a stale `visible: true` would resurrect a blank,
24
+ * content-less modal on the next reposition (e.g. a window resize).
25
+ */
26
+ onBroken?(): void;
27
+ }
28
+ /**
29
+ * Shared lazy-create / liveness / load / teardown lifecycle for the
30
+ * host-controllable WebContentsViews (host-toolbar, host-sidebar,
31
+ * host-dialog): a single `WebContentsView` recreated on demand when the
32
+ * previous one dies, backed by a ref-counted session-runtime registration and
33
+ * the per-load port-channel attach. Placement (persistent strip vs by-demand
34
+ * centered overlay) is layered on top by the caller — this module only owns
35
+ * "is there a live view, and (re)create/load/tear it down when needed."
36
+ */
37
+ export interface ManagedWebContentsView {
38
+ loadURL(url: string): Promise<void>;
39
+ loadFile(filePath: string): Promise<void>;
40
+ liveWebContents(): WebContents | null;
41
+ /** Raw view accessor for `reconciler.registerView`'s `getView` slot (may be non-null with a destroyed webContents). */
42
+ getView(): WebContentsView | null;
43
+ setPreloadPath(path: string | null): void;
44
+ ensureView(): WebContentsView;
45
+ dispose(): void;
46
+ }
47
+ export declare function createManagedWebContentsView(opts: ManagedWebContentsViewOptions): ManagedWebContentsView;
48
+ //# sourceMappingURL=managed-web-contents-view.d.ts.map
@@ -0,0 +1,123 @@
1
+ import { WebContentsView } from 'electron';
2
+ import { handleWindowOpenExternal } from '../../windows/navigation-hardening.js';
3
+ export function createManagedWebContentsView(opts) {
4
+ let view = null;
5
+ let preloadOverride = null;
6
+ let runtimeAcquired = false;
7
+ function liveWebContents() {
8
+ const wc = view?.webContents;
9
+ if (!wc || wc.isDestroyed())
10
+ return null;
11
+ return wc;
12
+ }
13
+ // `liveWebContents()`'s `!wc.isDestroyed()` alone cannot tell "alive" from
14
+ // "alive but broken" — a crashed renderer process or a failed main-frame
15
+ // load leaves `webContents` non-destroyed but blank/unresponsive, so
16
+ // without this the same dead view (still fielding clicks if it's an
17
+ // on-screen slot) would be handed back to every future `ensureView()`
18
+ // forever, and the host's own `webContents` getter would keep reporting it
19
+ // as live. Guarded by `view !== current` so a listener from an already-
20
+ // superseded instance can't tear down the CURRENT one.
21
+ function teardown(current, detail) {
22
+ if (view !== current)
23
+ return;
24
+ console.error(`[${opts.viewId}] ${detail} — destroying so the next ensureView() rebuilds`);
25
+ view = null;
26
+ opts.reconciler.destroyView(opts.viewId, current);
27
+ opts.onBroken?.();
28
+ }
29
+ function ensureView() {
30
+ if (view && liveWebContents()) {
31
+ return view;
32
+ }
33
+ if (view) {
34
+ opts.reconciler.destroyView(opts.viewId, view);
35
+ }
36
+ if (!runtimeAcquired) {
37
+ opts.sessionRuntime.acquire();
38
+ runtimeAcquired = true;
39
+ }
40
+ const webPreferences = {
41
+ nodeIntegration: false,
42
+ contextIsolation: true,
43
+ sandbox: false,
44
+ additionalArguments: [opts.marker],
45
+ };
46
+ if (preloadOverride !== null) {
47
+ webPreferences.preload = preloadOverride;
48
+ }
49
+ const next = new WebContentsView({ webPreferences });
50
+ view = next;
51
+ opts.port.attach(next.webContents);
52
+ try {
53
+ next.setBackgroundColor('#121212');
54
+ }
55
+ catch {
56
+ /* stub may lack it */
57
+ }
58
+ try {
59
+ next.webContents.setWindowOpenHandler(({ url }) => handleWindowOpenExternal(url));
60
+ }
61
+ catch {
62
+ /* stub may lack it */
63
+ }
64
+ next.webContents.on('did-fail-load', (_event, errorCode, _errorDescription, _validatedURL, isMainFrame) => {
65
+ // -3 is ERR_ABORTED, which fires on every routine superseded navigation
66
+ // (e.g. a fresh loadURL/loadFile cancelling this one) — not a real failure.
67
+ if (!isMainFrame || errorCode === -3)
68
+ return;
69
+ teardown(next, `did-fail-load (code ${errorCode})`);
70
+ });
71
+ next.webContents.on('render-process-gone', (_event, details) => {
72
+ teardown(next, `render-process-gone (${details.reason})`);
73
+ });
74
+ return next;
75
+ }
76
+ return {
77
+ async loadURL(url) {
78
+ const v = ensureView();
79
+ // Invalidate SYNCHRONOUSLY at initiation, before the load is issued:
80
+ // the current document is about to be replaced, so a same-tick send()
81
+ // must report false instead of confirming delivery into it. The channel
82
+ // recovers on the new document's did-finish-load handshake. (Cannot
83
+ // rely on did-start-navigation here — that only covers page-initiated
84
+ // navigations once the load is actually under way.)
85
+ opts.port.invalidate();
86
+ await v.webContents.loadURL(url);
87
+ },
88
+ async loadFile(filePath) {
89
+ const v = ensureView();
90
+ // Same initiation-invalidates contract as loadURL above.
91
+ opts.port.invalidate();
92
+ await v.webContents.loadFile(filePath);
93
+ },
94
+ liveWebContents,
95
+ getView: () => view,
96
+ setPreloadPath(path) {
97
+ // The HOST's own webPreferences.preload, applied when the view is next
98
+ // (re)created. `null` = no host preload. The framework advertiser is
99
+ // session-resident and unaffected either way (see ensureView).
100
+ preloadOverride = path;
101
+ },
102
+ ensureView,
103
+ dispose() {
104
+ // Narrow channel first: close the live MessagePort + sweep the onMessage
105
+ // registry, so a send() racing teardown reports false instead of posting
106
+ // into a wc that is about to be closed.
107
+ opts.port.dispose();
108
+ // Host-controllable slot view: removed from the contentView + its
109
+ // WebContents closed (the host's loaded content is torn down on app exit).
110
+ opts.reconciler.destroyView(opts.viewId, view);
111
+ view = null;
112
+ // Release this manager's reference on the shared defaultSession
113
+ // slot-runtime registration (only if it ever acquired one — a manager
114
+ // that never used the slot must not drive the shared count to zero).
115
+ // The LAST release unregisters; other coexisting managers keep theirs.
116
+ if (runtimeAcquired) {
117
+ opts.sessionRuntime.release();
118
+ runtimeAcquired = false;
119
+ }
120
+ },
121
+ };
122
+ }
123
+ //# sourceMappingURL=managed-web-contents-view.js.map