From 36892a27644d0c22e16fa272a0f001471964fd55 Mon Sep 17 00:00:00 2001 From: SimonShiki Date: Sun, 17 Sep 2023 11:28:55 +0000 Subject: [PATCH] :bug: fix: refreshBlock issues when sideloaded extensions Signed-off-by: SimonShiki --- package.json | 2 +- src/injector/inject.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8019e10..4b8a0c2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "chibi", "displayName": "Chibi", - "version": "0.0.1", + "version": "0.0.2", "description": "Load scratch extension everywhere.", "repository": "https://github.com/SimonShiki/chibi", "author": "SimonShiki", diff --git a/src/injector/inject.ts b/src/injector/inject.ts index 24fa817..4403480 100644 --- a/src/injector/inject.ts +++ b/src/injector/inject.ts @@ -62,7 +62,7 @@ export function inject (vm: ChibiCompatibleVM) { await loader.load(url, env as 'unsandboxed' | 'sandboxed'); const extensionId = loader.getIdByUrl(url); // @ts-expect-error internal hack - vm.extensionManager._loadedExtensions.set(extensionId, null); + vm.extensionManager._loadedExtensions.set(extensionId, 'Chibi'); } else { // @ts-expect-error internal hack return originalLoadFunc.apply(vm.extensionManager, [extensionURL, ...args]); @@ -76,6 +76,14 @@ export function inject (vm: ChibiCompatibleVM) { } }; + const originalRefreshBlocksFunc = vm.extensionManager.refreshBlocks; + vm.extensionManager.refreshBlocks = async function (...args: unknown[]) { + // @ts-expect-error internal hack + const result = await originalRefreshBlocksFunc.apply(vm.extensionManager, [...args]); + await window.chibi.loader.refreshBlocks(); + return result; + } + const originalToJSONFunc = vm.toJSON; vm.toJSON = function (optTargetId: string, ...args: unknown[]) { // @ts-expect-error internal hack