Skip to content

Commit

Permalink
feat: font-size setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Bin-Huang committed Apr 17, 2023
1 parent 5010852 commit 3968b85
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ function Main() {
save={(settings) => {
store.setSettings(settings)
setOpenSettingWindow(false)
if (settings.fontSize !== store.settings.fontSize) {
store.addToast(t('font size changed, effective after next launch'))
}
}}
close={() => setOpenSettingWindow(false)}
/>
Expand Down
18 changes: 18 additions & 0 deletions src/SettingWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ export default function SettingWindow(props: Props) {
<span style={{ marginRight: 10 }}>{t('theme')}</span>
<ThemeChangeButton value={settingsEdit.theme} onChange={theme => changeModeWithPreview(theme)} />
</FormControl>
<FormControl sx={{ m: 1, minWidth: 120 }} size="small">
<InputLabel>Font Size</InputLabel>
<Select
labelId="select-font-size"
value={settingsEdit.fontSize}
label="FontSize"
onChange={(event) => {
setSettingsEdit({ ...settingsEdit, fontSize: event.target.value as number })
}}
>
{
[12, 13, 14, 15, 16, 17, 18].map((size) => (
<MenuItem key={size} value={size}>{size}px</MenuItem>
))
}
</Select>
</FormControl>

<FormGroup>
<FormControlLabel control={<Switch />}
label={t('show word count')}
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@
"before making any modifications, please verify that your account has access to the selected models (some models require additional joining of the waiting list, regardless of your account type, otherwise, it will result in 404 errors).": "Before making any modifications, please verify that your account has access to the selected models (some models require additional joining of the waiting list, regardless of your account type, otherwise, it will result in 404 errors).",
"please make sure that the number of tokens does not exceed the limit for the selected model, otherwise, an error message will occur once the context exceeds the limit.": "Please make sure that the number of tokens does not exceed the limit for the selected model, otherwise, an error message will occur once the context exceeds the limit.",
"stop generating": "Stop generating",
"regenerate": "Regenerate"
"regenerate": "Regenerate",
"font size changed, effective after next launch": "Font size changed, effective after next launch"
}
3 changes: 2 additions & 1 deletion src/i18n/locales/zh-Hans/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@
"before making any modifications, please verify that your account has access to the selected models (some models require additional joining of the waiting list, regardless of your account type, otherwise, it will result in 404 errors).": "在修改前,请确认您的账户可以访问被选择的模型(不管您是什么账户类型,其中一些模型都需要额外申请,否则会导致请求出现 404 错误);",
"please make sure that the number of tokens does not exceed the limit for the selected model, otherwise, an error message will occur once the context exceeds the limit.": "同时,请确认 token 数量没有超过被选择模型的限制,否则上下文超出限制后将会直接报错。",
"stop generating": "停止生成",
"regenerate": "重新生成"
"regenerate": "重新生成",
"font size changed, effective after next launch": "字体大小已改变,将在下次启动时生效"
}
3 changes: 2 additions & 1 deletion src/i18n/locales/zh-Hant/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@
"before making any modifications, please verify that your account has access to the selected models (some models require additional joining of the waiting list, regardless of your account type, otherwise, it will result in 404 errors).": "在修改前,請確認您的帳號可以存取被選擇的模型(不管是甚麼類型的帳號,其中一些模型都需要額外申請,否則會導致請求出現 404 錯誤);",
"please make sure that the number of tokens does not exceed the limit for the selected model, otherwise, an error message will occur once the context exceeds the limit.": "同時,請確認 Token 沒有超過被選擇模型的上限,否則上下文超出上限後會直接報錯。",
"stop generating": "停止產生",
"regenerate": "重新產生"
"regenerate": "重新產生",
"font size changed, effective after next launch": "字體大小已改變,將在下次啟動時生效"
}
1 change: 1 addition & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function getDefaultSettings(): Settings {
showModelName: false,
theme: ThemeMode.System,
language: 'en',
fontSize: 13,
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/theme/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export function ThemeSwitcherProvider(props: ThemeSwitcherProviderProps) {
[mode]
);

const theme = useMemo(() => createTheme(fetchThemeDesign(realMode)), [realMode]);
const theme = useMemo(() => createTheme(
fetchThemeDesign(realMode, settings.fontSize)),
[realMode, settings],
);

useLayoutEffect(() => {
if (mode !== ThemeMode.System) return;
Expand Down
4 changes: 2 additions & 2 deletions src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ThemeModeMapPaletteMode: Record<RealThemeMode, PaletteMode> = {
[ThemeMode.Light]: 'light',
};

export function fetchThemeDesign(mode: RealThemeMode): ThemeOptions {
export function fetchThemeDesign(mode: RealThemeMode, fontSize: number): ThemeOptions {
return {
palette: {
mode: ThemeModeMapPaletteMode[mode],
Expand All @@ -32,7 +32,7 @@ export function fetchThemeDesign(mode: RealThemeMode): ThemeOptions {
typography: {
// In Chinese and Japanese the characters are usually larger,
// so a smaller fontsize may be appropriate.
fontSize: 12,
fontSize,
},
};
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface Settings {
showModelName?: boolean
theme: ThemeMode
language: string
fontSize: number
}

export const OpenAIRoleEnum = {
Expand Down

0 comments on commit 3968b85

Please sign in to comment.