Skip to content

Commit 4e1c904

Browse files
committed
🐛 修复沙盒加载问题 #195
1 parent 5405f6c commit 4e1c904

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/background.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ ListenerMessage(new LoggerDAO(), center);
4141

4242
IoC.instance(SystemConfig).init();
4343

44-
// 等待沙盒启动后再进行后续的步骤
4544
IoC.instance(SystemManager).init();
4645
// 资源管理器
4746
const resourceManager = new ResourceManager(center);
@@ -66,6 +65,8 @@ window.onload = () => {
6665
// eslint-disable-next-line no-undef
6766
const sandboxConnect = new MessageSandbox(sandbox);
6867
runtime.startSandbox(sandboxConnect);
68+
// eslint-disable-next-line no-undef
69+
center.setSandbox(sandbox);
6970
};
7071
center.setHandler("sandboxOnload", () => {
7172
return Promise.resolve(true);

src/sandbox.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,22 @@ const loggerCore = new LoggerCore({
1616
labels: { env: "sandbox" },
1717
});
1818

19-
loggerCore.logger().debug("sandbox start");
20-
2119
IoC.instance(SandboxRuntime).init();
2220

21+
let flag = false;
2322
// 为了确认能与background通讯
2423
const retry = () => {
24+
if (flag) {
25+
return;
26+
}
2527
const t = setTimeout(() => {
2628
retry();
2729
}, 1000);
2830
connectSandbox.syncSend("sandboxOnload", {}).then(() => {
2931
clearTimeout(t);
32+
flag = true;
33+
loggerCore.logger().debug("sandbox start");
3034
});
3135
};
3236

33-
window.onload = () => {
34-
retry();
35-
};
37+
retry();

0 commit comments

Comments
 (0)