From d5420959938865aa9cf81ab7abc7a7d49a31ecd5 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 13 May 2025 21:34:11 +0200 Subject: [PATCH] fix ContextMenus on canary --- src/webpack/common/menu.ts | 11 +++++++---- src/webpack/patchWebpack.ts | 14 ++++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/webpack/common/menu.ts b/src/webpack/common/menu.ts index 9896b3a2..e77b5456 100644 --- a/src/webpack/common/menu.ts +++ b/src/webpack/common/menu.ts @@ -27,10 +27,13 @@ waitFor(m => m.name === "MenuCheckboxItem", (_, id) => { // we have to do this manual require by ID because m is in this case the MenuCheckBoxItem instead of the entire module const module = wreq(id); - for (const e of Object.values(module)) { - if (typeof e === "function" && e.name.startsWith("Menu")) { - Menu[e.name] = e; - } + for (const key in module) { + try { + const e = module[key]; + if (typeof e === "function" && e.name.startsWith("Menu")) { + Menu[e.name] = e; + } + } catch { } } }); diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index a542cb9b..3186b503 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -445,13 +445,15 @@ function runFactoryWithWrap(patchedFactory: PatchedModuleFactory, thisArg: unkno } for (const exportKey in exports) { - const exportValue = exports[exportKey]; + try { + const exportValue = exports[exportKey]; - if (exportValue != null && filter(exportValue)) { - waitForSubscriptions.delete(filter); - callback(exportValue, module.id); - break; - } + if (exportValue != null && filter(exportValue)) { + waitForSubscriptions.delete(filter); + callback(exportValue, module.id); + break; + } + } catch { } } } catch (err) { logger.error("Error while firing callback for Webpack waitFor subscription:\n", err, filter, callback);