Skip to content

Commit

Permalink
Ability to import/export settings
Browse files Browse the repository at this point in the history
  • Loading branch information
killergerbah committed Nov 13, 2023
1 parent d12110b commit 9779b3b
Show file tree
Hide file tree
Showing 33 changed files with 506 additions and 159 deletions.
1 change: 1 addition & 0 deletions common/anki/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/anki';
12 changes: 6 additions & 6 deletions common/src/anki.ts → common/anki/src/anki.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import AudioClip from './audio-clip';
import Image from './image';
import { HttpFetcher, Fetcher } from './fetcher';
import { AnkiSettings } from './settings';
import { AudioClip } from '@project/common/audio-clip';
import { Image } from '@project/common';
import { HttpFetcher, Fetcher } from '@project/common';
import { AnkiSettings } from '@project/common';
import sanitize from 'sanitize-filename';
import { AudioModel, ImageModel, SubtitleModel } from './model';
import { extractText } from './util';
import { AudioModel, ImageModel, SubtitleModel } from '@project/common';
import { extractText } from '@project/common';

const ankiQuerySpecialCharacters = ['"', '*', '_', '\\', ':'];

Expand Down
7 changes: 3 additions & 4 deletions common/app/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { makeStyles, Theme } from '@material-ui/core/styles';
import ThemeProvider from '@material-ui/styles/ThemeProvider';
import { useWindowSize } from '../hooks/use-window-size';
import {
Anki,
AudioClip,
Image,
humanReadableTime,
AnkiDialogSliderContext,
Expand All @@ -23,6 +21,8 @@ import {
CopyHistoryItem,
Fetcher,
} from '@project/common';
import { AudioClip } from '@project/common/audio-clip';
import { Anki, AnkiExportMode } from '@project/common/anki';
import { SubtitleReader } from '@project/common/subtitle-reader';
import { v4 as uuidv4 } from 'uuid';
import clsx from 'clsx';
Expand All @@ -39,7 +39,6 @@ import Player, { AnkiDialogFinishedRequest, MediaSources } from './Player';
import SettingsDialog from './SettingsDialog';
import VideoPlayer, { SeekRequest } from './VideoPlayer';
import { Color } from '@material-ui/lab';
import { AnkiExportMode } from '@project/common';
import { DefaultKeyBinder } from '@project/common/key-binder';
import AppKeyBinder from '../services/app-key-binder';
import VideoChannel from '../services/video-channel';
Expand Down Expand Up @@ -288,7 +287,7 @@ interface Props {
settings: AsbplayerSettings;
extension: ChromeExtension;
fetcher: Fetcher;
onSettingsChanged: <K extends keyof AsbplayerSettings>(key: K, value: AsbplayerSettings[K]) => void;
onSettingsChanged: (settings: Partial<AsbplayerSettings>) => void;
}

function App({ origin, logoUrl, settings, extension, fetcher, onSettingsChanged }: Props) {
Expand Down
6 changes: 3 additions & 3 deletions common/app/src/components/RootApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const RootApp = ({ origin, logoUrl, settingsStorage, fetcher }: Props) => {
}, [settingsProvider]);

const handleSettingsChanged = useCallback(
async <K extends keyof AsbplayerSettings>(key: K, value: AsbplayerSettings[K]) => {
setSettings((s) => ({ ...s!, [key]: value }));
async (settings: Partial<AsbplayerSettings>) => {
setSettings((s) => ({ ...s!, ...settings }));

await settingsProvider.set({ [key]: value });
await settingsProvider.set(settings);

if (extension.installed) {
extension.notifySettingsUpdated();
Expand Down
5 changes: 3 additions & 2 deletions common/app/src/components/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogTitle from '@material-ui/core/DialogTitle';
import { Anki, AsbplayerSettings } from '@project/common';
import ChromeExtension from '../services/chrome-extension';
import { SettingsForm } from '../../../components';
import { useLocalFontFamilies } from '../../../hooks';
import { Anki } from '../../../anki';
import { AsbplayerSettings } from '../../..';

const useStyles = makeStyles({
root: {
Expand All @@ -28,7 +29,7 @@ interface Props {
open: boolean;
settings: AsbplayerSettings;
scrollToId?: string;
onSettingsChanged: <K extends keyof AsbplayerSettings>(key: K, value: AsbplayerSettings[K]) => void;
onSettingsChanged: (settings: Partial<AsbplayerSettings>) => void;
onClose: () => void;
}

Expand Down
2 changes: 2 additions & 0 deletions common/audio-clip/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as AudioClip } from './src/audio-clip';
export { default as Mp3Encoder } from './src/mp3-encoder';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Mp3Encoder from './mp3-encoder';
// eslint-disable-next-line
// @ts-ignore
import Worker from 'worker-loader!./mp3-encoder-worker.js';
import { download } from './util';
import { download } from '@project/common';
const defaultMp3WorkerFactory = () => new Worker();

interface ExperimentalAudioElement extends HTMLAudioElement {
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions common/components/src/AnkiDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { useTranslation } from 'react-i18next';
import makeStyles from '@material-ui/core/styles/makeStyles';
import withStyles from '@material-ui/core/styles/withStyles';
import {
Anki,
AnkiDialogSliderContext,
AudioClip,
Image,
humanReadableTime,
AnkiSettings,
Expand All @@ -14,6 +12,7 @@ import {
subtitleIntersectsTimeInterval,
joinSubtitles,
} from '@project/common';
import { AudioClip } from '@project/common/audio-clip';
import Button from '@material-ui/core/Button';
import FileCopyIcon from '@material-ui/icons/FileCopy';
import TextField from '@material-ui/core/TextField';
Expand All @@ -38,7 +37,7 @@ import ZoomInIcon from '@material-ui/icons/ZoomIn';
import ZoomOutIcon from '@material-ui/icons/ZoomOut';
import SubtitleTextImage from './SubtitleTextImage';
import TagsTextField from './TagsTextField';
import { AnkiExportMode } from '@project/common';
import { Anki, AnkiExportMode } from '../../anki';

const useStyles = makeStyles((theme) => ({
root: {
Expand Down
Loading

0 comments on commit 9779b3b

Please sign in to comment.