diff --git a/lib/services/main_search_loader.dart b/lib/services/main_search_loader.dart index 8724cc0..6bb1115 100644 --- a/lib/services/main_search_loader.dart +++ b/lib/services/main_search_loader.dart @@ -29,80 +29,78 @@ class _MainSearchLoaderState extends State { Future clearOldEntries = configHandler.clearOldDatesOfOpenendEntries(); // prepare Action Entries - ActionEntryList returnValue = ActionEntryList(entries: []); - returnValue.entries.addAll(getRecommendations(context)); - returnValue.entries.addAll(getBasicEntries(context)); + + List>> futures = []; if (configHandler.getValueUnsafe("search_filter_basic_folders", true)) { print("Loading basic folders"); - var folderEntries = await Linux.getAllFolderEntriesOfUser(context) - .timeout( - timeoutDuration, - onTimeout: () => - _onTimeoutOfSearchLoadingModule("folderEntries")); - returnValue.entries.addAll(folderEntries); + futures.add(Linux.getAllFolderEntriesOfUser(context).timeout( + timeoutDuration, + onTimeout: () => + _onTimeoutOfSearchLoadingModule("applicationEntries"))); + // future1 = Linux.getAllFolderEntriesOfUser(context); } + if (configHandler.getValueUnsafe("search_filter_applications", true)) { print("Loading applications"); - var applicationEntries = await Linux.getAllAvailableApplications() - .timeout(timeoutDuration, - onTimeout: () => - _onTimeoutOfSearchLoadingModule("applicationEntries")); - returnValue.entries.addAll(applicationEntries); + futures.add(Linux.getAllAvailableApplications().timeout(timeoutDuration, + onTimeout: () => + _onTimeoutOfSearchLoadingModule("applicationEntries"))); } if (configHandler.getValueUnsafe( "search_filter_recently_used_files_and_folders", true)) { print("Loading recently used files and folders"); - var recentFiles = await Linux.getRecentFiles(context).timeout( - timeoutDuration, - onTimeout: () => _onTimeoutOfSearchLoadingModule("recentFiles")); - returnValue.entries.addAll(recentFiles); + futures.add(Linux.getRecentFiles(context).timeout(timeoutDuration, + onTimeout: () => _onTimeoutOfSearchLoadingModule("recentFiles"))); } if (configHandler.getValueUnsafe( "search_filter_favorite_files_and_folder_bookmarks", true)) { print("Loading favorite files and folder bookmarks"); - var favoriteFiles = await Linux.getFavoriteFiles(context).timeout( - timeoutDuration, - onTimeout: () => _onTimeoutOfSearchLoadingModule("favoriteFiles")); - returnValue.entries.addAll(favoriteFiles); + futures.add(Linux.getFavoriteFiles(context).timeout(timeoutDuration, + onTimeout: () => _onTimeoutOfSearchLoadingModule("favoriteFiles"))); } if (configHandler.getValueUnsafe("search_filter_bookmarks", true)) { print("Loading browser bookmarks"); - var browserBookmarks = await Linux.getBrowserBookmarks(context).timeout( - timeoutDuration, - onTimeout: () => _onTimeoutOfSearchLoadingModule("browserBookmarks")); - returnValue.entries.addAll(browserBookmarks); - } - - if (configHandler.getValueUnsafe( - "search_filter_recently_used_files_and_folders", true)) { - print("Loading recently used files and folders"); - var additionalFolders = - Linux.getFoldersOfActionEntries(context, returnValue.entries); - returnValue.entries.addAll(additionalFolders); + futures.add(Linux.getBrowserBookmarks(context).timeout(timeoutDuration, + onTimeout: () => + _onTimeoutOfSearchLoadingModule("browserBookmarks"))); } // Flatpak Index Installations if (configHandler.getValueUnsafe("search_filter_install_software", true)) { print("Loading flatpaks"); - var flatpaks = await Linux.getAvailableFlatpaks(context).timeout( - timeoutDuration, - onTimeout: () => _onTimeoutOfSearchLoadingModule("flatpaks")); - returnValue.entries.addAll(flatpaks); + futures.add(Linux.getAvailableFlatpaks(context).timeout(timeoutDuration, + onTimeout: () => _onTimeoutOfSearchLoadingModule("flatpaks"))); } // Deinstallation Entries. if (configHandler.getValueUnsafe( "search_filter_uninstall_software", true)) { print("Loading uninstall entries"); - var actions = await Linux.getUninstallEntries(context).timeout( - timeoutDuration, + futures.add(Linux.getUninstallEntries(context).timeout(timeoutDuration, onTimeout: () => - _onTimeoutOfSearchLoadingModule("uninstall_entries")); - returnValue.entries.addAll(actions); + _onTimeoutOfSearchLoadingModule("uninstall_entries"))); + } + + ActionEntryList returnValue = ActionEntryList(entries: []); + returnValue.entries.addAll(getRecommendations(context)); + returnValue.entries.addAll(getBasicEntries(context)); + + // Collect all Futures in our returnValue. + for (Future> future in futures) { + returnValue.entries.addAll(await future); + } + + if (configHandler.getValueUnsafe( + "search_filter_recently_used_files_and_folders", true)) { + print("Loading recently used files and folders"); + var additionalFolders = + Linux.getFoldersOfActionEntries(context, returnValue.entries); + print("Finished: search_filter_recently_used_files_and_folders"); + returnValue.entries.addAll(additionalFolders); } // Remove action entries for specific environments @@ -123,6 +121,10 @@ class _MainSearchLoaderState extends State { await configHandler.setValue("runFirstStartUp", false); await clearOldEntries; + // EntryCache.saveEntries(returnValue.entries); + + // returnValue = EntryCache.loadEntries(); + return returnValue; }