diff options
author | 2023-12-07 22:37:37 -0700 | |
---|---|---|
committer | 2023-12-07 22:37:37 -0700 | |
commit | a774c879d4cf08a76fc404771883807d27465265 (patch) | |
tree | 202c9afdeb4830d417e0ec7137a01e7981c8651c /src | |
parent | 6.6.1-nightly.17 [skip ci] (diff) | |
download | ferdium-app-a774c879d4cf08a76fc404771883807d27465265.tar.gz ferdium-app-a774c879d4cf08a76fc404771883807d27465265.tar.zst ferdium-app-a774c879d4cf08a76fc404771883807d27465265.zip |
refactor: code cleanup (#1476)
- auto update `settings.json` due to new vscode version
- replace deprecated `e.keyCode` with `e.key`
- fix various code snippets with sonarlint and other lint plugins
Diffstat (limited to 'src')
-rw-r--r-- | src/api/server/ServerApi.ts | 2 | ||||
-rw-r--r-- | src/components/services/content/ServiceView.tsx | 2 | ||||
-rw-r--r-- | src/components/settings/settings/EditSettingsForm.tsx | 2 | ||||
-rw-r--r-- | src/components/ui/AppLoader/index.tsx | 2 | ||||
-rw-r--r-- | src/components/ui/input/scorePassword.ts | 2 | ||||
-rw-r--r-- | src/components/ui/select/index.tsx | 21 | ||||
-rw-r--r-- | src/containers/settings/EditServiceScreen.tsx | 8 | ||||
-rw-r--r-- | src/features/quickSwitch/Component.tsx | 18 | ||||
-rw-r--r-- | src/helpers/service-helpers.ts | 2 | ||||
-rw-r--r-- | src/helpers/update-helpers.ts | 2 | ||||
-rw-r--r-- | src/helpers/userAgent-helpers.ts | 2 | ||||
-rw-r--r-- | src/lib/Tray.ts | 7 | ||||
-rw-r--r-- | src/stores/ServicesStore.ts | 3 | ||||
-rw-r--r-- | src/webview/contextMenuBuilder.ts | 7 |
14 files changed, 27 insertions, 53 deletions
diff --git a/src/api/server/ServerApi.ts b/src/api/server/ServerApi.ts index 6e4485cfb..1530dd478 100644 --- a/src/api/server/ServerApi.ts +++ b/src/api/server/ServerApi.ts | |||
@@ -506,7 +506,7 @@ export default class ServerApi { | |||
506 | try { | 506 | try { |
507 | const config = readJsonSync(file); | 507 | const config = readJsonSync(file); |
508 | 508 | ||
509 | if (Object.prototype.hasOwnProperty.call(config, 'services')) { | 509 | if (Object.hasOwn(config, 'services')) { |
510 | const services = await Promise.all( | 510 | const services = await Promise.all( |
511 | config.services.map(async (s: { service: any }) => { | 511 | config.services.map(async (s: { service: any }) => { |
512 | const service = s; | 512 | const service = s; |
diff --git a/src/components/services/content/ServiceView.tsx b/src/components/services/content/ServiceView.tsx index 37dcafbe4..d89cd0610 100644 --- a/src/components/services/content/ServiceView.tsx +++ b/src/components/services/content/ServiceView.tsx | |||
@@ -64,7 +64,7 @@ class ServiceView extends Component<IProps, IState> { | |||
64 | 64 | ||
65 | componentWillUnmount() { | 65 | componentWillUnmount() { |
66 | this.autorunDisposer!(); | 66 | this.autorunDisposer!(); |
67 | clearTimeout(this.forceRepaintTimeout!); | 67 | clearTimeout(this.forceRepaintTimeout); |
68 | // clearTimeout(this.hibernationTimer); // TODO: [TS DEBT] class property not reassigned, need to find its purpose | 68 | // clearTimeout(this.hibernationTimer); // TODO: [TS DEBT] class property not reassigned, need to find its purpose |
69 | } | 69 | } |
70 | 70 | ||
diff --git a/src/components/settings/settings/EditSettingsForm.tsx b/src/components/settings/settings/EditSettingsForm.tsx index 210c8d9e9..1672a1411 100644 --- a/src/components/settings/settings/EditSettingsForm.tsx +++ b/src/components/settings/settings/EditSettingsForm.tsx | |||
@@ -397,7 +397,7 @@ class EditSettingsForm extends Component<IProps, IState> { | |||
397 | debug('cacheSize:', cacheSize); | 397 | debug('cacheSize:', cacheSize); |
398 | notCleared = | 398 | notCleared = |
399 | this.state.clearCacheButtonClicked && | 399 | this.state.clearCacheButtonClicked && |
400 | isClearingAllCache === false && | 400 | !isClearingAllCache && |
401 | cacheSizeBytes !== 0; | 401 | cacheSizeBytes !== 0; |
402 | } else { | 402 | } else { |
403 | cacheSize = '…'; | 403 | cacheSize = '…'; |
diff --git a/src/components/ui/AppLoader/index.tsx b/src/components/ui/AppLoader/index.tsx index 64c840aaa..4b5828ef4 100644 --- a/src/components/ui/AppLoader/index.tsx +++ b/src/components/ui/AppLoader/index.tsx | |||
@@ -61,7 +61,7 @@ class AppLoader extends Component<IProps, IState> { | |||
61 | className={classes.component} | 61 | className={classes.component} |
62 | spinnerColor={theme.colorAppLoaderSpinner} | 62 | spinnerColor={theme.colorAppLoaderSpinner} |
63 | > | 63 | > |
64 | {texts?.map((text, i) => ( | 64 | {texts.map((text, i) => ( |
65 | <span | 65 | <span |
66 | key={text} | 66 | key={text} |
67 | className={classnames({ | 67 | className={classnames({ |
diff --git a/src/components/ui/input/scorePassword.ts b/src/components/ui/input/scorePassword.ts index 59502e2b0..4a9f67265 100644 --- a/src/components/ui/input/scorePassword.ts +++ b/src/components/ui/input/scorePassword.ts | |||
@@ -33,7 +33,7 @@ export function scorePasswordFunc(password: string): number { | |||
33 | 33 | ||
34 | let variationCount = 0; | 34 | let variationCount = 0; |
35 | for (const key of Object.keys(variations)) { | 35 | for (const key of Object.keys(variations)) { |
36 | variationCount += variations[key] === true ? 1 : 0; | 36 | variationCount += variations[key] ? 1 : 0; |
37 | } | 37 | } |
38 | 38 | ||
39 | score += (variationCount - 1) * 10; | 39 | score += (variationCount - 1) * 10; |
diff --git a/src/components/ui/select/index.tsx b/src/components/ui/select/index.tsx index c06ac59b0..0d8520f58 100644 --- a/src/components/ui/select/index.tsx +++ b/src/components/ui/select/index.tsx | |||
@@ -282,23 +282,23 @@ class SelectComponent extends Component<IProps, IState> { | |||
282 | 282 | ||
283 | if (!open) return; | 283 | if (!open) return; |
284 | 284 | ||
285 | if (e.keyCode === 38 || e.keyCode === 40) { | 285 | if (e.key === 'ArrowUp' || e.key === 'ArrowDown') { |
286 | e.preventDefault(); | 286 | e.preventDefault(); |
287 | } | 287 | } |
288 | 288 | ||
289 | if (this.componentRef?.current) { | 289 | if (this.componentRef?.current) { |
290 | if (e.keyCode === 38 && selected > 0) { | 290 | if (e.key === 'ArrowUp' && selected > 0) { |
291 | this.setState((state: IState) => ({ | 291 | this.setState((state: IState) => ({ |
292 | selected: state.selected - 1, | 292 | selected: state.selected - 1, |
293 | })); | 293 | })); |
294 | } else if ( | 294 | } else if ( |
295 | e.keyCode === 40 && | 295 | e.key === 'ArrowDown' && |
296 | selected < Object.keys(options!).length - 1 | 296 | selected < Object.keys(options!).length - 1 |
297 | ) { | 297 | ) { |
298 | this.setState((state: IState) => ({ | 298 | this.setState((state: IState) => ({ |
299 | selected: state.selected + 1, | 299 | selected: state.selected + 1, |
300 | })); | 300 | })); |
301 | } else if (e.keyCode === 13) { | 301 | } else if (e.key === 'Enter') { |
302 | this.select(Object.keys(options!)[selected]); | 302 | this.select(Object.keys(options!)[selected]); |
303 | } | 303 | } |
304 | 304 | ||
@@ -311,19 +311,6 @@ class SelectComponent extends Component<IProps, IState> { | |||
311 | this.scrollContainerRef.current.scrollTop = topOffset - 35; | 311 | this.scrollContainerRef.current.scrollTop = topOffset - 35; |
312 | } | 312 | } |
313 | } | 313 | } |
314 | |||
315 | switch (e.keyCode) { | ||
316 | case 37: | ||
317 | case 39: | ||
318 | case 38: | ||
319 | case 40: // Arrow keys | ||
320 | case 32: { | ||
321 | break; | ||
322 | } // Space | ||
323 | default: { | ||
324 | break; | ||
325 | } // do not block other keys | ||
326 | } | ||
327 | } | 314 | } |
328 | 315 | ||
329 | render(): ReactElement { | 316 | render(): ReactElement { |
diff --git a/src/containers/settings/EditServiceScreen.tsx b/src/containers/settings/EditServiceScreen.tsx index ff2076fed..946ec09d3 100644 --- a/src/containers/settings/EditServiceScreen.tsx +++ b/src/containers/settings/EditServiceScreen.tsx | |||
@@ -261,7 +261,7 @@ class EditServiceScreen extends Component<IProps> { | |||
261 | }, | 261 | }, |
262 | customIcon: { | 262 | customIcon: { |
263 | label: intl.formatMessage(messages.icon), | 263 | label: intl.formatMessage(messages.icon), |
264 | value: service?.hasCustomUploadedIcon ? service?.icon : null, | 264 | value: service?.hasCustomUploadedIcon ? service.icon : null, |
265 | type: 'file', | 265 | type: 'file', |
266 | }, | 266 | }, |
267 | isDarkModeEnabled: { | 267 | isDarkModeEnabled: { |
@@ -276,21 +276,21 @@ class EditServiceScreen extends Component<IProps> { | |||
276 | darkReaderBrightness: { | 276 | darkReaderBrightness: { |
277 | label: intl.formatMessage(messages.darkReaderBrightness), | 277 | label: intl.formatMessage(messages.darkReaderBrightness), |
278 | value: service?.darkReaderSettings | 278 | value: service?.darkReaderSettings |
279 | ? service?.darkReaderSettings.brightness | 279 | ? service.darkReaderSettings.brightness |
280 | : DEFAULT_SERVICE_SETTINGS.darkReaderBrightness, | 280 | : DEFAULT_SERVICE_SETTINGS.darkReaderBrightness, |
281 | default: DEFAULT_SERVICE_SETTINGS.darkReaderBrightness, | 281 | default: DEFAULT_SERVICE_SETTINGS.darkReaderBrightness, |
282 | }, | 282 | }, |
283 | darkReaderContrast: { | 283 | darkReaderContrast: { |
284 | label: intl.formatMessage(messages.darkReaderContrast), | 284 | label: intl.formatMessage(messages.darkReaderContrast), |
285 | value: service?.darkReaderSettings | 285 | value: service?.darkReaderSettings |
286 | ? service?.darkReaderSettings.contrast | 286 | ? service.darkReaderSettings.contrast |
287 | : DEFAULT_SERVICE_SETTINGS.darkReaderContrast, | 287 | : DEFAULT_SERVICE_SETTINGS.darkReaderContrast, |
288 | default: DEFAULT_SERVICE_SETTINGS.darkReaderContrast, | 288 | default: DEFAULT_SERVICE_SETTINGS.darkReaderContrast, |
289 | }, | 289 | }, |
290 | darkReaderSepia: { | 290 | darkReaderSepia: { |
291 | label: intl.formatMessage(messages.darkReaderSepia), | 291 | label: intl.formatMessage(messages.darkReaderSepia), |
292 | value: service?.darkReaderSettings | 292 | value: service?.darkReaderSettings |
293 | ? service?.darkReaderSettings.sepia | 293 | ? service.darkReaderSettings.sepia |
294 | : DEFAULT_SERVICE_SETTINGS.darkReaderSepia, | 294 | : DEFAULT_SERVICE_SETTINGS.darkReaderSepia, |
295 | default: DEFAULT_SERVICE_SETTINGS.darkReaderSepia, | 295 | default: DEFAULT_SERVICE_SETTINGS.darkReaderSepia, |
296 | }, | 296 | }, |
diff --git a/src/features/quickSwitch/Component.tsx b/src/features/quickSwitch/Component.tsx index ab07e5d4d..7f6ad6432 100644 --- a/src/features/quickSwitch/Component.tsx +++ b/src/features/quickSwitch/Component.tsx | |||
@@ -88,14 +88,6 @@ interface IState { | |||
88 | @inject('stores', 'actions') | 88 | @inject('stores', 'actions') |
89 | @observer | 89 | @observer |
90 | class QuickSwitchModal extends Component<IProps, IState> { | 90 | class QuickSwitchModal extends Component<IProps, IState> { |
91 | ARROW_DOWN = 40; | ||
92 | |||
93 | ARROW_UP = 38; | ||
94 | |||
95 | ENTER = 13; | ||
96 | |||
97 | TAB = 9; | ||
98 | |||
99 | inputRef = createRef<HTMLDivElement>(); | 91 | inputRef = createRef<HTMLDivElement>(); |
100 | 92 | ||
101 | serviceElements = {}; | 93 | serviceElements = {}; |
@@ -214,12 +206,12 @@ class QuickSwitchModal extends Component<IProps, IState> { | |||
214 | // Handle global key presses to change the selection | 206 | // Handle global key presses to change the selection |
215 | _handleKeyDown(event: KeyboardEvent): void { | 207 | _handleKeyDown(event: KeyboardEvent): void { |
216 | if (ModalState.isModalVisible) { | 208 | if (ModalState.isModalVisible) { |
217 | switch (event.keyCode) { | 209 | switch (event.key) { |
218 | case this.ARROW_DOWN: { | 210 | case 'ArrowDown': { |
219 | this.changeSelected(1); | 211 | this.changeSelected(1); |
220 | break; | 212 | break; |
221 | } | 213 | } |
222 | case this.TAB: { | 214 | case 'Tab': { |
223 | if (event.shiftKey) { | 215 | if (event.shiftKey) { |
224 | this.changeSelected(-1); | 216 | this.changeSelected(-1); |
225 | } else { | 217 | } else { |
@@ -227,11 +219,11 @@ class QuickSwitchModal extends Component<IProps, IState> { | |||
227 | } | 219 | } |
228 | break; | 220 | break; |
229 | } | 221 | } |
230 | case this.ARROW_UP: { | 222 | case 'ArrowUp': { |
231 | this.changeSelected(-1); | 223 | this.changeSelected(-1); |
232 | break; | 224 | break; |
233 | } | 225 | } |
234 | case this.ENTER: { | 226 | case 'Enter': { |
235 | this.openService(this.state.selected); | 227 | this.openService(this.state.selected); |
236 | break; | 228 | break; |
237 | } | 229 | } |
diff --git a/src/helpers/service-helpers.ts b/src/helpers/service-helpers.ts index 678d5024f..f27d53285 100644 --- a/src/helpers/service-helpers.ts +++ b/src/helpers/service-helpers.ts | |||
@@ -12,7 +12,7 @@ export function removeServicePartitionDirectory( | |||
12 | const servicePartition = getServicePartitionsDirectory( | 12 | const servicePartition = getServicePartitionsDirectory( |
13 | `${addServicePrefix ? 'service-' : ''}${id}`, | 13 | `${addServicePrefix ? 'service-' : ''}${id}`, |
14 | ); | 14 | ); |
15 | return removeSync(servicePartition); | 15 | removeSync(servicePartition); |
16 | } | 16 | } |
17 | 17 | ||
18 | export async function getServiceIdsFromPartitions() { | 18 | export async function getServiceIdsFromPartitions() { |
diff --git a/src/helpers/update-helpers.ts b/src/helpers/update-helpers.ts index 9a36850fc..ca541c4b0 100644 --- a/src/helpers/update-helpers.ts +++ b/src/helpers/update-helpers.ts | |||
@@ -5,7 +5,7 @@ export function getFerdiumVersion( | |||
5 | currentLocation: string, | 5 | currentLocation: string, |
6 | ferdiumVersion: string, | 6 | ferdiumVersion: string, |
7 | ): string { | 7 | ): string { |
8 | const matches = currentLocation?.match(/version=([^&]*)/); | 8 | const matches = currentLocation.match(/version=([^&]*)/); |
9 | if (matches !== null) { | 9 | if (matches !== null) { |
10 | return `v${matches[1]}`; | 10 | return `v${matches[1]}`; |
11 | } | 11 | } |
diff --git a/src/helpers/userAgent-helpers.ts b/src/helpers/userAgent-helpers.ts index bc99fbc52..42e3a9851 100644 --- a/src/helpers/userAgent-helpers.ts +++ b/src/helpers/userAgent-helpers.ts | |||
@@ -13,7 +13,7 @@ import { | |||
13 | function macOS() { | 13 | function macOS() { |
14 | const version = macosVersion() ?? ''; | 14 | const version = macosVersion() ?? ''; |
15 | let cpuName = cpus()[0].model.split(' ')[0]; | 15 | let cpuName = cpus()[0].model.split(' ')[0]; |
16 | if (cpuName && /\(/.test(cpuName)) { | 16 | if (cpuName.includes('(')) { |
17 | // eslint-disable-next-line prefer-destructuring | 17 | // eslint-disable-next-line prefer-destructuring |
18 | cpuName = cpuName.split('(')[0]; | 18 | cpuName = cpuName.split('(')[0]; |
19 | } | 19 | } |
diff --git a/src/lib/Tray.ts b/src/lib/Tray.ts index c8f113346..d83f91478 100644 --- a/src/lib/Tray.ts +++ b/src/lib/Tray.ts | |||
@@ -153,16 +153,13 @@ export default class TrayIcon { | |||
153 | 153 | ||
154 | _toggleWindow(): void { | 154 | _toggleWindow(): void { |
155 | const [mainWindow] = BrowserWindow.getAllWindows(); | 155 | const [mainWindow] = BrowserWindow.getAllWindows(); |
156 | if (!mainWindow) { | ||
157 | return; | ||
158 | } | ||
159 | 156 | ||
160 | if (mainWindow.isMinimized()) { | 157 | if (mainWindow.isMinimized()) { |
161 | mainWindow.restore(); | 158 | mainWindow.restore(); |
162 | } else if (mainWindow.isVisible() && mainWindow.isFocused()) { | 159 | } else if (mainWindow.isVisible() && mainWindow.isFocused()) { |
163 | if (isMac && mainWindow.isFullScreen()) { | 160 | if (isMac && mainWindow.isFullScreen()) { |
164 | mainWindow.once('show', () => mainWindow?.setFullScreen(true)); | 161 | mainWindow.once('show', () => mainWindow.setFullScreen(true)); |
165 | mainWindow.once('leave-full-screen', () => mainWindow?.hide()); | 162 | mainWindow.once('leave-full-screen', () => mainWindow.hide()); |
166 | mainWindow.setFullScreen(false); | 163 | mainWindow.setFullScreen(false); |
167 | } else { | 164 | } else { |
168 | mainWindow.hide(); | 165 | mainWindow.hide(); |
diff --git a/src/stores/ServicesStore.ts b/src/stores/ServicesStore.ts index 9c0072586..95aae6ccb 100644 --- a/src/stores/ServicesStore.ts +++ b/src/stores/ServicesStore.ts | |||
@@ -966,7 +966,8 @@ export default class ServicesStore extends TypedStore { | |||
966 | service.lostRecipeConnection = false; | 966 | service.lostRecipeConnection = false; |
967 | 967 | ||
968 | if (service.isTodosService) { | 968 | if (service.isTodosService) { |
969 | return this.actions.todos.reload(); | 969 | this.actions.todos.reload(); |
970 | return; | ||
970 | } | 971 | } |
971 | 972 | ||
972 | if (!service.webview) return; | 973 | if (!service.webview) return; |
diff --git a/src/webview/contextMenuBuilder.ts b/src/webview/contextMenuBuilder.ts index 93dfbebb6..ee55fbe62 100644 --- a/src/webview/contextMenuBuilder.ts +++ b/src/webview/contextMenuBuilder.ts | |||
@@ -101,7 +101,7 @@ function translatePopup(res, isError: boolean = false) { | |||
101 | 101 | ||
102 | document.addEventListener('click', e => { | 102 | document.addEventListener('click', e => { |
103 | if (div !== e.target && !childOf(e.target, div)) { | 103 | if (div !== e.target && !childOf(e.target, div)) { |
104 | div?.remove(); | 104 | div.remove(); |
105 | } | 105 | } |
106 | }); | 106 | }); |
107 | } | 107 | } |
@@ -253,10 +253,7 @@ export class ContextMenuBuilder { | |||
253 | return this.buildMenuForVideo(info); | 253 | return this.buildMenuForVideo(info); |
254 | } | 254 | } |
255 | 255 | ||
256 | if ( | 256 | if (info.isEditable || info.inputFieldType !== 'none') { |
257 | info.isEditable || | ||
258 | (info.inputFieldType && info.inputFieldType !== 'none') | ||
259 | ) { | ||
260 | return this.buildMenuForTextInput(info); | 257 | return this.buildMenuForTextInput(info); |
261 | } | 258 | } |
262 | 259 | ||