Skip to content

Commit

Permalink
Applied suggestions from code inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener committed Mar 2, 2024
1 parent 03e1ccd commit 6db0d2a
Show file tree
Hide file tree
Showing 20 changed files with 62 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/common/Core/ContextBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type ContextBridge = {
on: IpcRenderer["on"];
};

resetChache: () => Promise<void>;
resetCache: () => Promise<void>;
copyTextToClipboard: (textToCopy: string) => void;
extensionDisabled: (extensionId: string) => void;
extensionEnabled: (extensionId: string) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/common/Extensions/Shortcuts/Shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export type Shortcut = {
id: string;
type: ShortcutType;
argument: string;
hideWindowAfterInvokation?: boolean;
hideWindowAfterInvocation?: boolean;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
this.clipboard.writeText(action.argument);
this.browserWindowNotifer.notify("copiedToClipboard");
this.browserWindowNotifier.notify("copiedToClipboard");
}
}
6 changes: 1 addition & 5 deletions src/main/Extensions/Calculator/Calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
8 changes: 4 additions & 4 deletions src/main/Extensions/Shortcuts/Shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -62,7 +62,7 @@ export class Shortcuts implements Extension {
namespace: Shortcuts.translationNamespace,
},
handlerId: "Shortcut",
hideWindowAfterInvocation: hideWindowAfterInvokation,
hideWindowAfterInvocation,
fluentIcon: "ArrowSquareUpRightRegular",
},
}),
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ describe(UeliCommandActionHandler, () => {
};

it("should invoke an ueli command", async () => {
testInvokeAction({
await testInvokeAction({
searchResultItemAction: <SearchResultItemAction>{ argument: "quit" },
expectedUeliCommand: "quit",
});

testInvokeAction({
await testInvokeAction({
searchResultItemAction: <SearchResultItemAction>{ argument: "settings" },
expectedUeliCommand: "openSettings",
});

testInvokeAction({
await testInvokeAction({
searchResultItemAction: <SearchResultItemAction>{ argument: "extensions" },
expectedUeliCommand: "openExtensions",
});

testInvokeAction({
await testInvokeAction({
searchResultItemAction: <SearchResultItemAction>{ argument: "centerWindow" },
expectedUeliCommand: "centerWindow",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Suggestion[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/main/Extensions/WebSearch/WebSearchExtension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/main/Extensions/WebSearch/WebSearchExtensionModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -14,7 +14,7 @@ export class WebSearchExtensionModule implements ExtensionModule {

return {
extension: new WebSearchExtension(assetPathResolver, settingsManager, [
new DuckduckGoWebSearchEngine(net),
new DuckDuckGoWebSearchEngine(net),
new GoogleWebSearchEngine(net),
]),
};
Expand Down
2 changes: 1 addition & 1 deletion src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/Core/Components/BasicSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/renderer/Core/Settings/Pages/Debug/ResetCache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export const ResetCache = () => {
const [dialogIsOpen, setDialogIsOpen] = useState<boolean>(false);
const [resetIsRunning, setResetIsRunning] = useState<boolean>(false);

const resetChache = async () => {
const resetCache = async () => {
setResetIsRunning(true);

try {
await contextBridge.resetChache();
await contextBridge.resetCache();
} catch (error) {
// do nothing
} finally {
Expand Down Expand Up @@ -71,7 +71,7 @@ export const ResetCache = () => {
>
{t("resetCacheCancel", { ns })}
</Button>
<Button disabled={resetIsRunning} onClick={() => resetChache()} appearance="primary">
<Button disabled={resetIsRunning} onClick={() => resetCache()} appearance="primary">
{t("resetCacheConfirm", { ns })}
</Button>
</DialogActions>
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/Core/Settings/Pages/Extensions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -116,9 +117,9 @@ export const Extensions = () => {
<TableCellLayout>
<Link
appearance="subtle"
onClick={(e) => {
onClick={async (e) => {
e.preventDefault();
contextBridge.openExternal(
await contextBridge.openExternal(
`https://github.com/${author.githubUserName}`,
);
}}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/Core/Settings/Pages/Window/Window.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
};

Expand Down
8 changes: 4 additions & 4 deletions src/renderer/Extensions/ApplicationSearch/Windows/Folders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export const Folders = () => {

const [newFolder, setNewFolder] = useState<string>("");

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("");
};

Expand Down
20 changes: 10 additions & 10 deletions src/renderer/Extensions/DeeplTranslator/DeeplTranslatorSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
Expand All @@ -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 } }}
>
<Virtualizer
numItems={Object.keys(sourceLanguages).length}
virtualizerLength={sourceLanguageVirutalizer.virtualizerLength}
bufferItems={sourceLanguageVirutalizer.bufferItems}
bufferSize={sourceLanguageVirutalizer.bufferSize}
virtualizerLength={sourceLanguageVirtualizerMeasure.virtualizerLength}
bufferItems={sourceLanguageVirtualizerMeasure.bufferItems}
bufferSize={sourceLanguageVirtualizerMeasure.bufferSize}
itemSize={20}
>
{(i) => (
Expand All @@ -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 } }}
>
<Virtualizer
numItems={Object.keys(targetLanguages).length}
virtualizerLength={targetLanguageVirutalizer.virtualizerLength}
bufferItems={targetLanguageVirutalizer.bufferItems}
bufferSize={targetLanguageVirutalizer.bufferSize}
virtualizerLength={targetLanguageVirtzalizerMeasure.virtualizerLength}
bufferItems={targetLanguageVirtzalizerMeasure.bufferItems}
bufferSize={targetLanguageVirtzalizerMeasure.bufferSize}
itemSize={20}
>
{(i) => (
Expand Down
9 changes: 4 additions & 5 deletions src/renderer/Extensions/FileSearch/FileSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ export const FileSearch = ({ contextBridge, goBack }: ExtensionProps) => {

const getSearchResultItems = async (searchTerm: string) => {
try {
const searchResultItems = await contextBridge.invokeExtension<
{ searchTerm: string },
Promise<SearchResultItem[]>
>("FileSearch", { searchTerm });
return searchResultItems;
return await contextBridge.invokeExtension<{ searchTerm: string }, Promise<SearchResultItem[]>>(
"FileSearch",
{ searchTerm },
);
} catch (error) {
return [];
}
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/Extensions/Shortcuts/EditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ export const EditModal = ({
/>
</Field>
{argumentElements[temporaryShortcut.type]}
<Field label={t("hideWindowAfterInvokation", { ns })}>
<Field label={t("hideWindowAfterInvocation", { ns })}>
<Switch
checked={temporaryShortcut.hideWindowAfterInvokation}
onChange={(_, { checked }) => setProperty("hideWindowAfterInvokation", checked)}
checked={temporaryShortcut.hideWindowAfterInvocation}
onChange={(_, { checked }) => setProperty("hideWindowAfterInvocation", checked)}
/>
</Field>
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/renderer/Extensions/Shortcuts/ShortcutsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 6db0d2a

Please sign in to comment.