diff --git a/src/main/Extensions/ApplicationSearch/Windows/WindowsApplicationRepository.ts b/src/main/Extensions/ApplicationSearch/Windows/WindowsApplicationRepository.ts index 8e83ceb11..daf85d5db 100644 --- a/src/main/Extensions/ApplicationSearch/Windows/WindowsApplicationRepository.ts +++ b/src/main/Extensions/ApplicationSearch/Windows/WindowsApplicationRepository.ts @@ -14,7 +14,16 @@ export class WindowsApplicationRepository implements ApplicationRepository { ) {} public async getApplications(): Promise { - const stdout = await this.powershellUtility.executeScript(this.getPowershellScript()); + const folderPaths = this.settings.getValue("windowsFolders"); + const fileExtensions = this.settings.getValue("windowsFileExtensions"); + + if (!folderPaths.length || !fileExtensions.length) { + return []; + } + + const stdout = await this.powershellUtility.executeScript( + this.getPowershellScript(folderPaths, fileExtensions), + ); const windowsApplicationRetrieverResults = JSON.parse(stdout); @@ -23,16 +32,9 @@ export class WindowsApplicationRepository implements ApplicationRepository { ); } - private getPowershellScript(): string { - const folderPaths = this.settings - .getValue("windowsFolders") - .map((folderPath) => `'${folderPath}'`) - .join(","); - - const fileExtensions = this.settings - .getValue("windowsFileExtensions") - .map((fileExtension) => `'*.${fileExtension}'`) - .join(","); + private getPowershellScript(folderPaths: string[], fileExtensions: string[]): string { + const concatenatedFolderPaths = folderPaths.map((folderPath) => `'${folderPath}'`).join(","); + const concatenatedFileExtensions = fileExtensions.map((fileExtension) => `'*.${fileExtension}'`).join(","); const { extractShortcutPowershellScript, getWindowsAppsPowershellScript } = usePowershellScripts(); @@ -40,6 +42,6 @@ export class WindowsApplicationRepository implements ApplicationRepository { ${extractShortcutPowershellScript} ${getWindowsAppsPowershellScript} - Get-WindowsApps -FolderPaths ${folderPaths} -FileExtensions ${fileExtensions} -AppIconFolder '${this.extensionCacheFolder.path}';`; + Get-WindowsApps -FolderPaths ${concatenatedFolderPaths} -FileExtensions ${concatenatedFileExtensions} -AppIconFolder '${this.extensionCacheFolder.path}';`; } } diff --git a/src/renderer/Extensions/ApplicationSearch/MacOs/MacOsSettings.tsx b/src/renderer/Extensions/ApplicationSearch/MacOs/MacOsSettings.tsx index da6c29b5a..11f8bac42 100644 --- a/src/renderer/Extensions/ApplicationSearch/MacOs/MacOsSettings.tsx +++ b/src/renderer/Extensions/ApplicationSearch/MacOs/MacOsSettings.tsx @@ -10,25 +10,28 @@ export const MacOsSettings = () => { const extensionId = "ApplicationSearch"; - const [newValue, setNewValue] = useState(""); + const [newFolder, setNewFolder] = useState(""); - const { value, updateValue } = useExtensionSetting({ extensionId, key: "macOsFolders" }); + const { value: folders, updateValue: setFolders } = useExtensionSetting({ + extensionId, + key: "macOsFolders", + }); const removeFolder = async (indexToRemove: number) => { - await updateValue(value.filter((_, index) => index !== indexToRemove)); + await setFolders(folders.filter((_, index) => index !== indexToRemove)); }; const addFolder = async () => { - if (newValue.trim().length) { - await updateValue([...value, newValue]); - setNewValue(""); + if (newFolder.trim().length) { + await setFolders([...folders, newFolder]); + setNewFolder(""); } }; const chooseFolder = async () => { const result = await contextBridge.showOpenDialog({ properties: ["openDirectory"] }); if (!result.canceled && result.filePaths.length) { - setNewValue(result.filePaths[0]); + setNewFolder(result.filePaths[0]); } }; @@ -36,10 +39,10 @@ export const MacOsSettings = () => {
- {value.map((v, index) => ( + {folders.map((folder, index) => ( @@ -53,23 +56,25 @@ export const MacOsSettings = () => { /> ))} setNewValue(value)} + onChange={(_, { value }) => setNewFolder(value)} contentAfter={ <>