From 6db0d2a3b51727555c11ed83f0b4d4aa9c8a0c2a Mon Sep 17 00:00:00 2001 From: Oliver Schwendener Date: Sat, 2 Mar 2024 18:02:22 +0100 Subject: [PATCH] Applied suggestions from code inspection --- src/common/Core/ContextBridge.ts | 2 +- src/common/Extensions/Shortcuts/Shortcut.ts | 2 +- .../CopyToClipboardActionHandler.ts | 4 ++-- src/main/Extensions/Calculator/Calculator.ts | 6 +----- src/main/Extensions/Shortcuts/Shortcuts.ts | 8 ++++---- .../UeliCommandActionHandler.test.ts | 8 ++++---- ...Engine.ts => DuckDuckGoWebSearchEngine.ts} | 2 +- .../WebSearch/WebSearchExtension.test.ts | 2 +- .../WebSearch/WebSearchExtensionModule.ts | 4 ++-- src/preload/index.ts | 2 +- src/renderer/Core/Components/BasicSearch.tsx | 10 +++++----- .../Core/Settings/Pages/Debug/ResetCache.tsx | 6 +++--- .../Core/Settings/Pages/Extensions.tsx | 7 ++++--- .../Core/Settings/Pages/Window/Window.tsx | 2 +- .../Windows/FileExtensions.tsx | 8 ++++---- .../ApplicationSearch/Windows/Folders.tsx | 8 ++++---- .../DeeplTranslatorSettings.tsx | 20 +++++++++---------- .../Extensions/FileSearch/FileSearch.tsx | 9 ++++----- .../Extensions/Shortcuts/EditModal.tsx | 6 +++--- .../Shortcuts/ShortcutsSettings.tsx | 12 +++++------ 20 files changed, 62 insertions(+), 66 deletions(-) rename src/main/Extensions/WebSearch/{DuckduckGoWebSearchEngine.ts => DuckDuckGoWebSearchEngine.ts} (95%) diff --git a/src/common/Core/ContextBridge.ts b/src/common/Core/ContextBridge.ts index 18ad3bd84..08c8b9b9f 100644 --- a/src/common/Core/ContextBridge.ts +++ b/src/common/Core/ContextBridge.ts @@ -11,7 +11,7 @@ export type ContextBridge = { on: IpcRenderer["on"]; }; - resetChache: () => Promise; + resetCache: () => Promise; copyTextToClipboard: (textToCopy: string) => void; extensionDisabled: (extensionId: string) => void; extensionEnabled: (extensionId: string) => void; diff --git a/src/common/Extensions/Shortcuts/Shortcut.ts b/src/common/Extensions/Shortcuts/Shortcut.ts index 23e5396f3..4be35c446 100644 --- a/src/common/Extensions/Shortcuts/Shortcut.ts +++ b/src/common/Extensions/Shortcuts/Shortcut.ts @@ -5,5 +5,5 @@ export type Shortcut = { id: string; type: ShortcutType; argument: string; - hideWindowAfterInvokation?: boolean; + hideWindowAfterInvocation?: boolean; }; diff --git a/src/main/Core/ActionHandler/DefaultActionHandlers/CopyToClipboardActionHandler.ts b/src/main/Core/ActionHandler/DefaultActionHandlers/CopyToClipboardActionHandler.ts index 23b8cbaff..4e0be6d75 100644 --- a/src/main/Core/ActionHandler/DefaultActionHandlers/CopyToClipboardActionHandler.ts +++ b/src/main/Core/ActionHandler/DefaultActionHandlers/CopyToClipboardActionHandler.ts @@ -8,11 +8,11 @@ export class CopyToClipboardActionHandler implements ActionHandler { public constructor( private readonly clipboard: Clipboard, - private readonly browserWindowNotifer: BrowserWindowNotifier, + private readonly browserWindowNotifier: BrowserWindowNotifier, ) {} public async invokeAction(action: SearchResultItemAction): Promise { this.clipboard.writeText(action.argument); - this.browserWindowNotifer.notify("copiedToClipboard"); + this.browserWindowNotifier.notify("copiedToClipboard"); } } diff --git a/src/main/Extensions/Calculator/Calculator.ts b/src/main/Extensions/Calculator/Calculator.ts index a715ad07e..6744c9122 100644 --- a/src/main/Extensions/Calculator/Calculator.ts +++ b/src/main/Extensions/Calculator/Calculator.ts @@ -87,10 +87,6 @@ export class Calculator { private static isValidMathType(value: any): boolean { const mathType = typeOf(value); - if ((mathType === "Unit" && value.value === null) || mathType === "function") { - return false; - } - - return true; + return !((mathType === "Unit" && value.value === null) || mathType === "function"); } } diff --git a/src/main/Extensions/Shortcuts/Shortcuts.ts b/src/main/Extensions/Shortcuts/Shortcuts.ts index a2e19af03..f5b01cabb 100644 --- a/src/main/Extensions/Shortcuts/Shortcuts.ts +++ b/src/main/Extensions/Shortcuts/Shortcuts.ts @@ -45,7 +45,7 @@ export class Shortcuts implements Extension { const images = await this.getSearchResultItemImages(shortcuts); return shortcuts.map( - ({ name, id, type, argument, hideWindowAfterInvokation }): SearchResultItem => ({ + ({ name, id, type, argument, hideWindowAfterInvocation }): SearchResultItem => ({ name: name, description: "Shortcut", descriptionTranslation: { @@ -62,7 +62,7 @@ export class Shortcuts implements Extension { namespace: Shortcuts.translationNamespace, }, handlerId: "Shortcut", - hideWindowAfterInvocation: hideWindowAfterInvokation, + hideWindowAfterInvocation, fluentIcon: "ArrowSquareUpRightRegular", }, }), @@ -101,7 +101,7 @@ export class Shortcuts implements Extension { fileOrFolderDoesNotExist: "File/folder does not exist", name: "Name", invalidName: "Invalid name", - hideWindowAfterInvokation: "Hide window after invokation", + hideWindowAfterInvocation: "Hide window after invocation", createShortcut: "Create Shortcut", editShortcut: "Edit Shortcut", save: "Save", @@ -122,7 +122,7 @@ export class Shortcuts implements Extension { fileOrFolderDoesNotExist: "Datei/Ordner existiert nicht", name: "Name", invalidName: "Ungültiger Name", - hideWindowAfterInvokation: "Fester verstecken nach Ausführung", + hideWindowAfterInvocation: "Fester verstecken nach Ausführung", createShortcut: "Verknüpfung erstellen", editShortcut: "Verknüpfung bearbeiten", save: "Speichern", diff --git a/src/main/Extensions/UeliCommand/UeliCommandActionHandler.test.ts b/src/main/Extensions/UeliCommand/UeliCommandActionHandler.test.ts index f074e7678..ae01d14b7 100644 --- a/src/main/Extensions/UeliCommand/UeliCommandActionHandler.test.ts +++ b/src/main/Extensions/UeliCommand/UeliCommandActionHandler.test.ts @@ -24,22 +24,22 @@ describe(UeliCommandActionHandler, () => { }; it("should invoke an ueli command", async () => { - testInvokeAction({ + await testInvokeAction({ searchResultItemAction: { argument: "quit" }, expectedUeliCommand: "quit", }); - testInvokeAction({ + await testInvokeAction({ searchResultItemAction: { argument: "settings" }, expectedUeliCommand: "openSettings", }); - testInvokeAction({ + await testInvokeAction({ searchResultItemAction: { argument: "extensions" }, expectedUeliCommand: "openExtensions", }); - testInvokeAction({ + await testInvokeAction({ searchResultItemAction: { argument: "centerWindow" }, expectedUeliCommand: "centerWindow", }); diff --git a/src/main/Extensions/WebSearch/DuckduckGoWebSearchEngine.ts b/src/main/Extensions/WebSearch/DuckDuckGoWebSearchEngine.ts similarity index 95% rename from src/main/Extensions/WebSearch/DuckduckGoWebSearchEngine.ts rename to src/main/Extensions/WebSearch/DuckDuckGoWebSearchEngine.ts index b1d4b56c2..fd65ab8f1 100644 --- a/src/main/Extensions/WebSearch/DuckduckGoWebSearchEngine.ts +++ b/src/main/Extensions/WebSearch/DuckDuckGoWebSearchEngine.ts @@ -6,7 +6,7 @@ type DuckDuckGoSuggestion = { phrase: string; }; -export class DuckduckGoWebSearchEngine implements WebSearchEngine { +export class DuckDuckGoWebSearchEngine implements WebSearchEngine { public constructor(private readonly net: Net) {} public async getSuggestions(searchTerm: string, locale: string): Promise { diff --git a/src/main/Extensions/WebSearch/WebSearchExtension.test.ts b/src/main/Extensions/WebSearch/WebSearchExtension.test.ts index 501a36941..9c0f4c505 100644 --- a/src/main/Extensions/WebSearch/WebSearchExtension.test.ts +++ b/src/main/Extensions/WebSearch/WebSearchExtension.test.ts @@ -195,7 +195,7 @@ describe(WebSearchExtension, () => { expect(getValueMock).toHaveBeenCalledWith(getExtensionSettingKey("WebSearch", "searchEngine"), "Google"); }); - it("should return the suggestions on invokation", async () => { + it("should return the suggestions on invocation", async () => { const getSearchEngineMock = vi.fn().mockReturnValue("MyEngine"); const getLocaleMock = vi.fn().mockReturnValue("de-CH"); const getExtensionAssetPathMock = vi.fn().mockReturnValue("assets/asset.png"); diff --git a/src/main/Extensions/WebSearch/WebSearchExtensionModule.ts b/src/main/Extensions/WebSearch/WebSearchExtensionModule.ts index cfdfcd619..18380d8d4 100644 --- a/src/main/Extensions/WebSearch/WebSearchExtensionModule.ts +++ b/src/main/Extensions/WebSearch/WebSearchExtensionModule.ts @@ -2,7 +2,7 @@ import type { Dependencies } from "@Core/Dependencies"; import type { DependencyRegistry } from "@Core/DependencyRegistry"; import type { ExtensionBootstrapResult } from "../ExtensionBootstrapResult"; import type { ExtensionModule } from "../ExtensionModule"; -import { DuckduckGoWebSearchEngine } from "./DuckduckGoWebSearchEngine"; +import { DuckDuckGoWebSearchEngine } from "./DuckDuckGoWebSearchEngine"; import { GoogleWebSearchEngine } from "./GoogleWebSearchEngine"; import { WebSearchExtension } from "./WebSearchExtension"; @@ -14,7 +14,7 @@ export class WebSearchExtensionModule implements ExtensionModule { return { extension: new WebSearchExtension(assetPathResolver, settingsManager, [ - new DuckduckGoWebSearchEngine(net), + new DuckDuckGoWebSearchEngine(net), new GoogleWebSearchEngine(net), ]), }; diff --git a/src/preload/index.ts b/src/preload/index.ts index d6911726b..cdc064bb0 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -6,7 +6,7 @@ const contextBridgeImplementation: ContextBridge = { on: (channel, listener) => ipcRenderer.on(channel, listener), }, - resetChache: () => ipcRenderer.invoke("resetCache"), + resetCache: () => ipcRenderer.invoke("resetCache"), copyTextToClipboard: (textToCopy) => ipcRenderer.send("copyTextToClipboard", { textToCopy }), extensionDisabled: (extensionId) => ipcRenderer.send("extensionDisabled", { extensionId }), extensionEnabled: (extensionId) => ipcRenderer.send("extensionEnabled", { extensionId }), diff --git a/src/renderer/Core/Components/BasicSearch.tsx b/src/renderer/Core/Components/BasicSearch.tsx index 6bfdd73b9..98fee9b17 100644 --- a/src/renderer/Core/Components/BasicSearch.tsx +++ b/src/renderer/Core/Components/BasicSearch.tsx @@ -5,7 +5,7 @@ import { SearchResultList } from "@Core/Search/SearchResultList"; import type { SearchResultItem } from "@common/Core"; import { Button, Input, ProgressBar } from "@fluentui/react-components"; import { ArrowLeftFilled, SearchRegular } from "@fluentui/react-icons"; -import { useEffect, useRef, useState } from "react"; +import { KeyboardEvent, useEffect, useRef, useState } from "react"; import { useNavigate } from "react-router"; type BasicSearchProps = { @@ -43,7 +43,7 @@ export const BasicSearch = ({ const goBack = () => navigate({ pathname: "/" }); - const handleKeyDownEvent = (event: React.KeyboardEvent) => { + const handleKeyDownEvent = async (event: KeyboardEvent) => { if (event.key === "ArrowDown") { event.preventDefault(); selectNextSearchResultItem(); @@ -52,15 +52,15 @@ export const BasicSearch = ({ selectPreviousSearchResultItem(); } else if (event.key === "Enter") { event.preventDefault(); - invokeSelectedSearchResultItem(); + await invokeSelectedSearchResultItem(); } }; - const invokeSelectedSearchResultItem = () => { + const invokeSelectedSearchResultItem = async () => { const selectedSearchResultItem = getSelectedSearchResultItem(); if (selectedSearchResultItem) { - contextBridge.invokeAction(selectedSearchResultItem.defaultAction); + await contextBridge.invokeAction(selectedSearchResultItem.defaultAction); } }; diff --git a/src/renderer/Core/Settings/Pages/Debug/ResetCache.tsx b/src/renderer/Core/Settings/Pages/Debug/ResetCache.tsx index edcaf11e9..e3d9eadeb 100644 --- a/src/renderer/Core/Settings/Pages/Debug/ResetCache.tsx +++ b/src/renderer/Core/Settings/Pages/Debug/ResetCache.tsx @@ -21,11 +21,11 @@ export const ResetCache = () => { const [dialogIsOpen, setDialogIsOpen] = useState(false); const [resetIsRunning, setResetIsRunning] = useState(false); - const resetChache = async () => { + const resetCache = async () => { setResetIsRunning(true); try { - await contextBridge.resetChache(); + await contextBridge.resetCache(); } catch (error) { // do nothing } finally { @@ -71,7 +71,7 @@ export const ResetCache = () => { > {t("resetCacheCancel", { ns })} - diff --git a/src/renderer/Core/Settings/Pages/Extensions.tsx b/src/renderer/Core/Settings/Pages/Extensions.tsx index 7798d1c1c..01eb31036 100644 --- a/src/renderer/Core/Settings/Pages/Extensions.tsx +++ b/src/renderer/Core/Settings/Pages/Extensions.tsx @@ -18,6 +18,7 @@ import { useToastController, } from "@fluentui/react-components"; import { ArrowClockwiseRegular } from "@fluentui/react-icons"; +import { MouseEvent } from "react"; import { useTranslation } from "react-i18next"; export const Extensions = () => { @@ -50,7 +51,7 @@ export const Extensions = () => { disableExtension(extensionId); }; - const triggerExtensionRescan = async (event: React.MouseEvent, extensionId: string) => { + const triggerExtensionRescan = async (event: MouseEvent, extensionId: string) => { event.preventDefault(); await contextBridge.triggerExtensionRescan(extensionId); const { name, nameTranslation } = contextBridge.getExtension(extensionId); @@ -116,9 +117,9 @@ export const Extensions = () => { { + onClick={async (e) => { e.preventDefault(); - contextBridge.openExternal( + await contextBridge.openExternal( `https://github.com/${author.githubUserName}`, ); }} diff --git a/src/renderer/Core/Settings/Pages/Window/Window.tsx b/src/renderer/Core/Settings/Pages/Window/Window.tsx index 15945514d..8f059ed37 100644 --- a/src/renderer/Core/Settings/Pages/Window/Window.tsx +++ b/src/renderer/Core/Settings/Pages/Window/Window.tsx @@ -1,4 +1,4 @@ -import { useContextBridge, useSetting } from "../../../Hooks"; +import { useContextBridge, useSetting } from "@Core/Hooks"; import { Section } from "../../Section"; import { SectionList } from "../../SectionList"; import { AlwaysOnTop } from "./AlwaysOnTop"; diff --git a/src/renderer/Extensions/ApplicationSearch/Windows/FileExtensions.tsx b/src/renderer/Extensions/ApplicationSearch/Windows/FileExtensions.tsx index 4de88b5c9..2dbd9fde9 100644 --- a/src/renderer/Extensions/ApplicationSearch/Windows/FileExtensions.tsx +++ b/src/renderer/Extensions/ApplicationSearch/Windows/FileExtensions.tsx @@ -11,12 +11,12 @@ export const FileExtensions = () => { key: "windowsFileExtensions", }); - const removeFileExtension = (fileExtension: string) => { - setFileExtensions(fileExtensions.filter((f) => f !== fileExtension)); + const removeFileExtension = async (fileExtension: string) => { + await setFileExtensions(fileExtensions.filter((f) => f !== fileExtension)); }; - const addFileExtension = (fileExtension: string) => { - setFileExtensions([...fileExtensions, fileExtension]); + const addFileExtension = async (fileExtension: string) => { + await setFileExtensions([...fileExtensions, fileExtension]); setNewFileExtension(""); }; diff --git a/src/renderer/Extensions/ApplicationSearch/Windows/Folders.tsx b/src/renderer/Extensions/ApplicationSearch/Windows/Folders.tsx index 0fea579ca..81bb896d0 100644 --- a/src/renderer/Extensions/ApplicationSearch/Windows/Folders.tsx +++ b/src/renderer/Extensions/ApplicationSearch/Windows/Folders.tsx @@ -13,12 +13,12 @@ export const Folders = () => { const [newFolder, setNewFolder] = useState(""); - const removeFolder = (folder: string) => { - setFolders(folders.filter((f) => f !== folder)); + const removeFolder = async (folder: string) => { + await setFolders(folders.filter((f) => f !== folder)); }; - const addFolder = (folder: string) => { - setFolders([...folders, folder]); + const addFolder = async (folder: string) => { + await setFolders([...folders, folder]); setNewFolder(""); }; diff --git a/src/renderer/Extensions/DeeplTranslator/DeeplTranslatorSettings.tsx b/src/renderer/Extensions/DeeplTranslator/DeeplTranslatorSettings.tsx index 13880f5d3..a26355cc6 100644 --- a/src/renderer/Extensions/DeeplTranslator/DeeplTranslatorSettings.tsx +++ b/src/renderer/Extensions/DeeplTranslator/DeeplTranslatorSettings.tsx @@ -25,12 +25,12 @@ export const DeeplTranslatorSettings = () => { key: "defaultTargetLanguage", }); - const sourceLanguageVirutalizer = useStaticVirtualizerMeasure({ + const sourceLanguageVirtualizerMeasure = useStaticVirtualizerMeasure({ defaultItemSize: 20, direction: "vertical", }); - const targetLanguageVirutalizer = useStaticVirtualizerMeasure({ + const targetLanguageVirtzalizerMeasure = useStaticVirtualizerMeasure({ defaultItemSize: 20, direction: "vertical", }); @@ -48,13 +48,13 @@ export const DeeplTranslatorSettings = () => { value={sourceLanguages[sourceLanguage]} onOptionSelect={(_, { optionValue }) => optionValue && setSourceLanguage(optionValue)} selectedOptions={[sourceLanguage]} - listbox={{ ref: sourceLanguageVirutalizer.scrollRef, style: { maxHeight: 145 } }} + listbox={{ ref: sourceLanguageVirtualizerMeasure.scrollRef, style: { maxHeight: 145 } }} > {(i) => ( @@ -76,13 +76,13 @@ export const DeeplTranslatorSettings = () => { value={targetLanguages[targetLanguage]} onOptionSelect={(_, { optionValue }) => optionValue && setTargetLanguage(optionValue)} selectedOptions={[targetLanguage]} - listbox={{ ref: targetLanguageVirutalizer.scrollRef, style: { maxHeight: 145 } }} + listbox={{ ref: targetLanguageVirtzalizerMeasure.scrollRef, style: { maxHeight: 145 } }} > {(i) => ( diff --git a/src/renderer/Extensions/FileSearch/FileSearch.tsx b/src/renderer/Extensions/FileSearch/FileSearch.tsx index 0d811bef0..cce9a0389 100644 --- a/src/renderer/Extensions/FileSearch/FileSearch.tsx +++ b/src/renderer/Extensions/FileSearch/FileSearch.tsx @@ -12,11 +12,10 @@ export const FileSearch = ({ contextBridge, goBack }: ExtensionProps) => { const getSearchResultItems = async (searchTerm: string) => { try { - const searchResultItems = await contextBridge.invokeExtension< - { searchTerm: string }, - Promise - >("FileSearch", { searchTerm }); - return searchResultItems; + return await contextBridge.invokeExtension<{ searchTerm: string }, Promise>( + "FileSearch", + { searchTerm }, + ); } catch (error) { return []; } diff --git a/src/renderer/Extensions/Shortcuts/EditModal.tsx b/src/renderer/Extensions/Shortcuts/EditModal.tsx index 22208295f..c8107b6b8 100644 --- a/src/renderer/Extensions/Shortcuts/EditModal.tsx +++ b/src/renderer/Extensions/Shortcuts/EditModal.tsx @@ -156,10 +156,10 @@ export const EditModal = ({ /> {argumentElements[temporaryShortcut.type]} - + setProperty("hideWindowAfterInvokation", checked)} + checked={temporaryShortcut.hideWindowAfterInvocation} + onChange={(_, { checked }) => setProperty("hideWindowAfterInvocation", checked)} /> diff --git a/src/renderer/Extensions/Shortcuts/ShortcutsSettings.tsx b/src/renderer/Extensions/Shortcuts/ShortcutsSettings.tsx index d8213a1bf..bfc1cbe1b 100644 --- a/src/renderer/Extensions/Shortcuts/ShortcutsSettings.tsx +++ b/src/renderer/Extensions/Shortcuts/ShortcutsSettings.tsx @@ -21,16 +21,16 @@ export const ShortcutsSettings = () => { key: "shortcuts", }); - const removeShortcut = (id: string) => { - setShortcuts(shortcuts.filter((s) => s.id !== id)); + const removeShortcut = async (id: string) => { + await setShortcuts(shortcuts.filter((s) => s.id !== id)); }; - const editShortcut = (shortcut: Shortcut) => { - setShortcuts(shortcuts.map((s) => (s.id === shortcut.id ? shortcut : s))); + const editShortcut = async (shortcut: Shortcut) => { + await setShortcuts(shortcuts.map((s) => (s.id === shortcut.id ? shortcut : s))); }; - const addShortcut = (shortcut: Shortcut) => { - setShortcuts([...shortcuts, shortcut]); + const addShortcut = async (shortcut: Shortcut) => { + await setShortcuts([...shortcuts, shortcut]); }; const getSearchResultItemByShortcutId = (id: string) => {