Skip to content

Commit

Permalink
🐛 修复沙盒加载问题 #195
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Jun 2, 2023
1 parent 5405f6c commit 4e1c904
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/background.ts
Expand Up @@ -41,7 +41,6 @@ ListenerMessage(new LoggerDAO(), center);

IoC.instance(SystemConfig).init();

// 等待沙盒启动后再进行后续的步骤
IoC.instance(SystemManager).init();
// 资源管理器
const resourceManager = new ResourceManager(center);
Expand All @@ -66,6 +65,8 @@ window.onload = () => {
// eslint-disable-next-line no-undef
const sandboxConnect = new MessageSandbox(sandbox);
runtime.startSandbox(sandboxConnect);
// eslint-disable-next-line no-undef
center.setSandbox(sandbox);
};
center.setHandler("sandboxOnload", () => {
return Promise.resolve(true);
Expand Down
12 changes: 7 additions & 5 deletions src/sandbox.ts
Expand Up @@ -16,20 +16,22 @@ const loggerCore = new LoggerCore({
labels: { env: "sandbox" },
});

loggerCore.logger().debug("sandbox start");

IoC.instance(SandboxRuntime).init();

let flag = false;
// 为了确认能与background通讯
const retry = () => {
if (flag) {
return;
}
const t = setTimeout(() => {
retry();
}, 1000);
connectSandbox.syncSend("sandboxOnload", {}).then(() => {
clearTimeout(t);
flag = true;
loggerCore.logger().debug("sandbox start");
});
};

window.onload = () => {
retry();
};
retry();

0 comments on commit 4e1c904

Please sign in to comment.