Prevent closing the crash dialog

Closes #1115
This commit is contained in:
Keavon Chambers 2023-04-27 13:37:39 -07:00
parent 44c26f1570
commit 0af42ee6f9
3 changed files with 18 additions and 19 deletions

View file

@ -13,12 +13,8 @@
let self: FloatingMenu | undefined;
export function dismiss() {
dialog.dismissDialog();
}
onMount(() => {
// Focus the first button in the popup
// Focus the button which is marked as emphasized, or otherwise the first button, in the popup
const emphasizedOrFirstButton = (self?.div()?.querySelector("[data-emphasized]") || self?.div()?.querySelector("[data-text-button]") || undefined) as HTMLButtonElement | undefined;
emphasizedOrFirstButton?.focus();
});
@ -34,9 +30,9 @@
{#if $dialog.widgets.layout.length > 0}
<WidgetLayout layout={$dialog.widgets} class="details" />
{/if}
{#if ($dialog.jsCallbackBasedButtons?.length || NaN) > 0}
{#if ($dialog.crashDialogButtons?.length || NaN) > 0}
<LayoutRow class="panic-buttons-row">
{#each $dialog.jsCallbackBasedButtons || [] as button, index (index)}
{#each $dialog.crashDialogButtons || [] as button, index (index)}
<TextButton action={() => button.callback?.()} {...button.props} />
{/each}
</LayoutRow>

View file

@ -19,12 +19,12 @@ export function createPanicManager(editor: Editor, dialogState: DialogState): vo
// eslint-disable-next-line no-console
console.error(panicDetails);
const panicDialog = preparePanicDialog(displayDialogPanic.header, displayDialogPanic.description, panicDetails);
dialogState.createPanicDialog(...panicDialog);
const crashDialog = prepareCrashDialog(displayDialogPanic.header, displayDialogPanic.description, panicDetails);
dialogState.createCrashDialog(...crashDialog);
});
}
function preparePanicDialog(header: string, details: string, panicDetails: string): [IconName, WidgetLayout, TextButtonWidget[]] {
function prepareCrashDialog(header: string, details: string, panicDetails: string): [IconName, WidgetLayout, TextButtonWidget[]] {
const headerLabel: TextLabel = { kind: "TextLabel", value: header, disabled: false, bold: true, italic: false, tableAlign: false, minWidth: 0, multiline: false, tooltip: "" };
const detailsLabel: TextLabel = { kind: "TextLabel", value: details, disabled: false, bold: false, italic: false, tableAlign: false, minWidth: 0, multiline: true, tooltip: "" };
@ -52,9 +52,9 @@ function preparePanicDialog(header: string, details: string, panicDetails: strin
},
props: { kind: "TextButton", label: "Clear Saved Data", emphasized: false, minWidth: 96 },
};
const jsCallbackBasedButtons = [reloadButton, copyErrorLogButton, reportOnGithubButton, clearPersistedDataButton];
const crashDialogButtons = [reloadButton, copyErrorLogButton, reportOnGithubButton, clearPersistedDataButton];
return ["Warning", widgets, jsCallbackBasedButtons];
return ["Warning", widgets, crashDialogButtons];
}
function githubUrl(panicDetails: string): string {

View file

@ -11,24 +11,27 @@ export function createDialogState(editor: Editor) {
icon: "" as IconName,
widgets: defaultWidgetLayout(),
// Special case for the crash dialog because we cannot handle button widget callbacks from Rust once the editor instance has panicked
jsCallbackBasedButtons: undefined as undefined | TextButtonWidget[],
crashDialogButtons: undefined as undefined | TextButtonWidget[],
});
function dismissDialog(): void {
update((state) => {
state.visible = false;
// Disallow dismissing the crash dialog since it can confuse users why the app stopped responding if they dismiss it without realizing what it means
if (!state.crashDialogButtons) state.visible = false;
return state;
});
}
// Creates a panic dialog from JS.
// Creates a crash dialog from JS once the editor has panicked.
// Normal dialogs are created in the Rust backend, but for the crash dialog, the editor instance has panicked so it cannot respond to widget callbacks.
function createPanicDialog(icon: IconName, widgets: WidgetLayout, jsCallbackBasedButtons: TextButtonWidget[]): void {
function createCrashDialog(icon: IconName, widgets: WidgetLayout, crashDialogButtons: TextButtonWidget[]): void {
update((state) => {
state.visible = true;
state.icon = icon;
state.widgets = widgets;
state.jsCallbackBasedButtons = jsCallbackBasedButtons;
state.crashDialogButtons = crashDialogButtons;
return state;
});
}
@ -45,7 +48,7 @@ export function createDialogState(editor: Editor) {
update((state) => {
patchWidgetLayout(state.widgets, updateDialogDetails);
state.jsCallbackBasedButtons = undefined;
state.crashDialogButtons = undefined;
return state;
});
});
@ -54,7 +57,7 @@ export function createDialogState(editor: Editor) {
return {
subscribe,
dismissDialog,
createPanicDialog,
createCrashDialog: createCrashDialog,
};
}
export type DialogState = ReturnType<typeof createDialogState>;