@dimina-kit/devtools 0.3.1-dev.20260513123738 → 0.3.1-dev.20260517100756
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +153 -82
- package/dist/main/api.d.ts +6 -2
- package/dist/main/api.js +5 -2
- package/dist/main/app/app.d.ts +1 -1
- package/dist/main/app/app.js +71 -36
- package/dist/main/app/launch.d.ts +2 -2
- package/dist/main/app/launch.js +6 -3
- package/dist/main/index.bundle.js +1074 -289
- package/dist/main/ipc/app.d.ts +2 -1
- package/dist/main/ipc/app.js +5 -4
- package/dist/main/ipc/index.d.ts +5 -4
- package/dist/main/ipc/index.js +5 -4
- package/dist/main/ipc/panels.d.ts +2 -1
- package/dist/main/ipc/panels.js +14 -9
- package/dist/main/ipc/popover.d.ts +4 -1
- package/dist/main/ipc/popover.js +15 -5
- package/dist/main/ipc/projects.d.ts +4 -1
- package/dist/main/ipc/projects.js +42 -5
- package/dist/main/ipc/session.d.ts +4 -1
- package/dist/main/ipc/session.js +26 -6
- package/dist/main/ipc/settings.d.ts +4 -1
- package/dist/main/ipc/settings.js +30 -17
- package/dist/main/ipc/simulator-module.d.ts +8 -0
- package/dist/main/ipc/simulator-module.js +19 -0
- package/dist/main/ipc/simulator.d.ts +2 -1
- package/dist/main/ipc/simulator.js +29 -15
- package/dist/main/ipc/toolbar.d.ts +2 -1
- package/dist/main/ipc/toolbar.js +3 -2
- package/dist/main/services/automation/index.js +88 -13
- package/dist/main/services/mcp/server.d.ts +2 -1
- package/dist/main/services/mcp/server.js +5 -0
- package/dist/main/services/module.d.ts +18 -0
- package/dist/main/services/module.js +2 -0
- package/dist/main/services/notifications/renderer-notifier.d.ts +2 -0
- package/dist/main/services/projects/project-repository.d.ts +1 -0
- package/dist/main/services/projects/project-repository.js +3 -0
- package/dist/main/services/settings/index.d.ts +4 -0
- package/dist/main/services/settings/index.js +12 -1
- package/dist/main/services/simulator/custom-apis.d.ts +10 -0
- package/dist/main/services/simulator/custom-apis.js +26 -0
- package/dist/main/services/simulator-storage/index.d.ts +22 -1
- package/dist/main/services/simulator-storage/index.js +365 -98
- package/dist/main/services/update/update-manager.d.ts +16 -1
- package/dist/main/services/update/update-manager.js +18 -15
- package/dist/main/services/views/view-manager.d.ts +4 -0
- package/dist/main/services/views/view-manager.js +33 -2
- package/dist/main/services/window-service.d.ts +24 -0
- package/dist/main/services/window-service.js +26 -0
- package/dist/main/services/workbench-context.d.ts +15 -0
- package/dist/main/services/workbench-context.js +6 -0
- package/dist/main/services/workspace/workspace-service.d.ts +1 -0
- package/dist/main/services/workspace/workspace-service.js +7 -3
- package/dist/main/simulator-apis.d.ts +23 -0
- package/dist/main/simulator-apis.js +24 -0
- package/dist/main/utils/disposable.d.ts +13 -0
- package/dist/main/utils/disposable.js +60 -0
- package/dist/main/utils/ipc-registry.d.ts +39 -0
- package/dist/main/utils/ipc-registry.js +109 -0
- package/dist/main/utils/ipc-schema.d.ts +28 -0
- package/dist/main/utils/ipc-schema.js +38 -0
- package/dist/main/utils/paths.d.ts +6 -0
- package/dist/main/utils/paths.js +6 -0
- package/dist/main/utils/sender-policy.d.ts +23 -0
- package/dist/main/utils/sender-policy.js +42 -0
- package/dist/main/windows/main-window/create.d.ts +6 -0
- package/dist/main/windows/main-window/create.js +65 -9
- package/dist/main/windows/main-window/events.d.ts +2 -1
- package/dist/main/windows/main-window/events.js +25 -2
- package/dist/main/windows/navigation-hardening.d.ts +24 -0
- package/dist/main/windows/navigation-hardening.js +55 -0
- package/dist/main/windows/settings-window/create.js +11 -1
- package/dist/preload/index.d.ts +19 -0
- package/dist/preload/index.js +18 -0
- package/dist/preload/instrumentation/app-data.js +178 -19
- package/dist/preload/runtime/custom-apis.d.ts +6 -0
- package/dist/preload/runtime/custom-apis.js +18 -0
- package/dist/preload/runtime/host.d.ts +1 -0
- package/dist/preload/runtime/host.js +13 -0
- package/dist/preload/windows/main.cjs +47 -0
- package/dist/preload/windows/main.cjs.map +7 -0
- package/dist/preload/windows/simulator.js +174 -18
- package/dist/renderer/assets/index-DW_0thr-.js +46 -0
- package/dist/renderer/assets/{input-DxfYnzX_.js → input-C5M5Wxn6.js} +2 -2
- package/dist/renderer/assets/{ipc-transport-ClIvDcYY.js → ipc-transport-CUsl-fS2.js} +2 -2
- package/dist/renderer/assets/ipc-transport-CltRuvhi.css +1 -0
- package/dist/renderer/assets/{popover-CtXcBJtM.js → popover-BSBPVO0o.js} +2 -2
- package/dist/renderer/assets/{select-DMfp49f1.js → select-B1tF3UAc.js} +2 -2
- package/dist/renderer/assets/{settings-DteGraEU.js → settings-7w54H6p-.js} +2 -2
- package/dist/renderer/assets/settings-api-BjJalghB.js +2 -0
- package/dist/renderer/assets/workbenchSettings-q2_-nc8t.js +8 -0
- package/dist/renderer/entries/main/index.html +12 -5
- package/dist/renderer/entries/popover/index.html +7 -5
- package/dist/renderer/entries/settings/index.html +7 -5
- package/dist/renderer/entries/workbench-settings/index.html +6 -4
- package/dist/shared/ipc-channels.d.ts +22 -0
- package/dist/shared/ipc-channels.js +23 -0
- package/dist/shared/ipc-schemas.d.ts +113 -0
- package/dist/shared/ipc-schemas.js +128 -0
- package/dist/shared/types.d.ts +2 -0
- package/dist/simulator/assets/simulator-DL6kOCq-.js +9 -0
- package/dist/simulator/simulator.html +1 -1
- package/package.json +11 -27
- package/dist/preload/windows/main.d.ts +0 -6
- package/dist/preload/windows/main.js +0 -6
- package/dist/renderer/assets/index-D1p6crtf.js +0 -46
- package/dist/renderer/assets/ipc-transport-EiWxu_hG.css +0 -1
- package/dist/renderer/assets/settings-api-CY84UMpN.js +0 -2
- package/dist/renderer/assets/workbenchSettings-DjELLnSJ.js +0 -8
- package/dist/simulator/assets/simulator-C1eHXnuq.js +0 -9
|
@@ -2,6 +2,19 @@ import { ipcRenderer } from 'electron';
|
|
|
2
2
|
export function sendToHost(channel, data) {
|
|
3
3
|
ipcRenderer.sendToHost(channel, data);
|
|
4
4
|
}
|
|
5
|
+
export function onHostMessage(channel, handler) {
|
|
6
|
+
let active = true;
|
|
7
|
+
const wrapped = (_event, ...args) => {
|
|
8
|
+
if (!active)
|
|
9
|
+
return;
|
|
10
|
+
handler(...args);
|
|
11
|
+
};
|
|
12
|
+
ipcRenderer.on(channel, wrapped);
|
|
13
|
+
return () => {
|
|
14
|
+
active = false;
|
|
15
|
+
ipcRenderer.removeListener(channel, wrapped);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
5
18
|
export function safeSerialize(val) {
|
|
6
19
|
if (val === null || val === undefined)
|
|
7
20
|
return val;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/preload/windows/main.ts
|
|
17
|
+
var main_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(main_exports);
|
|
19
|
+
var import_electron = require("electron");
|
|
20
|
+
var api = {
|
|
21
|
+
ipc: {
|
|
22
|
+
invoke: (channel, ...args) => import_electron.ipcRenderer.invoke(channel, ...args),
|
|
23
|
+
send: (channel, ...args) => {
|
|
24
|
+
import_electron.ipcRenderer.send(channel, ...args);
|
|
25
|
+
},
|
|
26
|
+
on: (channel, listener) => {
|
|
27
|
+
import_electron.ipcRenderer.on(channel, listener);
|
|
28
|
+
return () => import_electron.ipcRenderer.removeListener(channel, listener);
|
|
29
|
+
},
|
|
30
|
+
once: (channel, listener) => {
|
|
31
|
+
import_electron.ipcRenderer.once(channel, listener);
|
|
32
|
+
},
|
|
33
|
+
removeListener: (channel, listener) => {
|
|
34
|
+
import_electron.ipcRenderer.removeListener(channel, listener);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
import_electron.contextBridge.exposeInMainWorld("devtools", api);
|
|
39
|
+
if (process.env.NODE_ENV === "test") {
|
|
40
|
+
import_electron.contextBridge.exposeInMainWorld("__testIpc", {
|
|
41
|
+
emit: (channel, ...args) => {
|
|
42
|
+
;
|
|
43
|
+
import_electron.ipcRenderer.emit(channel, ...args);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=main.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/preload/windows/main.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Preload bridge for the main window, settings window, settings overlay\n * view, and popover overlay view. Exposes a minimal, typed `window.devtools`\n * surface so the renderer never has to call `window.require('electron')`.\n *\n * This file is bundled by esbuild to CJS at `dist/preload/windows/main.js`\n * (see package.json `build:preload`). It must remain a leaf module \u2014 do\n * NOT import other preload files via `.js` ESM specifiers; everything goes\n * through the Electron `contextBridge` / `ipcRenderer` runtime.\n *\n * Channel governance lives in the main process: `sender-policy.ts` plus the\n * per-handler zod schemas decide what's accepted. The preload layer is a\n * thin pass-through \u2014 a renderer inventing channel names will just hit a\n * main-side rejection, so duplicating an allowlist here added no real\n * defense for a devtool that loads user-trusted mini-programs.\n */\nimport { contextBridge, ipcRenderer, type IpcRendererEvent } from 'electron'\n\nconst api = {\n ipc: {\n invoke: (channel: string, ...args: unknown[]) => ipcRenderer.invoke(channel, ...args),\n send: (channel: string, ...args: unknown[]) => {\n ipcRenderer.send(channel, ...args)\n },\n on: (\n channel: string,\n listener: (event: IpcRendererEvent, ...args: unknown[]) => void,\n ) => {\n ipcRenderer.on(channel, listener)\n return () => ipcRenderer.removeListener(channel, listener)\n },\n once: (\n channel: string,\n listener: (event: IpcRendererEvent, ...args: unknown[]) => void,\n ) => {\n ipcRenderer.once(channel, listener)\n },\n removeListener: (\n channel: string,\n listener: (...args: unknown[]) => void,\n ) => {\n ipcRenderer.removeListener(channel, listener)\n },\n },\n}\n\n// All host windows that load this preload run with `contextIsolation: true`\n// (main / settings / view-manager), so `contextBridge` is the path that\n// reaches the renderer's `window`. The simulator <webview> uses a separate\n// preload (`simulator.ts`).\ncontextBridge.exposeInMainWorld('devtools', api)\n\n// Test-only hatch: e2e helpers emit synthetic IPC events on the renderer's\n// ipcRenderer instance to trigger handlers registered via `devtools.ipc.on`\n// without round-tripping through the main process. Gated on NODE_ENV so\n// production builds never expose it.\nif (process.env.NODE_ENV === 'test') {\n contextBridge.exposeInMainWorld('__testIpc', {\n emit: (channel: string, ...args: unknown[]) => {\n ;(ipcRenderer as unknown as { emit: (c: string, ...a: unknown[]) => void }).emit(channel, ...args)\n },\n })\n}\n\nexport type DevtoolsApi = typeof api\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAgBA,sBAAkE;AAElE,IAAM,MAAM;AAAA,EACV,KAAK;AAAA,IACH,QAAQ,CAAC,YAAoB,SAAoB,4BAAY,OAAO,SAAS,GAAG,IAAI;AAAA,IACpF,MAAM,CAAC,YAAoB,SAAoB;AAC7C,kCAAY,KAAK,SAAS,GAAG,IAAI;AAAA,IACnC;AAAA,IACA,IAAI,CACF,SACA,aACG;AACH,kCAAY,GAAG,SAAS,QAAQ;AAChC,aAAO,MAAM,4BAAY,eAAe,SAAS,QAAQ;AAAA,IAC3D;AAAA,IACA,MAAM,CACJ,SACA,aACG;AACH,kCAAY,KAAK,SAAS,QAAQ;AAAA,IACpC;AAAA,IACA,gBAAgB,CACd,SACA,aACG;AACH,kCAAY,eAAe,SAAS,QAAQ;AAAA,IAC9C;AAAA,EACF;AACF;AAMA,8BAAc,kBAAkB,YAAY,GAAG;AAM/C,IAAI,QAAQ,IAAI,aAAa,QAAQ;AACnC,gCAAc,kBAAkB,aAAa;AAAA,IAC3C,MAAM,CAAC,YAAoB,SAAoB;AAC7C;AAAC,MAAC,4BAA0E,KAAK,SAAS,GAAG,IAAI;AAAA,IACnG;AAAA,EACF,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -173,6 +173,9 @@ function installSimulatorBridge() {
|
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
// src/preload/runtime/custom-apis.ts
|
|
177
|
+
var import_electron2 = require("electron");
|
|
178
|
+
|
|
176
179
|
// src/shared/ipc-channels.ts
|
|
177
180
|
var SimulatorChannel = {
|
|
178
181
|
Attach: "simulator:attach",
|
|
@@ -184,11 +187,48 @@ var SimulatorChannel = {
|
|
|
184
187
|
AppData: "simulator:appdata",
|
|
185
188
|
AppDataAll: "simulator:appdata-all"
|
|
186
189
|
};
|
|
190
|
+
var SimulatorCustomApiChannel = {
|
|
191
|
+
List: "simulator:custom-apis:list",
|
|
192
|
+
Invoke: "simulator:custom-apis:invoke"
|
|
193
|
+
};
|
|
194
|
+
var BridgeChannel = {
|
|
195
|
+
WxmlRefreshRequest: "wxml:refresh:request",
|
|
196
|
+
AppDataGetAllRequest: "appdata:getAll:request",
|
|
197
|
+
AppDataGetAllResponse: "appdata:getAll:response"
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// src/preload/runtime/custom-apis.ts
|
|
201
|
+
function buildBridge() {
|
|
202
|
+
return {
|
|
203
|
+
list: () => import_electron2.ipcRenderer.invoke(SimulatorCustomApiChannel.List),
|
|
204
|
+
invoke: (name, params) => import_electron2.ipcRenderer.invoke(SimulatorCustomApiChannel.Invoke, name, params)
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function installCustomApisBridge() {
|
|
208
|
+
const bridge = buildBridge();
|
|
209
|
+
try {
|
|
210
|
+
import_electron2.contextBridge.exposeInMainWorld("__diminaCustomApis", bridge);
|
|
211
|
+
} catch {
|
|
212
|
+
window.__diminaCustomApis = bridge;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
187
215
|
|
|
188
216
|
// src/preload/runtime/host.ts
|
|
189
|
-
var
|
|
217
|
+
var import_electron3 = require("electron");
|
|
190
218
|
function sendToHost(channel, data) {
|
|
191
|
-
|
|
219
|
+
import_electron3.ipcRenderer.sendToHost(channel, data);
|
|
220
|
+
}
|
|
221
|
+
function onHostMessage(channel, handler) {
|
|
222
|
+
let active = true;
|
|
223
|
+
const wrapped = (_event, ...args) => {
|
|
224
|
+
if (!active) return;
|
|
225
|
+
handler(...args);
|
|
226
|
+
};
|
|
227
|
+
import_electron3.ipcRenderer.on(channel, wrapped);
|
|
228
|
+
return () => {
|
|
229
|
+
active = false;
|
|
230
|
+
import_electron3.ipcRenderer.removeListener(channel, wrapped);
|
|
231
|
+
};
|
|
192
232
|
}
|
|
193
233
|
function safeSerialize(val) {
|
|
194
234
|
if (val === null || val === void 0) return val;
|
|
@@ -272,13 +312,46 @@ function createDisposableSet() {
|
|
|
272
312
|
|
|
273
313
|
// src/preload/instrumentation/app-data.ts
|
|
274
314
|
var appDataCache = /* @__PURE__ */ new Map();
|
|
315
|
+
var bridgeOrder = [];
|
|
316
|
+
var bridgePagePath = /* @__PURE__ */ new Map();
|
|
317
|
+
function recordBridge(bridgeId) {
|
|
318
|
+
if (!bridgeOrder.includes(bridgeId)) bridgeOrder.push(bridgeId);
|
|
319
|
+
}
|
|
320
|
+
function buildSnapshot() {
|
|
321
|
+
const bridges = [];
|
|
322
|
+
for (const id of bridgeOrder) {
|
|
323
|
+
bridges.push({ id, pagePath: bridgePagePath.get(id) ?? null });
|
|
324
|
+
}
|
|
325
|
+
const entries = {};
|
|
326
|
+
for (const [key, entry] of appDataCache) {
|
|
327
|
+
const slash = key.indexOf("/");
|
|
328
|
+
if (slash < 0) continue;
|
|
329
|
+
const bridgeId = key.slice(0, slash);
|
|
330
|
+
const moduleId = key.slice(slash + 1);
|
|
331
|
+
if (!entries[bridgeId]) entries[bridgeId] = {};
|
|
332
|
+
const displayKey = entry.componentPath ?? moduleId;
|
|
333
|
+
entries[bridgeId][displayKey] = entry.data;
|
|
334
|
+
}
|
|
335
|
+
return { bridges, entries };
|
|
336
|
+
}
|
|
275
337
|
function publishSnapshot() {
|
|
276
338
|
const data = {};
|
|
277
|
-
for (const [key,
|
|
278
|
-
data[key] =
|
|
339
|
+
for (const [key, entry] of appDataCache) {
|
|
340
|
+
data[key] = entry.data;
|
|
279
341
|
}
|
|
280
342
|
setAppDataSnapshot(data);
|
|
281
343
|
}
|
|
344
|
+
function clearBridge(bridgeId) {
|
|
345
|
+
const prefix = `${bridgeId}/`;
|
|
346
|
+
for (const key of [...appDataCache.keys()]) {
|
|
347
|
+
if (key.startsWith(prefix)) appDataCache.delete(key);
|
|
348
|
+
}
|
|
349
|
+
const idx = bridgeOrder.indexOf(bridgeId);
|
|
350
|
+
if (idx >= 0) bridgeOrder.splice(idx, 1);
|
|
351
|
+
bridgePagePath.delete(bridgeId);
|
|
352
|
+
publishSnapshot();
|
|
353
|
+
sendToHost(SimulatorChannel.AppDataAll, buildSnapshot());
|
|
354
|
+
}
|
|
282
355
|
function decodeWorkerMessage(message) {
|
|
283
356
|
let payload = message;
|
|
284
357
|
if (typeof payload === "string") {
|
|
@@ -288,9 +361,61 @@ function decodeWorkerMessage(message) {
|
|
|
288
361
|
return null;
|
|
289
362
|
}
|
|
290
363
|
}
|
|
364
|
+
if (!payload || typeof payload !== "object") return null;
|
|
291
365
|
const record = payload;
|
|
292
|
-
if (record
|
|
293
|
-
|
|
366
|
+
if (record.type === "ub") {
|
|
367
|
+
const body = record.body;
|
|
368
|
+
if (!body || typeof body !== "object") return null;
|
|
369
|
+
if (typeof body.bridgeId !== "string" || !Array.isArray(body.updates)) return null;
|
|
370
|
+
const out = [];
|
|
371
|
+
for (const u of body.updates) {
|
|
372
|
+
if (!u || typeof u.moduleId !== "string") continue;
|
|
373
|
+
if (!u.moduleId.startsWith("page_")) continue;
|
|
374
|
+
out.push({ mode: "patch", bridgeId: body.bridgeId, moduleId: u.moduleId, data: u.data });
|
|
375
|
+
}
|
|
376
|
+
return out.length > 0 ? out : null;
|
|
377
|
+
}
|
|
378
|
+
if (typeof record.type === "string" && record.type.startsWith("page_")) {
|
|
379
|
+
const body = record.body;
|
|
380
|
+
if (!body || typeof body !== "object") return null;
|
|
381
|
+
if (typeof body.bridgeId !== "string" || typeof body.path !== "string") return null;
|
|
382
|
+
if (!body.data || typeof body.data !== "object") return null;
|
|
383
|
+
return [{
|
|
384
|
+
mode: "init",
|
|
385
|
+
bridgeId: body.bridgeId,
|
|
386
|
+
moduleId: record.type,
|
|
387
|
+
componentPath: body.path,
|
|
388
|
+
data: body.data
|
|
389
|
+
}];
|
|
390
|
+
}
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
function decodeOutgoingMessage(message) {
|
|
394
|
+
let payload = message;
|
|
395
|
+
if (typeof payload === "string") {
|
|
396
|
+
try {
|
|
397
|
+
payload = JSON.parse(payload);
|
|
398
|
+
} catch {
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (!payload || typeof payload !== "object") return null;
|
|
403
|
+
const r = payload;
|
|
404
|
+
if (typeof r.type !== "string") return null;
|
|
405
|
+
return {
|
|
406
|
+
type: r.type,
|
|
407
|
+
bridgeId: typeof r.body?.bridgeId === "string" ? r.body.bridgeId : void 0
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function instrumentPostMessage(worker) {
|
|
411
|
+
const orig = worker.postMessage.bind(worker);
|
|
412
|
+
worker.postMessage = function(msg, ...rest) {
|
|
413
|
+
const decoded = decodeOutgoingMessage(msg);
|
|
414
|
+
if (decoded?.type === "pageUnload" && decoded.bridgeId) {
|
|
415
|
+
clearBridge(decoded.bridgeId);
|
|
416
|
+
}
|
|
417
|
+
return orig(msg, ...rest);
|
|
418
|
+
};
|
|
294
419
|
}
|
|
295
420
|
function createInstrumentedWorker(OriginalWorker) {
|
|
296
421
|
function InstrumentedWorker(scriptURL, options) {
|
|
@@ -300,14 +425,20 @@ function createInstrumentedWorker(OriginalWorker) {
|
|
|
300
425
|
[resolvedScriptURL, options],
|
|
301
426
|
new.target ?? InstrumentedWorker
|
|
302
427
|
);
|
|
428
|
+
instrumentPostMessage(worker);
|
|
303
429
|
worker.addEventListener("message", (event) => {
|
|
304
|
-
const
|
|
305
|
-
if (!
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
430
|
+
const entries = decodeWorkerMessage(event.data);
|
|
431
|
+
if (!entries) return;
|
|
432
|
+
for (const entry of entries) {
|
|
433
|
+
const hookBody = {
|
|
434
|
+
bridgeId: entry.bridgeId,
|
|
435
|
+
moduleId: entry.moduleId,
|
|
436
|
+
data: entry.data,
|
|
437
|
+
mode: entry.mode
|
|
438
|
+
};
|
|
439
|
+
if (entry.mode === "init") hookBody.componentPath = entry.componentPath;
|
|
440
|
+
window.__simulatorHook?.appData(hookBody);
|
|
441
|
+
}
|
|
311
442
|
});
|
|
312
443
|
return worker;
|
|
313
444
|
}
|
|
@@ -325,12 +456,27 @@ function installAppDataInstrumentation() {
|
|
|
325
456
|
window.__simulatorHook = {
|
|
326
457
|
appData: (body) => {
|
|
327
458
|
const record = body;
|
|
328
|
-
if (record?.bridgeId
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
459
|
+
if (!record?.bridgeId || !record?.moduleId) return;
|
|
460
|
+
if (record.mode !== "init" && !bridgePagePath.has(record.bridgeId)) return;
|
|
461
|
+
const key = `${record.bridgeId}/${record.moduleId}`;
|
|
462
|
+
const prev = appDataCache.get(key);
|
|
463
|
+
const incoming = record.data && typeof record.data === "object" ? record.data : {};
|
|
464
|
+
const merged = record.mode === "init" ? { ...incoming } : { ...prev?.data ?? {}, ...incoming };
|
|
465
|
+
const componentPath = record.componentPath ?? prev?.componentPath;
|
|
466
|
+
const next = componentPath !== void 0 ? { componentPath, data: merged } : { data: merged };
|
|
467
|
+
appDataCache.set(key, next);
|
|
468
|
+
recordBridge(record.bridgeId);
|
|
469
|
+
if (record.mode === "init" && record.moduleId.startsWith("page_") && record.componentPath) {
|
|
470
|
+
bridgePagePath.set(record.bridgeId, record.componentPath);
|
|
332
471
|
}
|
|
333
|
-
|
|
472
|
+
publishSnapshot();
|
|
473
|
+
const payload = {
|
|
474
|
+
bridgeId: record.bridgeId,
|
|
475
|
+
moduleId: record.moduleId,
|
|
476
|
+
data: merged
|
|
477
|
+
};
|
|
478
|
+
if (componentPath !== void 0) payload.componentPath = componentPath;
|
|
479
|
+
sendToHost(SimulatorChannel.AppData, payload);
|
|
334
480
|
}
|
|
335
481
|
};
|
|
336
482
|
Object.defineProperty(window, "Worker", {
|
|
@@ -338,6 +484,9 @@ function installAppDataInstrumentation() {
|
|
|
338
484
|
writable: true,
|
|
339
485
|
value: createInstrumentedWorker(OriginalWorker)
|
|
340
486
|
});
|
|
487
|
+
disposables2.add(
|
|
488
|
+
onHostMessage(BridgeChannel.AppDataGetAllRequest, () => sendAllAppData())
|
|
489
|
+
);
|
|
341
490
|
publishSnapshot();
|
|
342
491
|
disposables2.add(() => {
|
|
343
492
|
if (originalDescriptor) {
|
|
@@ -355,6 +504,8 @@ function installAppDataInstrumentation() {
|
|
|
355
504
|
});
|
|
356
505
|
disposables2.add(() => {
|
|
357
506
|
appDataCache.clear();
|
|
507
|
+
bridgeOrder.length = 0;
|
|
508
|
+
bridgePagePath.clear();
|
|
358
509
|
clearAppDataSnapshot();
|
|
359
510
|
publishSnapshot();
|
|
360
511
|
});
|
|
@@ -362,6 +513,10 @@ function installAppDataInstrumentation() {
|
|
|
362
513
|
disposables2.disposeAll();
|
|
363
514
|
};
|
|
364
515
|
}
|
|
516
|
+
function sendAllAppData() {
|
|
517
|
+
publishSnapshot();
|
|
518
|
+
sendToHost(SimulatorChannel.AppDataAll, buildSnapshot());
|
|
519
|
+
}
|
|
365
520
|
|
|
366
521
|
// src/preload/shared/constants.ts
|
|
367
522
|
var WXML_DEBOUNCE_MS = 300;
|
|
@@ -948,6 +1103,7 @@ function setupApiCompatHook() {
|
|
|
948
1103
|
// src/preload/windows/simulator.ts
|
|
949
1104
|
setupApiCompatHook();
|
|
950
1105
|
installSimulatorBridge();
|
|
1106
|
+
installCustomApisBridge();
|
|
951
1107
|
installConsoleInstrumentation();
|
|
952
1108
|
installAppDataInstrumentation();
|
|
953
1109
|
installWxmlInstrumentation();
|