From 5dedc0ebcb92880c3dbcca787c231e09ed7f3772 Mon Sep 17 00:00:00 2001 From: Oliver Schwendener Date: Thu, 15 Nov 2018 10:48:00 +0100 Subject: [PATCH] Rewrite SearchPlugin interface to return promise --- .../search-plugins/file-search-plugin.test.ts | 60 ++++++++++--------- src/tests/unit/fake-search-plugin.ts | 6 +- .../calculator-input-validator.test.ts | 3 + ...environment-variable-search-plugin.test.ts | 16 ++--- .../search-plugins/fake-search-plugin.test.ts | 5 +- .../mac-os-settings-plugin.test.ts | 9 +-- .../search-plugins/programs-plugin.test.ts | 26 ++++---- .../search-plugins/shortcut-plugin.test.ts | 56 ++++++++--------- .../ueli-commands-plugin.test.ts | 5 +- .../windows-10-settings-plugin.test.ts | 5 +- .../calculator-input-validator.ts | 14 ++--- .../environment-variable-search-plugin.ts | 26 ++++---- src/ts/search-plugins/file-search-plugin.ts | 6 +- .../search-plugins/mac-os-settings-plugin.ts | 20 ++++--- .../operating-system-commands-plugin.ts | 21 +++---- src/ts/search-plugins/programs-plugin.ts | 22 +++---- src/ts/search-plugins/search-plugin.ts | 2 +- src/ts/search-plugins/shortcuts-plugin.ts | 6 +- src/ts/search-plugins/ueli-commands-plugin.ts | 22 +++---- .../windows-10-settings-plugin.ts | 7 ++- src/ts/searcher/search-plugins-searcher.ts | 19 +++--- 21 files changed, 193 insertions(+), 163 deletions(-) diff --git a/src/tests/integration/search-plugins/file-search-plugin.test.ts b/src/tests/integration/search-plugins/file-search-plugin.test.ts index 8201b4e33..7f51a937b 100644 --- a/src/tests/integration/search-plugins/file-search-plugin.test.ts +++ b/src/tests/integration/search-plugins/file-search-plugin.test.ts @@ -75,11 +75,11 @@ describe(FileSearchPlugin.name, (): void => { }; }); const plugin = new FileSearchPlugin(options, testIconSet, emptyBlackList); - const actual = plugin.getAllItems(); - const actualLength = actual.length; - const expectedLength = (testFiles.length + subFolders.length) * parentFolders.length; - - expect(actualLength).toBe(expectedLength); + plugin.getAllItems().then((result) => { + const actualLength = result.length; + const expectedLength = (testFiles.length + subFolders.length) * parentFolders.length; + expect(actualLength).toBe(expectedLength); + }); }); it("should return all files and folders (recursively) if recursive search is set to true", (): void => { @@ -91,13 +91,15 @@ describe(FileSearchPlugin.name, (): void => { }; }); const plugin = new FileSearchPlugin(options, testIconSet, emptyBlackList); - const actual = plugin.getAllItems(); - const actualLength = actual.length; - const expectedLength = (parentFolders.length * subFolders.length * testFiles.length) - + (parentFolders.length * testFiles.length) - + (parentFolders.length * subFolders.length); + plugin.getAllItems().then((result) => { + const actualLength = result.length; + const expectedLength = (parentFolders.length * subFolders.length * testFiles.length) + + (parentFolders.length * testFiles.length) + + (parentFolders.length * subFolders.length); + + expect(actualLength).toBe(expectedLength); + }); - expect(actualLength).toBe(expectedLength); }); it("all returned items should have name, execution argument and tags set", (): void => { @@ -108,12 +110,12 @@ describe(FileSearchPlugin.name, (): void => { }; }); const plugin = new FileSearchPlugin(options, testIconSet, emptyBlackList); - const actual = plugin.getAllItems(); - - for (const item of actual) { - expect(item.name.length).toBeGreaterThan(0); - expect(item.executionArgument.length).toBeGreaterThan(0); - } + plugin.getAllItems().then((result) => { + for (const item of result) { + expect(item.name.length).toBeGreaterThan(0); + expect(item.executionArgument.length).toBeGreaterThan(0); + } + }); }); it("should set the right icon", (): void => { @@ -124,25 +126,25 @@ describe(FileSearchPlugin.name, (): void => { }; }); const plugin = new FileSearchPlugin(options, testIconSet, emptyBlackList); - const actual = plugin.getAllItems(); + plugin.getAllItems().then((result) => { + const actualFiles = result.filter((a) => { + return a.icon === testIconSet.fileIcon; + }); - const actualFiles = actual.filter((a) => { - return a.icon === testIconSet.fileIcon; - }); + const actualFolders = result.filter((a) => { + return a.icon === testIconSet.folderIcon; + }); - const actualFolders = actual.filter((a) => { - return a.icon === testIconSet.folderIcon; + expect(actualFiles.length).toBe(testFiles.length * parentFolders.length); + expect(actualFolders.length).toBe(subFolders.length * parentFolders.length); }); - - expect(actualFiles.length).toBe(testFiles.length * parentFolders.length); - expect(actualFolders.length).toBe(subFolders.length * parentFolders.length); }); it("should return an empty array if no folders are specified", (): void => { const plugin = new FileSearchPlugin([], testIconSet, emptyBlackList); - const acutal = plugin.getAllItems(); - - expect(acutal.length).toBe(0); + plugin.getAllItems().then((result) => { + expect(result.length).toBe(0); + }); }); }); diff --git a/src/tests/unit/fake-search-plugin.ts b/src/tests/unit/fake-search-plugin.ts index 606956e4d..023e1c062 100644 --- a/src/tests/unit/fake-search-plugin.ts +++ b/src/tests/unit/fake-search-plugin.ts @@ -12,7 +12,9 @@ export class FakeSearchPlugin implements SearchPlugin { return this.searchResultItems.length; } - public getAllItems(): SearchResultItem[] { - return this.searchResultItems; + public getAllItems(): Promise { + return new Promise((resolve, reject) => { + resolve(this.searchResultItems); + }); } } diff --git a/src/tests/unit/input-validators/calculator-input-validator.test.ts b/src/tests/unit/input-validators/calculator-input-validator.test.ts index d4974fdd0..4d8315c5d 100644 --- a/src/tests/unit/input-validators/calculator-input-validator.test.ts +++ b/src/tests/unit/input-validators/calculator-input-validator.test.ts @@ -23,6 +23,9 @@ describe(CalculatorInputValidator.name, (): void => { it("should return false when passing in an invalid argument", (): void => { const invalidInputs = [ + undefined, + null, + "", "s", "kg", "log()", diff --git a/src/tests/unit/search-plugins/environment-variable-search-plugin.test.ts b/src/tests/unit/search-plugins/environment-variable-search-plugin.test.ts index 496e1e489..a2636ba8a 100644 --- a/src/tests/unit/search-plugins/environment-variable-search-plugin.test.ts +++ b/src/tests/unit/search-plugins/environment-variable-search-plugin.test.ts @@ -12,15 +12,15 @@ describe(EnvironmentVariableSearchPlugin.name, (): void => { describe(plugin.getAllItems.name, (): void => { it("should return an search result item for each item in the environment variable collection", (): void => { - const actual = plugin.getAllItems(); + plugin.getAllItems().then((result) => { + expect(result.length).toBe(Object.keys(fakeEnvironmentVariableCollection).length); - expect(actual.length).toBe(Object.keys(fakeEnvironmentVariableCollection).length); - - for (const key of Object.keys(fakeEnvironmentVariableCollection)) { - const item = actual.filter((a) => a.name === key)[0]; - expect(item).not.toBe(undefined); - expect(item).not.toBe(null); - } + for (const key of Object.keys(fakeEnvironmentVariableCollection)) { + const item = result.filter((a) => a.name === key)[0]; + expect(item).not.toBe(undefined); + expect(item).not.toBe(null); + } + }); }); }); diff --git a/src/tests/unit/search-plugins/fake-search-plugin.test.ts b/src/tests/unit/search-plugins/fake-search-plugin.test.ts index eb318318c..cee2eaed3 100644 --- a/src/tests/unit/search-plugins/fake-search-plugin.test.ts +++ b/src/tests/unit/search-plugins/fake-search-plugin.test.ts @@ -7,8 +7,9 @@ describe(FakeSearchPlugin.name, (): void => { describe(plugin.getAllItems.name, (): void => { it("should return all items", (): void => { - const actual = plugin.getAllItems(); - expect(actual.length).toBe(items.length); + plugin.getAllItems().then((result) => { + expect(result.length).toBe(items.length); + }); }); }); diff --git a/src/tests/unit/search-plugins/mac-os-settings-plugin.test.ts b/src/tests/unit/search-plugins/mac-os-settings-plugin.test.ts index 6ac36454c..b398e6c1d 100644 --- a/src/tests/unit/search-plugins/mac-os-settings-plugin.test.ts +++ b/src/tests/unit/search-plugins/mac-os-settings-plugin.test.ts @@ -14,10 +14,11 @@ describe(MacOsSettingsPlugin.name, (): void => { describe(searchPlugin.getAllItems.name, (): void => { it("should return more than zero items", () => { - const actual = searchPlugin.getAllItems(); - expect(actual).not.toBe(undefined); - expect(actual).not.toBe(null); - expect(actual.length).toBeGreaterThan(0); + searchPlugin.getAllItems().then((actual) => { + expect(actual).not.toBe(undefined); + expect(actual).not.toBe(null); + expect(actual.length).toBeGreaterThan(0); + }); }); }); diff --git a/src/tests/unit/search-plugins/programs-plugin.test.ts b/src/tests/unit/search-plugins/programs-plugin.test.ts index 507ab4a49..22827a5cd 100644 --- a/src/tests/unit/search-plugins/programs-plugin.test.ts +++ b/src/tests/unit/search-plugins/programs-plugin.test.ts @@ -26,19 +26,19 @@ describe("ProgramsPlugin", (): void => { describe(programsPlugin.getAllItems.name, (): void => { it("should return all programs", (): void => { - const actual = programsPlugin.getAllItems(); - - expect(actual.length).toBeGreaterThan(0); - - for (const fakeProgram of fakePrograms) { - const filtered = actual.filter((a): boolean => { - return a.name === fakeProgram.name; - }); - - expect(filtered.length).toBe(1); - expect(filtered[0].name).toBe(fakeProgram.name); - expect(filtered[0].executionArgument).toBe(fakeProgram.executionArgument); - } + programsPlugin.getAllItems().then((result) => { + expect(result.length).toBeGreaterThan(0); + + for (const fakeProgram of fakePrograms) { + const filtered = result.filter((a): boolean => { + return a.name === fakeProgram.name; + }); + + expect(filtered.length).toBe(1); + expect(filtered[0].name).toBe(fakeProgram.name); + expect(filtered[0].executionArgument).toBe(fakeProgram.executionArgument); + } + }); }); }); diff --git a/src/tests/unit/search-plugins/shortcut-plugin.test.ts b/src/tests/unit/search-plugins/shortcut-plugin.test.ts index aca8a8ab4..cbf0492a2 100644 --- a/src/tests/unit/search-plugins/shortcut-plugin.test.ts +++ b/src/tests/unit/search-plugins/shortcut-plugin.test.ts @@ -19,16 +19,16 @@ describe(ShortcutsPlugin.name, (): void => { const plugin = new ShortcutsPlugin(shortcuts, ""); - const actual = plugin.getAllItems(); - - for (const item of actual) { - const shortcut = shortcuts.filter((c: Shortcut): boolean => { - return c.name === item.name; - })[0]; - - expect(shortcut).not.toBe(undefined); - expect(item.executionArgument).toBe(shortcut.executionArgument); - } + plugin.getAllItems().then((actual) => { + for (const item of actual) { + const shortcut = shortcuts.filter((c: Shortcut): boolean => { + return c.name === item.name; + })[0]; + + expect(shortcut).not.toBe(undefined); + expect(item.executionArgument).toBe(shortcut.executionArgument); + } + }); }); it("should set the deafult icon if no icon is specified", (): void => { @@ -47,16 +47,16 @@ describe(ShortcutsPlugin.name, (): void => { const plugin = new ShortcutsPlugin(shortcuts, defaultIcon); - const actual = plugin.getAllItems(); + plugin.getAllItems().then((actual) => { + for (const item of actual) { + const shortcut = shortcuts.filter((c: Shortcut): boolean => { + return c.name === item.name; + })[0]; - for (const item of actual) { - const shortcut = shortcuts.filter((c: Shortcut): boolean => { - return c.name === item.name; - })[0]; - - expect(shortcut).not.toBe(undefined); - expect(item.icon).toBe(defaultIcon); - } + expect(shortcut).not.toBe(undefined); + expect(item.icon).toBe(defaultIcon); + } + }); }); it("should set the given icon if it is specified", (): void => { @@ -77,16 +77,16 @@ describe(ShortcutsPlugin.name, (): void => { const plugin = new ShortcutsPlugin(shortcuts, defaultIcon); - const actual = plugin.getAllItems(); - - for (const item of actual) { - const shortcut = shortcuts.filter((c: Shortcut): boolean => { - return c.name === item.name; - })[0]; + plugin.getAllItems().then((actual) => { + for (const item of actual) { + const shortcut = shortcuts.filter((c: Shortcut): boolean => { + return c.name === item.name; + })[0]; - expect(shortcut).not.toBe(undefined); - expect(item.icon).toBe(shortcut.icon); - } + expect(shortcut).not.toBe(undefined); + expect(item.icon).toBe(shortcut.icon); + } + }); }); }); diff --git a/src/tests/unit/search-plugins/ueli-commands-plugin.test.ts b/src/tests/unit/search-plugins/ueli-commands-plugin.test.ts index c989e7260..c91f52c3f 100644 --- a/src/tests/unit/search-plugins/ueli-commands-plugin.test.ts +++ b/src/tests/unit/search-plugins/ueli-commands-plugin.test.ts @@ -5,8 +5,9 @@ describe(UeliCommandsSearchPlugin.name, (): void => { describe(plugin.getAllItems.name, (): void => { it("should return all items", (): void => { - const actual = plugin.getAllItems(); - expect(actual.length).toBe(3); + plugin.getAllItems().then((actual) => { + expect(actual.length).toBe(3); + }); }); }); diff --git a/src/tests/unit/search-plugins/windows-10-settings-plugin.test.ts b/src/tests/unit/search-plugins/windows-10-settings-plugin.test.ts index 03356f602..484176522 100644 --- a/src/tests/unit/search-plugins/windows-10-settings-plugin.test.ts +++ b/src/tests/unit/search-plugins/windows-10-settings-plugin.test.ts @@ -22,8 +22,9 @@ describe(Windows10SettingsSearchPlugin.name, (): void => { describe(searchPlugin.getAllItems.name, (): void => { it("should return more than zero items", () => { - const actual = searchPlugin.getAllItems(); - expect(actual.length).toBe(testSettings.length + testApps.length); + searchPlugin.getAllItems().then((actual) => { + expect(actual.length).toBe(testSettings.length + testApps.length); + }); }); }); diff --git a/src/ts/input-validators/calculator-input-validator.ts b/src/ts/input-validators/calculator-input-validator.ts index cd67d4f21..f4b827d3c 100644 --- a/src/ts/input-validators/calculator-input-validator.ts +++ b/src/ts/input-validators/calculator-input-validator.ts @@ -1,9 +1,13 @@ import { InputValidator } from "./input-validator"; -import * as math from "mathjs"; import { StringHelpers } from "../helpers/string-helpers"; +import * as math from "mathjs"; export class CalculatorInputValidator implements InputValidator { - public isValidForSearchResults(userInput: string): boolean { + public isValidForSearchResults(userInput: string | undefined | null): boolean { + if (userInput === undefined || userInput === null) { + return false; + } + if (!this.isValidInput(userInput)) { return false; } @@ -18,7 +22,7 @@ export class CalculatorInputValidator implements InputValidator { return !isNaN(result) || this.isValidMathType(result) || false; } - private isValidMathType(input: any): boolean { + private isValidMathType(input: any | undefined): boolean { const mathType = math.typeof(input); if ((mathType === "Unit" && input.value === null) @@ -34,10 +38,6 @@ export class CalculatorInputValidator implements InputValidator { return false; } - if (userInput === undefined || userInput === null) { - return false; - } - if (StringHelpers.trimAndReplaceMultipleWhiteSpacesWithOne(userInput).length === 0) { return false; } diff --git a/src/ts/search-plugins/environment-variable-search-plugin.ts b/src/ts/search-plugins/environment-variable-search-plugin.ts index dceb56876..0391cf0c3 100644 --- a/src/ts/search-plugins/environment-variable-search-plugin.ts +++ b/src/ts/search-plugins/environment-variable-search-plugin.ts @@ -15,19 +15,21 @@ export class EnvironmentVariableSearchPlugin implements SearchPlugin { return Object.keys(this.variableCollection).length; } - public getAllItems(): SearchResultItem[] { - const result: SearchResultItem[] = []; + public getAllItems(): Promise { + return new Promise((resolve, reject) => { + const result: SearchResultItem[] = []; - for (const variableName of Object.keys(this.variableCollection)) { - result.push({ - description: this.variableCollection[variableName], - executionArgument: this.variableCollection[variableName], - icon: this.iconSet.environmentVariableIcon, - name: variableName, - searchable: [variableName], - }); - } + for (const variableName of Object.keys(this.variableCollection)) { + result.push({ + description: this.variableCollection[variableName], + executionArgument: this.variableCollection[variableName], + icon: this.iconSet.environmentVariableIcon, + name: variableName, + searchable: [variableName], + }); + } - return result; + resolve(result); + }); } } diff --git a/src/ts/search-plugins/file-search-plugin.ts b/src/ts/search-plugins/file-search-plugin.ts index 3f3302192..65c8928a2 100644 --- a/src/ts/search-plugins/file-search-plugin.ts +++ b/src/ts/search-plugins/file-search-plugin.ts @@ -24,8 +24,10 @@ export class FileSearchPlugin implements SearchPlugin { return this.items.length; } - public getAllItems(): SearchResultItem[] { - return this.items; + public getAllItems(): Promise { + return new Promise((resolve, reject) => { + resolve(this.items); + }); } private loadFilesAndFolders(): SearchResultItem[] { diff --git a/src/ts/search-plugins/mac-os-settings-plugin.ts b/src/ts/search-plugins/mac-os-settings-plugin.ts index df2292d45..196dbd4d6 100644 --- a/src/ts/search-plugins/mac-os-settings-plugin.ts +++ b/src/ts/search-plugins/mac-os-settings-plugin.ts @@ -18,15 +18,17 @@ export class MacOsSettingsPlugin implements SearchPlugin { return this.settings.length; } - public getAllItems(): SearchResultItem[] { - return this.settings.map((setting: MacOsSetting): SearchResultItem => { - return { - description: `System Preferences ${UeliHelpers.searchResultDescriptionSeparator} ${basename(setting.executionArgument)}`, - executionArgument: setting.executionArgument, - icon: this.iconSet.operatingSystemSettingsIcon, - name: setting.name, - searchable: [setting.name].concat(setting.tags), - }; + public getAllItems(): Promise { + return new Promise((resolve, reject) => { + resolve(this.settings.map((setting: MacOsSetting): SearchResultItem => { + return { + description: `System Preferences ${UeliHelpers.searchResultDescriptionSeparator} ${basename(setting.executionArgument)}`, + executionArgument: setting.executionArgument, + icon: this.iconSet.operatingSystemSettingsIcon, + name: setting.name, + searchable: [setting.name].concat(setting.tags), + }; + })); }); } } diff --git a/src/ts/search-plugins/operating-system-commands-plugin.ts b/src/ts/search-plugins/operating-system-commands-plugin.ts index f882f1f61..ee2ce08bb 100644 --- a/src/ts/search-plugins/operating-system-commands-plugin.ts +++ b/src/ts/search-plugins/operating-system-commands-plugin.ts @@ -19,16 +19,17 @@ export class OperatingSystemCommandsPlugin implements SearchPlugin { return this.systemCommands.length; } - public getAllItems(): SearchResultItem[] { - - return this.systemCommands.map((setting: OperatingSystemCommand): SearchResultItem => { - return { - description: `${this.descriptionPrefix} ${UeliHelpers.searchResultDescriptionSeparator} ${setting.name}`, - executionArgument: setting.executionArgument, - icon: setting.icon, - name: setting.name, - searchable: [setting.name].concat(setting.tags), - }; + public getAllItems(): Promise { + return new Promise((resolve, reject) => { + resolve(this.systemCommands.map((setting: OperatingSystemCommand): SearchResultItem => { + return { + description: `${this.descriptionPrefix} ${UeliHelpers.searchResultDescriptionSeparator} ${setting.name}`, + executionArgument: setting.executionArgument, + icon: setting.icon, + name: setting.name, + searchable: [setting.name].concat(setting.tags), + }; + })); }); } } diff --git a/src/ts/search-plugins/programs-plugin.ts b/src/ts/search-plugins/programs-plugin.ts index 88e81d1cc..7134c0ecf 100644 --- a/src/ts/search-plugins/programs-plugin.ts +++ b/src/ts/search-plugins/programs-plugin.ts @@ -18,16 +18,18 @@ export class ProgramsPlugin implements SearchPlugin { return this.programs.length; } - public getAllItems(): SearchResultItem[] { - return this.programs.map((program): SearchResultItem => { - return { - description: FilePathDescriptionBuilder.buildFilePathDescription(program.executionArgument), - executionArgument: program.executionArgument, - icon: this.iconSet.appIcon, - name: program.name, - searchable: [program.name], - tags: [], - } as SearchResultItem; + public getAllItems(): Promise { + return new Promise((resolve, reject) => { + resolve(this.programs.map((program): SearchResultItem => { + return { + description: FilePathDescriptionBuilder.buildFilePathDescription(program.executionArgument), + executionArgument: program.executionArgument, + icon: this.iconSet.appIcon, + name: program.name, + searchable: [program.name], + tags: [], + } as SearchResultItem; + })); }); } } diff --git a/src/ts/search-plugins/search-plugin.ts b/src/ts/search-plugins/search-plugin.ts index 692b2bc26..a5d104703 100644 --- a/src/ts/search-plugins/search-plugin.ts +++ b/src/ts/search-plugins/search-plugin.ts @@ -2,5 +2,5 @@ import { SearchResultItem } from "../search-result-item"; export interface SearchPlugin { getIndexLength(): number; - getAllItems(): SearchResultItem[]; + getAllItems(): Promise; } diff --git a/src/ts/search-plugins/shortcuts-plugin.ts b/src/ts/search-plugins/shortcuts-plugin.ts index e41ca107c..b1bb00a60 100644 --- a/src/ts/search-plugins/shortcuts-plugin.ts +++ b/src/ts/search-plugins/shortcuts-plugin.ts @@ -16,8 +16,10 @@ export class ShortcutsPlugin implements SearchPlugin { return this.items.length; } - public getAllItems(): SearchResultItem[] { - return this.items; + public getAllItems(): Promise { + return new Promise((resolve, reject) => { + resolve(this.items); + }); } private convertToSearchResultItems(shortcuts: Shortcut[]): SearchResultItem[] { diff --git a/src/ts/search-plugins/ueli-commands-plugin.ts b/src/ts/search-plugins/ueli-commands-plugin.ts index b738426e3..9d92c983d 100644 --- a/src/ts/search-plugins/ueli-commands-plugin.ts +++ b/src/ts/search-plugins/ueli-commands-plugin.ts @@ -29,16 +29,18 @@ export class UeliCommandsSearchPlugin implements SearchPlugin { return this.ueliCommands.length; } - public getAllItems(): SearchResultItem[] { - return this.ueliCommands.map((i): SearchResultItem => { - return { - description: "Ueli command", - executionArgument: i.executionArgument, - icon: this.icon, - name: i.name, - searchable: [i.name], - tags: [], - } as SearchResultItem; + public getAllItems(): Promise { + return new Promise((resolve, reject) => { + resolve(this.ueliCommands.map((i): SearchResultItem => { + return { + description: "Ueli command", + executionArgument: i.executionArgument, + icon: this.icon, + name: i.name, + searchable: [i.name], + tags: [], + } as SearchResultItem; + })); }); } } diff --git a/src/ts/search-plugins/windows-10-settings-plugin.ts b/src/ts/search-plugins/windows-10-settings-plugin.ts index 1fff5de84..0da6fd098 100644 --- a/src/ts/search-plugins/windows-10-settings-plugin.ts +++ b/src/ts/search-plugins/windows-10-settings-plugin.ts @@ -20,9 +20,10 @@ export class Windows10SettingsSearchPlugin implements SearchPlugin { return this.settings.length + this.apps.length; } - public getAllItems(): SearchResultItem[] { - return this.getAllWindowsSettings() - .concat(this.getAllWindows10Apps()); + public getAllItems(): Promise { + return new Promise((resolve, reject) => { + resolve(this.getAllWindowsSettings().concat(this.getAllWindows10Apps())); + }); } private getAllWindowsSettings(): SearchResultItem[] { diff --git a/src/ts/searcher/search-plugins-searcher.ts b/src/ts/searcher/search-plugins-searcher.ts index 282c995c7..b0e1d1222 100644 --- a/src/ts/searcher/search-plugins-searcher.ts +++ b/src/ts/searcher/search-plugins-searcher.ts @@ -7,10 +7,9 @@ import { CountManager } from "../count/count-manager"; export class SearchPluginsSearcher implements Searcher { public readonly blockOthers = false; - - private readonly items: SearchResultItem[]; private readonly countManager: CountManager; private readonly config: UserConfigOptions; + private items: SearchResultItem[] = []; constructor(config: UserConfigOptions, countManager: CountManager, searchPluginManager: SearchPluginManager) { this.config = config; @@ -18,11 +17,17 @@ export class SearchPluginsSearcher implements Searcher { const plugins = searchPluginManager.getPlugins(); - this.items = plugins.length > 0 - ? plugins - .map((plugin): SearchResultItem[] => plugin.getAllItems()) - .reduce((acc, pluginItems): SearchResultItem[] => acc.concat(pluginItems)) - : []; + if (plugins.length > 0) { + Promise.all(plugins.map((plugin) => plugin.getAllItems())).then((resultList) => { + let items: SearchResultItem[] = []; + + for (const results of resultList) { + items = items.concat(results); + } + + this.items = items; + }); + } } public getSearchResult(userInput: string): Promise {