2023-05-31 07:21:47 +00:00
|
|
|
import React, { FC, useEffect, useRef } from 'react';
|
2023-05-21 16:04:18 +00:00
|
|
|
import { Page } from '../components/Page';
|
2023-05-31 07:21:47 +00:00
|
|
|
import {
|
|
|
|
Accordion,
|
|
|
|
AccordionHeader,
|
|
|
|
AccordionItem,
|
|
|
|
AccordionPanel,
|
|
|
|
Dropdown,
|
|
|
|
Input,
|
|
|
|
Option,
|
|
|
|
Switch
|
|
|
|
} from '@fluentui/react-components';
|
2023-05-21 16:04:18 +00:00
|
|
|
import { Labeled } from '../components/Labeled';
|
2023-05-17 15:27:52 +00:00
|
|
|
import commonStore from '../stores/commonStore';
|
2023-05-21 16:04:18 +00:00
|
|
|
import { observer } from 'mobx-react-lite';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { checkUpdate } from '../utils';
|
2023-05-20 08:07:08 +00:00
|
|
|
|
|
|
|
export const Languages = {
|
|
|
|
dev: 'English', // i18n default
|
|
|
|
zh: '简体中文'
|
|
|
|
};
|
|
|
|
|
|
|
|
export type Language = keyof typeof Languages;
|
|
|
|
|
2023-05-20 08:33:32 +00:00
|
|
|
export type SettingsType = {
|
2023-05-31 07:21:47 +00:00
|
|
|
language: Language
|
2023-05-20 08:07:08 +00:00
|
|
|
darkMode: boolean
|
|
|
|
autoUpdatesCheck: boolean
|
2023-05-21 16:04:18 +00:00
|
|
|
giteeUpdatesSource: boolean
|
2023-05-21 02:49:45 +00:00
|
|
|
cnMirror: boolean
|
2023-05-24 14:03:30 +00:00
|
|
|
host: string
|
2023-05-31 07:21:47 +00:00
|
|
|
customModelsPath: string
|
|
|
|
customPythonPath: string
|
2023-05-20 08:07:08 +00:00
|
|
|
}
|
2023-05-05 15:23:34 +00:00
|
|
|
|
2023-05-17 15:27:52 +00:00
|
|
|
export const Settings: FC = observer(() => {
|
2023-05-21 16:04:18 +00:00
|
|
|
const { t, i18n } = useTranslation();
|
2023-05-31 07:21:47 +00:00
|
|
|
const advancedHeaderRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (advancedHeaderRef.current)
|
|
|
|
(advancedHeaderRef.current.firstElementChild as HTMLElement).style.padding = '0';
|
|
|
|
}, []);
|
2023-05-18 11:25:13 +00:00
|
|
|
|
2023-05-05 15:23:34 +00:00
|
|
|
return (
|
2023-05-18 11:25:13 +00:00
|
|
|
<Page title={t('Settings')} content={
|
2023-05-17 15:27:52 +00:00
|
|
|
<div className="flex flex-col gap-2 overflow-hidden">
|
2023-05-18 12:48:53 +00:00
|
|
|
<Labeled label={t('Language')} flex spaceBetween content={
|
2023-05-21 16:04:18 +00:00
|
|
|
<Dropdown style={{ minWidth: 0 }} listbox={{ style: { minWidth: 0 } }}
|
|
|
|
value={Languages[commonStore.settings.language]}
|
|
|
|
selectedOptions={[commonStore.settings.language]}
|
|
|
|
onOptionSelect={(_, data) => {
|
|
|
|
if (data.optionValue) {
|
|
|
|
const lang = data.optionValue as Language;
|
|
|
|
commonStore.setSettings({
|
|
|
|
language: lang
|
|
|
|
});
|
|
|
|
i18n.changeLanguage(lang);
|
|
|
|
}
|
|
|
|
}}>
|
2023-05-18 11:25:13 +00:00
|
|
|
{
|
|
|
|
Object.entries(Languages).map(([langKey, desc]) =>
|
|
|
|
<Option key={langKey} value={langKey}>{desc}</Option>)
|
|
|
|
}
|
2023-05-17 15:27:52 +00:00
|
|
|
</Dropdown>
|
2023-05-21 16:04:18 +00:00
|
|
|
} />
|
2023-05-18 12:48:53 +00:00
|
|
|
<Labeled label={t('Dark Mode')} flex spaceBetween content={
|
2023-05-17 15:27:52 +00:00
|
|
|
<Switch checked={commonStore.settings.darkMode}
|
2023-05-21 16:04:18 +00:00
|
|
|
onChange={(e, data) => {
|
|
|
|
commonStore.setSettings({
|
|
|
|
darkMode: data.checked
|
|
|
|
});
|
|
|
|
}} />
|
|
|
|
} />
|
2023-05-18 12:48:53 +00:00
|
|
|
<Labeled label={t('Automatic Updates Check')} flex spaceBetween content={
|
2023-05-17 15:27:52 +00:00
|
|
|
<Switch checked={commonStore.settings.autoUpdatesCheck}
|
2023-05-21 16:04:18 +00:00
|
|
|
onChange={(e, data) => {
|
|
|
|
commonStore.setSettings({
|
|
|
|
autoUpdatesCheck: data.checked
|
|
|
|
});
|
|
|
|
if (data.checked)
|
|
|
|
checkUpdate(true);
|
|
|
|
}} />
|
|
|
|
} />
|
|
|
|
{
|
|
|
|
commonStore.settings.language === 'zh' &&
|
|
|
|
<Labeled label={t('Use Gitee Updates Source')} flex spaceBetween content={
|
|
|
|
<Switch checked={commonStore.settings.giteeUpdatesSource}
|
|
|
|
onChange={(e, data) => {
|
|
|
|
commonStore.setSettings({
|
|
|
|
giteeUpdatesSource: data.checked
|
|
|
|
});
|
|
|
|
}} />
|
|
|
|
} />
|
|
|
|
}
|
2023-05-21 02:49:45 +00:00
|
|
|
{
|
|
|
|
commonStore.settings.language === 'zh' &&
|
|
|
|
<Labeled label={t('Use Tsinghua Pip Mirrors')} flex spaceBetween content={
|
|
|
|
<Switch checked={commonStore.settings.cnMirror}
|
2023-05-21 16:04:18 +00:00
|
|
|
onChange={(e, data) => {
|
|
|
|
commonStore.setSettings({
|
|
|
|
cnMirror: data.checked
|
|
|
|
});
|
|
|
|
}} />
|
|
|
|
} />
|
2023-05-21 02:49:45 +00:00
|
|
|
}
|
2023-05-29 13:34:24 +00:00
|
|
|
<Labeled label={t('Allow external access to the API (service must be restarted)')} flex spaceBetween content={
|
|
|
|
<Switch checked={commonStore.settings.host !== '127.0.0.1'}
|
2023-05-24 14:03:30 +00:00
|
|
|
onChange={(e, data) => {
|
|
|
|
commonStore.setSettings({
|
2023-05-29 13:34:24 +00:00
|
|
|
host: data.checked ? '0.0.0.0' : '127.0.0.1'
|
2023-05-24 14:03:30 +00:00
|
|
|
});
|
|
|
|
}} />
|
|
|
|
} />
|
2023-05-31 07:21:47 +00:00
|
|
|
<Accordion collapsible>
|
|
|
|
<AccordionItem value="1">
|
|
|
|
<AccordionHeader ref={advancedHeaderRef} size="large">{t('Advanced')}</AccordionHeader>
|
|
|
|
<AccordionPanel>
|
|
|
|
<div className="flex flex-col gap-2 overflow-hidden">
|
|
|
|
<Labeled label={t('Custom Models Path')}
|
|
|
|
content={
|
|
|
|
<Input className="grow" placeholder="./models" value={commonStore.settings.customModelsPath}
|
|
|
|
onChange={(e, data) => {
|
|
|
|
commonStore.setSettings({
|
|
|
|
customModelsPath: data.value
|
|
|
|
});
|
|
|
|
}} />
|
|
|
|
} />
|
|
|
|
<Labeled label={t('Custom Python Path')}
|
|
|
|
content={
|
|
|
|
<Input className="grow" placeholder="./py310/python" value={commonStore.settings.customPythonPath}
|
|
|
|
onChange={(e, data) => {
|
|
|
|
commonStore.setSettings({
|
|
|
|
customPythonPath: data.value
|
|
|
|
});
|
|
|
|
}} />
|
|
|
|
} />
|
|
|
|
</div>
|
|
|
|
</AccordionPanel>
|
|
|
|
</AccordionItem>
|
|
|
|
</Accordion>
|
2023-05-17 15:27:52 +00:00
|
|
|
</div>
|
2023-05-21 16:04:18 +00:00
|
|
|
} />
|
2023-05-05 15:23:34 +00:00
|
|
|
);
|
2023-05-17 15:27:52 +00:00
|
|
|
});
|