From f8a5f10db174fce29a659a472df007f1390095e2 Mon Sep 17 00:00:00 2001
From: Mikael Finstad
Date: Sat, 7 Jan 2023 00:04:20 +0800
Subject: [PATCH] refactor
---
src/App.jsx | 3 +-
src/dialogs/html5ify.jsx | 65 ++++++++++++++++++++++++++++++++++++++++
src/dialogs/index.jsx | 57 -----------------------------------
3 files changed, 67 insertions(+), 58 deletions(-)
create mode 100644 src/dialogs/html5ify.jsx
diff --git a/src/App.jsx b/src/App.jsx
index 72526044..95c7a874 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -71,7 +71,8 @@ import { formatDuration } from './util/duration';
import { adjustRate } from './util/rate-calculator';
import { showParametersDialog } from './dialogs/parameters';
import { askExtractFramesAsImages } from './dialogs/extractFrames';
-import { askForOutDir, askForInputDir, askForImportChapters, createNumSegments as createNumSegmentsDialog, createFixedDurationSegments as createFixedDurationSegmentsDialog, createRandomSegments as createRandomSegmentsDialog, promptTimeOffset, askForHtml5ifySpeed, askForFileOpenAction, confirmExtractAllStreamsDialog, showCleanupFilesDialog, showDiskFull, showExportFailedDialog, labelSegmentDialog, openYouTubeChaptersDialog, openAbout, showEditableJsonDialog, askForShiftSegments, selectSegmentsByLabelDialog, showRefuseToOverwrite, openDirToast, openCutFinishedToast } from './dialogs';
+import { askForHtml5ifySpeed } from './dialogs/html5ify';
+import { askForOutDir, askForInputDir, askForImportChapters, createNumSegments as createNumSegmentsDialog, createFixedDurationSegments as createFixedDurationSegmentsDialog, createRandomSegments as createRandomSegmentsDialog, promptTimeOffset, askForFileOpenAction, confirmExtractAllStreamsDialog, showCleanupFilesDialog, showDiskFull, showExportFailedDialog, labelSegmentDialog, openYouTubeChaptersDialog, openAbout, showEditableJsonDialog, askForShiftSegments, selectSegmentsByLabelDialog, showRefuseToOverwrite, openDirToast, openCutFinishedToast } from './dialogs';
import { openSendReportDialog } from './reporting';
import { fallbackLng } from './i18n';
import { createSegment, getCleanCutSegments, getSegApparentStart, getSegApparentEnd as getSegApparentEnd2, findSegmentsAtCursor, sortSegments, invertSegments, getSegmentTags, convertSegmentsToChapters, hasAnySegmentOverlap, combineOverlappingSegments as combineOverlappingSegments2, isDurationValid } from './segments';
diff --git a/src/dialogs/html5ify.jsx b/src/dialogs/html5ify.jsx
new file mode 100644
index 00000000..dcb3df75
--- /dev/null
+++ b/src/dialogs/html5ify.jsx
@@ -0,0 +1,65 @@
+import React, { useState, useCallback } from 'react';
+import { Checkbox, RadioGroup, Paragraph } from 'evergreen-ui';
+import Swal from 'sweetalert2';
+import i18n from 'i18next';
+import withReactContent from 'sweetalert2-react-content';
+
+const ReactSwal = withReactContent(Swal);
+
+
+// eslint-disable-next-line import/prefer-default-export
+export async function askForHtml5ifySpeed({ allowedOptions, showRemember, initialOption }) {
+ const availOptions = {
+ fastest: i18n.t('Fastest: Low playback speed (no audio)'),
+ 'fastest-audio': i18n.t('Fastest: Low playback speed'),
+ 'fastest-audio-remux': i18n.t('Fastest: Low playback speed (audio remux), likely to fail'),
+ fast: i18n.t('Fast: Full quality remux (no audio), likely to fail'),
+ 'fast-audio-remux': i18n.t('Fast: Full quality remux, likely to fail'),
+ 'fast-audio': i18n.t('Fast: Remux video, encode audio (fails if unsupported video codec)'),
+ slow: i18n.t('Slow: Low quality encode (no audio)'),
+ 'slow-audio': i18n.t('Slow: Low quality encode'),
+ slowest: i18n.t('Slowest: High quality encode'),
+ };
+ const inputOptions = {};
+ allowedOptions.forEach((allowedOption) => {
+ inputOptions[allowedOption] = availOptions[allowedOption];
+ });
+
+ let selectedOption = inputOptions[initialOption] ? initialOption : Object.keys(inputOptions)[0];
+ let rememberChoice = !!initialOption;
+
+ const Html = () => {
+ const [option, setOption] = useState(selectedOption);
+ const [remember, setRemember] = useState(rememberChoice);
+ const onOptionChange = useCallback((e) => {
+ selectedOption = e.target.value;
+ setOption(selectedOption);
+ }, []);
+ const onRememberChange = useCallback((e) => {
+ rememberChoice = e.target.checked;
+ setRemember(rememberChoice);
+ }, []);
+ return (
+
+
{i18n.t('These options will let you convert files to a format that is supported by the player. You can try different options and see which works with your file. Note that the conversion is for preview only. When you run an export, the output will still be lossless with full quality')}
+
({ label, value }))}
+ value={option}
+ onChange={onOptionChange}
+ />
+ {showRemember && }
+
+ );
+ };
+
+ const { value: response } = await ReactSwal.fire({
+ title: i18n.t('Convert to supported format'),
+ html: ,
+ showCancelButton: true,
+ });
+
+ return {
+ selectedOption: response && selectedOption,
+ remember: rememberChoice,
+ };
+}
diff --git a/src/dialogs/index.jsx b/src/dialogs/index.jsx
index e98a6f96..00a0b56f 100644
--- a/src/dialogs/index.jsx
+++ b/src/dialogs/index.jsx
@@ -39,63 +39,6 @@ export async function promptTimeOffset({ initialValue, title, text }) {
return duration;
}
-
-export async function askForHtml5ifySpeed({ allowedOptions, showRemember, initialOption }) {
- const availOptions = {
- fastest: i18n.t('Fastest: Low playback speed (no audio)'),
- 'fastest-audio': i18n.t('Fastest: Low playback speed'),
- 'fastest-audio-remux': i18n.t('Fastest: Low playback speed (audio remux), likely to fail'),
- fast: i18n.t('Fast: Full quality remux (no audio), likely to fail'),
- 'fast-audio-remux': i18n.t('Fast: Full quality remux, likely to fail'),
- 'fast-audio': i18n.t('Fast: Remux video, encode audio (fails if unsupported video codec)'),
- slow: i18n.t('Slow: Low quality encode (no audio)'),
- 'slow-audio': i18n.t('Slow: Low quality encode'),
- slowest: i18n.t('Slowest: High quality encode'),
- };
- const inputOptions = {};
- allowedOptions.forEach((allowedOption) => {
- inputOptions[allowedOption] = availOptions[allowedOption];
- });
-
- let selectedOption = inputOptions[initialOption] ? initialOption : Object.keys(inputOptions)[0];
- let rememberChoice = !!initialOption;
-
- const Html = () => {
- const [option, setOption] = useState(selectedOption);
- const [remember, setRemember] = useState(rememberChoice);
- const onOptionChange = useCallback((e) => {
- selectedOption = e.target.value;
- setOption(selectedOption);
- }, []);
- const onRememberChange = useCallback((e) => {
- rememberChoice = e.target.checked;
- setRemember(rememberChoice);
- }, []);
- return (
-
-
{i18n.t('These options will let you convert files to a format that is supported by the player. You can try different options and see which works with your file. Note that the conversion is for preview only. When you run an export, the output will still be lossless with full quality')}
-
({ label, value }))}
- value={option}
- onChange={onOptionChange}
- />
- {showRemember && }
-
- );
- };
-
- const { value: response } = await ReactSwal.fire({
- title: i18n.t('Convert to supported format'),
- html: