Skip to content

The swiss army knife of lossless video/audio editing

replace all window.confirm

Mikael Finstad25111741e131
diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx
index 99bbce87..8efe3ea2 100644
--- a/src/renderer/src/App.tsx
+++ b/src/renderer/src/App.tsx
@@ -772,22 +772,20 @@ function App() {
}
}, [commandedTimeRef, cutSegments, findSegmentsAtCursor, pause, playbackModeRef, playerTime, playingRef, seekAbs, selectedSegments, setCurrentSegIndex, setPlaybackMode, setPlayerTime]);
- const closeFileWithConfirm = useCallback(() => {
+ const closeFileWithConfirm = useCallback(async () => {
if (!isFileOpened || workingRef.current) return;
- // eslint-disable-next-line no-alert
- if (askBeforeClose && !window.confirm(i18n.t('Are you sure you want to close the current file?'))) return;
+ if (askBeforeClose && !(await confirmDialog({ focusConfirm: true, description: i18n.t('Are you sure you want to close the current file?') }))) return;
resetState();
clearSegments();
- }, [isFileOpened, workingRef, askBeforeClose, resetState, clearSegments]);
+ }, [isFileOpened, workingRef, askBeforeClose, confirmDialog, resetState, clearSegments]);
- const closeBatch = useCallback(() => {
- // eslint-disable-next-line no-alert
- if (askBeforeClose && !window.confirm(i18n.t('Are you sure you want to close the loaded batch of files?'))) return;
+ const closeBatch = useCallback(async () => {
+ if (askBeforeClose && !(await confirmDialog({ focusConfirm: true, description: i18n.t('Are you sure you want to close the loaded batch of files?') }))) return;
setBatchFiles([]);
setSelectedBatchFiles([]);
- }, [askBeforeClose]);
+ }, [askBeforeClose, confirmDialog]);
const batchListRemoveFile = useCallback((path: string | undefined) => {
setBatchFiles((existingBatch) => {
@@ -2360,9 +2358,10 @@ function App() {
setWorking,
handleError,
showGenericDialog,
+ confirmDialog,
keyboardLayoutMap,
updateKeyboardLayout,
- }), [handleError, keyboardLayoutMap, setWorking, showGenericDialog, updateKeyboardLayout, working]);
+ }), [confirmDialog, handleError, keyboardLayoutMap, setWorking, showGenericDialog, updateKeyboardLayout, working]);
const showLeftBar = batchFiles.length > 0;
diff --git a/src/renderer/src/components/GenericDialog.tsx b/src/renderer/src/components/GenericDialog.tsx
index 77a14aae..514b5d39 100644
--- a/src/renderer/src/components/GenericDialog.tsx
+++ b/src/renderer/src/components/GenericDialog.tsx
@@ -307,3 +307,5 @@ export function useDialog() {
openCleanupFilesDialog,
};
}
+
+export type ConfirmDialog = ReturnType<typeof useDialog>['confirmDialog'];
diff --git a/src/renderer/src/components/KeyboardShortcuts.tsx b/src/renderer/src/components/KeyboardShortcuts.tsx
index 928332d5..8d1c5a53 100644
--- a/src/renderer/src/components/KeyboardShortcuts.tsx
+++ b/src/renderer/src/components/KeyboardShortcuts.tsx
@@ -161,7 +161,7 @@ const KeyboardShortcuts = memo(({
currentCutSeg: StateSegment | undefined,
}) => {
const { t } = useTranslation();
- const { updateKeyboardLayout } = useAppContext();
+ const { updateKeyboardLayout, confirmDialog } = useAppContext();
const { mouseWheelZoomModifierKey, mouseWheelFrameSeekModifierKey, mouseWheelKeyframeSeekModifierKey, segmentMouseModifierKey } = useUserSettings();
@@ -795,24 +795,21 @@ const KeyboardShortcuts = memo(({
const categoriesWithActions = useMemo(() => Object.entries(groupBy(actionEntries, ([, { category }]) => category)), [actionEntries]);
- const onDeleteBindingClick = useCallback(({ action, keys }: { action: KeyboardAction, keys: string }) => {
- // eslint-disable-next-line no-alert
- if (!window.confirm(t('Are you sure?'))) return;
+ const onDeleteBindingClick = useCallback(async ({ action, keys }: { action: KeyboardAction, keys: string }) => {
+ if (!(await confirmDialog({ description: t('Are you sure?') }))) return;
console.log('Delete key binding', action, keys);
setKeyBindings((existingBindings) => existingBindings.filter((existingBinding) => !(existingBinding.keys === keys && existingBinding.action === action)));
- }, [setKeyBindings, t]);
+ }, [confirmDialog, setKeyBindings, t]);
- const onResetClick = useCallback(() => {
+ const onResetClick = useCallback(async () => {
// Double confirmation!
- // eslint-disable-next-line no-alert
- if (!window.confirm(t('Are you sure you want to reset all keyboard bindings?'))) return;
- // eslint-disable-next-line no-alert
- if (!window.confirm(t('Are you sure you want to reset all keyboard bindings?'))) return;
+ if (!(await confirmDialog({ description: t('Are you sure you want to reset all keyboard bindings?') }))) return;
+ if (!(await confirmDialog({ description: t('Are you sure you want to reset all keyboard bindings?') }))) return;
resetKeyBindings();
- }, [resetKeyBindings, t]);
+ }, [confirmDialog, resetKeyBindings, t]);
const onAddBindingClick = useCallback((action: KeyboardAction) => {
setCreatingBinding(action);
@@ -827,8 +824,7 @@ const KeyboardShortcuts = memo(({
const duplicate = keyBindings.find((existingBinding) => existingBinding.keys === keysStr);
let shouldReplaceDuplicate: KeyBinding | undefined;
if (duplicate) {
- // eslint-disable-next-line no-alert
- const isConfirmed = window.confirm(t('Combination is already bound to "{{alreadyBoundKey}}". Do you want to replace the existing binding?', { alreadyBoundKey: actionsMap[duplicate.action]?.name }));
+ const isConfirmed = await confirmDialog({ confirmButtonText: t('Replace'), description: t('Combination is already bound to "{{alreadyBoundKey}}". Do you want to replace the existing binding?', { alreadyBoundKey: actionsMap[duplicate.action]?.name }) });
if (isConfirmed) {
shouldReplaceDuplicate = duplicate;
@@ -843,7 +839,7 @@ const KeyboardShortcuts = memo(({
const filtered = !shouldReplaceDuplicate ? existingBindings : existingBindings.filter((existing) => existing.keys !== shouldReplaceDuplicate.keys);
return [...filtered, { action, keys: keysStr }];
});
- }, [actionsMap, keyBindings, setKeyBindings, t]);
+ }, [actionsMap, confirmDialog, keyBindings, setKeyBindings, t]);
return (
<>
diff --git a/src/renderer/src/contexts.ts b/src/renderer/src/contexts.ts
index d4f79d57..552a8a0c 100644
--- a/src/renderer/src/contexts.ts
+++ b/src/renderer/src/contexts.ts
@@ -6,7 +6,7 @@ import { UserSettingsRoot } from './hooks/useUserSettingsRoot';
import { ExportMode, KeyboardLayoutMap, SegmentColorIndex } from './types';
import type useLoading from './hooks/useLoading';
import { GenericError } from './components/ErrorDialog';
-import { ShowGenericDialog } from './components/GenericDialog';
+import { ConfirmDialog, ShowGenericDialog } from './components/GenericDialog';
export type UserSettingsContextType = Omit<UserSettingsRoot, 'settings'> & UserSettingsRoot['settings'] & {
@@ -31,6 +31,7 @@ export interface AppContextType {
working: ReturnType<typeof useLoading>['working'],
handleError: HandleError,
showGenericDialog: ShowGenericDialog,
+ confirmDialog: ConfirmDialog,
keyboardLayoutMap: KeyboardLayoutMap | undefined,
updateKeyboardLayout: () => Promise<void>,
}