Skip to content

Commit 4dcb1f2

Browse files
committed
Move behavior preferences to advanced tab
1 parent cf4f134 commit 4dcb1f2

3 files changed

Lines changed: 128 additions & 80 deletions

File tree

‎e2e/preferences.spec.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,56 @@ test.describe('preferences', () => {
7575
await expectFontSize(preferences.getByText('Hide at Launch', { exact: true }))
7676
})
7777

78+
test('places app behavior toggles at the top of advanced preferences', async ({ page }) => {
79+
await page.getByLabel('Settings').click()
80+
await page.getByText('Preferences').click()
81+
const preferences = page.getByRole('dialog')
82+
await expect(preferences.getByText('General')).toBeVisible()
83+
84+
await preferences.getByRole('tab', { name: 'Advanced' }).click()
85+
await expect(preferences.getByText('Make SwitchHosts Better!', { exact: true })).toBeVisible()
86+
87+
const orderedLabels = [
88+
'Show Title in Tray',
89+
'Remove Duplicate Records',
90+
'Refresh Remote Hosts at Launch',
91+
'Sync Child Items When Toggling Folders',
92+
'Tray Icon Shortcut',
93+
'Enable HTTP API',
94+
]
95+
96+
const visibleLabels: string[] = []
97+
for (const label of orderedLabels) {
98+
const text = preferences.getByText(label, { exact: true })
99+
if ((await text.count()) === 0) continue
100+
await expect(text).toBeVisible()
101+
visibleLabels.push(label)
102+
}
103+
expect(visibleLabels).toEqual(
104+
expect.arrayContaining([
105+
'Remove Duplicate Records',
106+
'Refresh Remote Hosts at Launch',
107+
'Sync Child Items When Toggling Folders',
108+
'Tray Icon Shortcut',
109+
'Enable HTTP API',
110+
]),
111+
)
112+
113+
const usageDataBox = await preferences
114+
.getByText('Make SwitchHosts Better!', { exact: true })
115+
.boundingBox()
116+
expect(usageDataBox).not.toBeNull()
117+
118+
let previousY = 0
119+
for (const label of visibleLabels) {
120+
const labelBox = await preferences.getByText(label, { exact: true }).boundingBox()
121+
expect(labelBox).not.toBeNull()
122+
expect(labelBox!.y).toBeGreaterThanOrEqual(previousY)
123+
expect(labelBox!.y).toBeLessThan(usageDataBox!.y)
124+
previousY = labelBox!.y
125+
}
126+
})
127+
78128
test('saves basic preferences immediately', async ({ page }) => {
79129
await clearMockCalls(page)
80130

@@ -216,6 +266,7 @@ test.describe('preferences', () => {
216266
await page.getByText('Preferences').click()
217267
const preferences = page.getByRole('dialog')
218268
await expect(preferences.getByText('General')).toBeVisible()
269+
await preferences.getByRole('tab', { name: 'Advanced' }).click()
219270
await expect(
220271
preferences.getByText(
221272
'When enabled, every launch automatically refreshes all remote Hosts entries.',

‎src/renderer/components/Pref/Advanced.tsx‎

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
* @homepage: https://oldj.net
44
*/
55

6+
import { httpApiPort } from '@common/constants'
67
import { ConfigsType } from '@common/default_configs'
7-
import { Checkbox, Stack, Tooltip } from '@mantine/core'
8-
import DescriptionText from '@renderer/components/DescriptionText'
9-
import { actions } from '@renderer/core/agent'
8+
import { Box, Checkbox, Stack, Tooltip } from '@mantine/core'
9+
import DescriptionText, { checkboxDescriptionStyles } from '@renderer/components/DescriptionText'
10+
import { actions, agent } from '@renderer/core/agent'
1011
import useI18n from '@renderer/models/useI18n'
1112
import { IconFile, IconFolder } from '@tabler/icons-react'
1213
import React, { useEffect, useState } from 'react'
@@ -49,7 +50,8 @@ const PathLink = (props: { link: string; icon?: React.ReactNode }) => {
4950

5051
const Advanced = (props: IProps) => {
5152
const { data, onChange } = props
52-
const { lang } = useI18n()
53+
const { i18n, lang } = useI18n()
54+
const { platform } = agent
5355
const [hostsPath, setHostsPath] = useState('')
5456
const [dataDir, setDataDir] = useState('')
5557

@@ -60,6 +62,76 @@ const Advanced = (props: IProps) => {
6062

6163
return (
6264
<Stack gap="40px" pb={60}>
65+
<Stack gap="16px" w="100%">
66+
{platform === 'darwin' ? (
67+
<Box w="100%">
68+
<Checkbox
69+
checked={data.show_title_on_tray}
70+
onChange={(e) => onChange({ show_title_on_tray: e.target.checked })}
71+
label={lang.show_title_on_tray}
72+
/>
73+
</Box>
74+
) : null}
75+
76+
<Box w="100%">
77+
<Checkbox
78+
checked={data.remove_duplicate_records}
79+
onChange={(e) => onChange({ remove_duplicate_records: e.target.checked })}
80+
label={lang.remove_duplicate_records}
81+
description={lang.remove_duplicate_records_desc}
82+
styles={checkboxDescriptionStyles}
83+
/>
84+
</Box>
85+
86+
<Box w="100%">
87+
<Checkbox
88+
checked={data.refresh_remote_hosts_on_startup}
89+
onChange={(e) => onChange({ refresh_remote_hosts_on_startup: e.target.checked })}
90+
label={lang.refresh_remote_hosts_on_startup}
91+
description={lang.refresh_remote_hosts_on_startup_desc}
92+
styles={checkboxDescriptionStyles}
93+
/>
94+
</Box>
95+
96+
<Box w="100%">
97+
<Checkbox
98+
checked={data.multi_chose_folder_switch_all}
99+
onChange={(e) => onChange({ multi_chose_folder_switch_all: e.target.checked })}
100+
label={lang.multi_chose_folder_switch_all}
101+
description={lang.multi_chose_folder_switch_all_desc}
102+
styles={checkboxDescriptionStyles}
103+
/>
104+
</Box>
105+
106+
<Box w="100%">
107+
<Checkbox
108+
checked={data.tray_mini_window}
109+
onChange={(e) => onChange({ tray_mini_window: e.target.checked })}
110+
label={lang.tray_mini_window}
111+
/>
112+
</Box>
113+
114+
<Box w="100%">
115+
<Stack gap="8px">
116+
<Checkbox
117+
checked={data.http_api_on}
118+
onChange={(e) => onChange({ http_api_on: e.target.checked })}
119+
label={lang.http_api_on}
120+
description={i18n.trans('http_api_on_desc', [httpApiPort.toString()])}
121+
styles={checkboxDescriptionStyles}
122+
/>
123+
<Box pl="28px">
124+
<Checkbox
125+
disabled={!data.http_api_on}
126+
checked={data.http_api_only_local}
127+
onChange={(e) => onChange({ http_api_only_local: e.target.checked })}
128+
label={lang.http_api_only_local}
129+
/>
130+
</Box>
131+
</Stack>
132+
</Box>
133+
</Stack>
134+
63135
<div style={{ width: '100%' }}>
64136
<div>{lang.usage_data_title}</div>
65137
<DescriptionText mb="8px">{lang.usage_data_help}</DescriptionText>

‎src/renderer/components/Pref/General.tsx‎

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @homepage: https://oldj.net
44
*/
55

6-
import { httpApiPort } from '@common/constants'
76
import { ConfigsType, ThemeType } from '@common/default_configs'
87
import { LocaleName } from '@common/i18n'
98
import { Box, Checkbox, Group, SegmentedControl, Select, Stack } from '@mantine/core'
@@ -27,7 +26,7 @@ const segmentedControlLabelStyle: CSSProperties = {
2726

2827
const General = (props: IProps) => {
2928
const { data, onChange } = props
30-
const { i18n, lang } = useI18n()
29+
const { lang } = useI18n()
3130
const { platform } = agent
3231

3332
return (
@@ -135,18 +134,6 @@ const General = (props: IProps) => {
135134
</Box>
136135
) : null}
137136

138-
{platform === 'darwin' ? (
139-
<Box w="100%">
140-
<Group>
141-
<Checkbox
142-
checked={data.show_title_on_tray}
143-
onChange={(e) => onChange({ show_title_on_tray: e.target.checked })}
144-
label={lang.show_title_on_tray}
145-
/>
146-
</Group>
147-
</Box>
148-
) : null}
149-
150137
{platform === 'linux' ? (
151138
<Box w="100%">
152139
<Group>
@@ -159,26 +146,6 @@ const General = (props: IProps) => {
159146
</Box>
160147
) : null}
161148

162-
<Box w="100%">
163-
<Checkbox
164-
checked={data.remove_duplicate_records}
165-
onChange={(e) => onChange({ remove_duplicate_records: e.target.checked })}
166-
label={lang.remove_duplicate_records}
167-
description={lang.remove_duplicate_records_desc}
168-
styles={checkboxDescriptionStyles}
169-
/>
170-
</Box>
171-
172-
<Box w="100%">
173-
<Checkbox
174-
checked={data.refresh_remote_hosts_on_startup}
175-
onChange={(e) => onChange({ refresh_remote_hosts_on_startup: e.target.checked })}
176-
label={lang.refresh_remote_hosts_on_startup}
177-
description={lang.refresh_remote_hosts_on_startup_desc}
178-
styles={checkboxDescriptionStyles}
179-
/>
180-
</Box>
181-
182149
<Box w="100%">
183150
<Checkbox
184151
checked={data.auto_check_update}
@@ -188,48 +155,6 @@ const General = (props: IProps) => {
188155
styles={checkboxDescriptionStyles}
189156
/>
190157
</Box>
191-
192-
<Box w="100%">
193-
<Stack gap="16px">
194-
<Checkbox
195-
checked={data.tray_mini_window}
196-
onChange={(e) => onChange({ tray_mini_window: e.target.checked })}
197-
label={lang.tray_mini_window}
198-
/>
199-
</Stack>
200-
</Box>
201-
202-
<Box w="100%">
203-
<Stack gap="16px">
204-
<Checkbox
205-
checked={data.multi_chose_folder_switch_all}
206-
onChange={(e) => onChange({ multi_chose_folder_switch_all: e.target.checked })}
207-
label={lang.multi_chose_folder_switch_all}
208-
description={lang.multi_chose_folder_switch_all_desc}
209-
styles={checkboxDescriptionStyles}
210-
/>
211-
</Stack>
212-
</Box>
213-
214-
<Box w="100%">
215-
<Stack gap="8px">
216-
<Checkbox
217-
checked={data.http_api_on}
218-
onChange={(e) => onChange({ http_api_on: e.target.checked })}
219-
label={lang.http_api_on}
220-
description={i18n.trans('http_api_on_desc', [httpApiPort.toString()])}
221-
styles={checkboxDescriptionStyles}
222-
/>
223-
<Box pl="28px">
224-
<Checkbox
225-
disabled={!data.http_api_on}
226-
checked={data.http_api_only_local}
227-
onChange={(e) => onChange({ http_api_only_local: e.target.checked })}
228-
label={lang.http_api_only_local}
229-
/>
230-
</Box>
231-
</Stack>
232-
</Box>
233158
</Stack>
234159
)
235160
}

0 commit comments

Comments
 (0)