General.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. * General
  3. * @author: oldj
  4. * @homepage: https://oldj.net
  5. */
  6. import { useModel } from '@@/plugin-model/useModel'
  7. import {
  8. Box,
  9. Checkbox,
  10. FormControl,
  11. FormHelperText,
  12. FormLabel,
  13. HStack,
  14. Radio,
  15. RadioGroup,
  16. Select,
  17. VStack,
  18. } from '@chakra-ui/react'
  19. import { agent } from '@renderer/core/agent'
  20. import { http_api_port } from '@root/common/constants'
  21. import { ConfigsType, ThemeType } from '@root/common/default_configs'
  22. import { LocaleName } from '@root/common/i18n'
  23. import React from 'react'
  24. interface IProps {
  25. data: ConfigsType
  26. onChange: (kv: Partial<ConfigsType>) => void
  27. }
  28. const General = (props: IProps) => {
  29. const { data, onChange } = props
  30. const { i18n, lang } = useModel('useI18n')
  31. const { platform } = agent
  32. const label_width = 20
  33. return (
  34. <VStack spacing={4}>
  35. <FormControl>
  36. <HStack>
  37. <FormLabel w={label_width}>{lang.language}</FormLabel>
  38. <Select
  39. w="200px"
  40. value={data.locale}
  41. onChange={(e) => onChange({ locale: e.target.value as LocaleName })}
  42. >
  43. <option value="zh">简体中文</option>
  44. <option value="en">English</option>
  45. <option value="fr">Français</option>
  46. </Select>
  47. </HStack>
  48. </FormControl>
  49. <FormControl>
  50. <HStack>
  51. <FormLabel w={label_width}>{lang.theme}</FormLabel>
  52. <Select
  53. w="200px"
  54. value={data.theme}
  55. onChange={(e) => onChange({ theme: e.target.value as ThemeType })}
  56. >
  57. <option value="light">{lang.theme_light}</option>
  58. <option value="dark">{lang.theme_dark}</option>
  59. </Select>
  60. </HStack>
  61. </FormControl>
  62. <FormControl pb={6}>
  63. <HStack>
  64. <FormLabel w={label_width}>{lang.choice_mode}</FormLabel>
  65. <VStack align="left">
  66. <RadioGroup
  67. value={data.choice_mode.toString()}
  68. onChange={(v) =>
  69. onChange({
  70. choice_mode: parseInt(
  71. v.toString(),
  72. ) as ConfigsType['choice_mode'],
  73. })
  74. }
  75. >
  76. <HStack spacing={10}>
  77. <Radio value="1">
  78. <Box>{lang.choice_mode_single}</Box>
  79. </Radio>
  80. <Radio value="2">
  81. <Box>{lang.choice_mode_multiple}</Box>
  82. </Radio>
  83. </HStack>
  84. </RadioGroup>
  85. <FormHelperText>{lang.choice_mode_desc}</FormHelperText>
  86. </VStack>
  87. </HStack>
  88. </FormControl>
  89. {platform === 'darwin' ? (
  90. <FormControl>
  91. <HStack>
  92. <Checkbox
  93. isChecked={data.show_title_on_tray}
  94. onChange={(e) =>
  95. onChange({ show_title_on_tray: e.target.checked })
  96. }
  97. >
  98. {lang.show_title_on_tray}
  99. </Checkbox>
  100. </HStack>
  101. </FormControl>
  102. ) : null}
  103. <FormControl>
  104. <HStack>
  105. <Checkbox
  106. isChecked={data.hide_at_launch}
  107. onChange={(e) => onChange({ hide_at_launch: e.target.checked })}
  108. >
  109. {lang.hide_at_launch}
  110. </Checkbox>
  111. </HStack>
  112. </FormControl>
  113. {agent.platform === 'darwin' ? (
  114. <FormControl>
  115. <HStack>
  116. <Checkbox
  117. isChecked={data.hide_dock_icon}
  118. onChange={(e) => onChange({ hide_dock_icon: e.target.checked })}
  119. >
  120. {lang.hide_dock_icon}
  121. </Checkbox>
  122. </HStack>
  123. </FormControl>
  124. ) : null}
  125. <FormControl>
  126. <VStack align="left">
  127. <Checkbox
  128. isChecked={data.remove_duplicate_records}
  129. onChange={(e) =>
  130. onChange({ remove_duplicate_records: e.target.checked })
  131. }
  132. >
  133. {lang.remove_duplicate_records}
  134. </Checkbox>
  135. <FormHelperText pl="20px">
  136. {lang.remove_duplicate_records_desc}
  137. </FormHelperText>
  138. </VStack>
  139. </FormControl>
  140. <FormControl>
  141. <VStack align="left">
  142. <Checkbox
  143. isChecked={data.http_api_on}
  144. onChange={(e) => onChange({ http_api_on: e.target.checked })}
  145. >
  146. {lang.http_api_on}
  147. </Checkbox>
  148. <FormHelperText pl="20px">
  149. {i18n.trans('http_api_on_desc', [http_api_port.toString()])}
  150. </FormHelperText>
  151. </VStack>
  152. </FormControl>
  153. </VStack>
  154. )
  155. }
  156. export default General