1616 * along with this program. If not, see <https://www.gnu.org/licenses/>.
1717 */
1818
19- import React , { useCallback } from "react" ;
20- import { Checkbox , Grid , NumberInput , Textarea , useMantineTheme } from "@mantine/core" ;
19+ import React , { useCallback , useEffect , useState } from "react" ;
20+ import { Checkbox , Grid , NativeSelect , NumberInput , Textarea , useMantineTheme } from "@mantine/core" ;
2121import type { UseFormReturnType } from "@mantine/form" ;
2222import type { ColorSetting } from "components/colorswatch" ;
2323import ColorChooser from "components/colorswatch" ;
2424import { useGlobalStyleOverrides } from "themehooks" ;
25+ const { TAURI , invoke } = await import ( /* webpackChunkName: "taurishim" */ "taurishim" ) ;
2526
2627export interface InterfaceFormValues {
2728 interface : {
29+ styleOverrides : {
30+ color ?: ColorSetting ,
31+ backgroundColor ?: ColorSetting ,
32+ font ?: string ,
33+ } ,
2834 skipAddDialog : boolean ,
2935 numLastSaveDirs : number ,
3036 defaultTrackers : string [ ] ,
@@ -33,15 +39,39 @@ export interface InterfaceFormValues {
3339
3440export function InterfaceSettigsPanel < V extends InterfaceFormValues > ( props : { form : UseFormReturnType < V > } ) {
3541 const theme = useMantineTheme ( ) ;
36- const { color, backgroundColor, setStyle } = useGlobalStyleOverrides ( ) ;
42+ const { color, backgroundColor, font, setStyle } = useGlobalStyleOverrides ( ) ;
43+ const [ systemFonts , setSystemFonts ] = useState < string [ ] > ( [ "Default" ] ) ;
44+
45+ useEffect ( ( ) => {
46+ if ( TAURI ) {
47+ invoke < string [ ] > ( "list_system_fonts" ) . then ( ( fonts ) => {
48+ fonts . sort ( ) ;
49+ setSystemFonts ( [ "Default" ] . concat ( fonts ) ) ;
50+ } ) . catch ( console . error ) ;
51+ } else {
52+ setSystemFonts ( [ "Default" , "Arial" , "Verdana" , "Tahoma" , "Roboto" ] ) ;
53+ }
54+ } , [ ] ) ;
55+
56+ const { setFieldValue } = props . form as unknown as UseFormReturnType < InterfaceFormValues > ;
3757
3858 const setTextColor = useCallback ( ( color : ColorSetting | undefined ) => {
39- setStyle ( { color, backgroundColor } ) ;
40- } , [ backgroundColor , setStyle ] ) ;
59+ const style = { color, backgroundColor, font } ;
60+ setStyle ( style ) ;
61+ setFieldValue ( "interface.styleOverrides" , style ) ;
62+ } , [ backgroundColor , font , setFieldValue , setStyle ] ) ;
4163
4264 const setBgColor = useCallback ( ( backgroundColor : ColorSetting | undefined ) => {
43- setStyle ( { color, backgroundColor } ) ;
44- } , [ color , setStyle ] ) ;
65+ const style = { color, backgroundColor, font } ;
66+ setStyle ( style ) ;
67+ setFieldValue ( "interface.styleOverrides" , style ) ;
68+ } , [ color , font , setFieldValue , setStyle ] ) ;
69+
70+ const setFont = useCallback ( ( font : string ) => {
71+ const style = { color, backgroundColor, font : font === "Default" ? undefined : font } ;
72+ setStyle ( style ) ;
73+ setFieldValue ( "interface.styleOverrides" , style ) ;
74+ } , [ backgroundColor , color , setFieldValue , setStyle ] ) ;
4575
4676 const defaultColor = theme . colorScheme === "dark"
4777 ? { color : "dark" , shade : 0 }
@@ -52,20 +82,25 @@ export function InterfaceSettigsPanel<V extends InterfaceFormValues>(props: { fo
5282 : { color : "gray" , shade : 0 } ;
5383
5484 return (
55- < Grid >
85+ < Grid align = "center" >
86+ < Grid . Col span = { 2 } >
87+ Font
88+ </ Grid . Col >
89+ < Grid . Col span = { 4 } >
90+ < NativeSelect data = { systemFonts } value = { font } onChange = { ( e ) => { setFont ( e . currentTarget . value ) ; } } />
91+ </ Grid . Col >
5692 < Grid . Col span = { 2 } >
57- Text
93+ Text color
5894 </ Grid . Col >
5995 < Grid . Col span = { 1 } >
6096 < ColorChooser value = { color ?? defaultColor } onChange = { setTextColor } />
6197 </ Grid . Col >
6298 < Grid . Col span = { 2 } >
63- Bakground
99+ Background
64100 </ Grid . Col >
65101 < Grid . Col span = { 1 } >
66102 < ColorChooser value = { backgroundColor ?? defaultBg } onChange = { setBgColor } />
67103 </ Grid . Col >
68- < Grid . Col span = { 6 } />
69104 < Grid . Col >
70105 < Checkbox label = "Skip add torrent dialog"
71106 { ...props . form . getInputProps ( "interface.skipAddDialog" , { type : "checkbox" } ) } />
0 commit comments