diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 7f89436..a46348f 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -35,7 +35,7 @@ function makeSettingsListenerHelpers(o: SettingsStore) { listeners.set(cb, path); o.addChangeListener(path, cb); }; - const removeListener = () => { + const removeAllListeners = () => { for (const [listener, path] of listeners) { o.removeChangeListener(path as any, listener); } @@ -43,7 +43,7 @@ function makeSettingsListenerHelpers(o: SettingsStore) { listeners.clear(); }; - return [addListener, removeListener] as const; + return [addListener, removeAllListeners] as const; } const [addSettingsListener, removeSettingsListeners] = makeSettingsListenerHelpers(Settings); diff --git a/src/renderer/patches/spellCheck.tsx b/src/renderer/patches/spellCheck.tsx index d6c0f51..91d34fa 100644 --- a/src/renderer/patches/spellCheck.tsx +++ b/src/renderer/patches/spellCheck.tsx @@ -22,14 +22,20 @@ addPatch({ find: ".enableSpellCheck)", replacement: { // if (isDesktop) { DiscordNative.onSpellcheck(openMenu(props)) } else { e.preventDefault(); openMenu(props) } - match: /else\{.{1,3}\.preventDefault\(\);(.{1,3}\(.{1,3}\))\}/, + match: /else\{(.{1,3})\.preventDefault\(\);(.{1,3}\(.{1,3}\))\}(?<=:(.{1,3})\.enableSpellCheck\).+?)/, // ... else { $self.onSlateContext(() => openMenu(props)) } - replace: "else {$self.onSlateContext(() => $1)}" + replace: "else {$self.onSlateContext($1, $3?.enableSpellCheck, () => $2)}" } } ], - onSlateContext(openMenu: () => void) { + onSlateContext(e: MouseEvent, hasSpellcheck: boolean | undefined, openMenu: () => void) { + if (!hasSpellcheck) { + e.preventDefault(); + openMenu(); + return; + } + const cb = (w: string, c: string[]) => { VencordDesktopNative.spellcheck.offSpellcheckResult(cb); word = w;