CrashHandler: attempt to prevent more crashes

This commit is contained in:
Nuckyz 2023-11-29 16:14:05 -03:00
parent 9b6308a835
commit 091d29bf5e
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

View file

@ -24,11 +24,14 @@ import { closeAllModals } from "@utils/modal";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { maybePromptToUpdate } from "@utils/updater"; import { maybePromptToUpdate } from "@utils/updater";
import { findByPropsLazy } from "@webpack"; import { findByPropsLazy } from "@webpack";
import { FluxDispatcher, NavigationRouter } from "@webpack/common"; import { FluxDispatcher, NavigationRouter, SelectedChannelStore } from "@webpack/common";
import type { ReactElement } from "react"; import type { ReactElement } from "react";
const CrashHandlerLogger = new Logger("CrashHandler"); const CrashHandlerLogger = new Logger("CrashHandler");
const ModalStack = findByPropsLazy("pushLazy", "popAll"); const ModalStack = findByPropsLazy("pushLazy", "popAll");
const DraftManager = findByPropsLazy("clearDraft", "saveDraft");
const { DraftType } = findByPropsLazy("DraftType");
const { closeExpressionPicker } = findByPropsLazy("closeExpressionPicker", "openExpressionPicker");
const settings = definePluginSettings({ const settings = definePluginSettings({
attemptToPreventCrashes: { attemptToPreventCrashes: {
@ -115,6 +118,20 @@ export default definePlugin({
} catch { } } catch { }
} }
try {
const channelId = SelectedChannelStore.getChannelId();
DraftManager.clearDraft(channelId, DraftType.ChannelMessage);
DraftManager.clearDraft(channelId, DraftType.FirstThreadMessage);
} catch (err) {
CrashHandlerLogger.debug("Failed to clear drafts.", err);
}
try {
closeExpressionPicker();
}
catch (err) {
CrashHandlerLogger.debug("Failed to close expression picker.", err);
}
try { try {
FluxDispatcher.dispatch({ type: "CONTEXT_MENU_CLOSE" }); FluxDispatcher.dispatch({ type: "CONTEXT_MENU_CLOSE" });
} catch (err) { } catch (err) {