@@ -19,148 +19,99 @@ class MainSearchLoader extends StatefulWidget {
1919class _MainSearchLoaderState extends State <MainSearchLoader > {
2020 late Future <void > futureVoid;
2121
22+ @override
23+ void initState () {
24+ super .initState ();
25+ // P1: initialise once in initState — build() can be called multiple times
26+ // (e.g. theme change, resize) which would restart prepare() on every rebuild.
27+ futureVoid = prepare ();
28+ }
29+
2230 Future <void > prepare () async {
2331 MainSearch .unregisterHotkeysForKeyboardUse ();
2432
2533 ConfigHandler configHandler = ConfigHandler ();
2634 await configHandler.ensureConfigIsLoaded ();
2735 Future clearOldEntries = configHandler.clearOldDatesOfOpenendEntries ();
2836
29- // prepare Action Entries
30-
31- // List<Future<List<ActionEntry>>> futures = [];
32-
33- // if (configHandler.getValueUnsafe("search_filter_basic_folders", true)) {
34- // print("Loading basic folders");
35- // futures.add(Linux.getAllFolderEntriesOfUser(context).timeout(
36- // timeoutDuration,
37- // onTimeout: () =>
38- // _onTimeoutOfSearchLoadingModule("applicationEntries")));
39- // // future1 = Linux.getAllFolderEntriesOfUser(context);
40- // }
41-
4237 ActionEntryListService .clearEntries ();
4338
39+ // P2: wrap fire-and-forget calls in unawaited error handlers so exceptions
40+ // are logged rather than silently swallowed.
4441 if (configHandler.getValueUnsafe ("search_filter_basic_folders" , true )) {
4542 print ("Loading basic folders" );
46- Linux .getAllFolderEntriesOfUser (context);
43+ Linux .getAllFolderEntriesOfUser (context).catchError ((e) {
44+ print ("Error loading basic folders: $e " );
45+ return < ActionEntry > [];
46+ });
4747 }
4848
49- // if (configHandler.getValueUnsafe("search_filter_applications", true)) {
50- // print("Loading applications");
51- // futures.add(Linux.getAllAvailableApplications().timeout(timeoutDuration,
52- // onTimeout: () =>
53- // _onTimeoutOfSearchLoadingModule("applicationEntries")));
54- // }
55-
5649 if (configHandler.getValueUnsafe ("search_filter_applications" , true )) {
5750 print ("Loading applications" );
58- Linux .getAllAvailableApplications ();
51+ Linux .getAllAvailableApplications ().catchError ((e) {
52+ print ("Error loading applications: $e " );
53+ return < ActionEntry > [];
54+ });
5955 }
6056
61- // if (configHandler.getValueUnsafe(
62- // "search_filter_recently_used_files_and_folders", true)) {
63- // print("Loading recently used files and folders");
64- // futures.add(Linux.getRecentFiles(context).timeout(timeoutDuration,
65- // onTimeout: () => _onTimeoutOfSearchLoadingModule("recentFiles")));
66- // }
67-
6857 if (configHandler.getValueUnsafe (
6958 "search_filter_recently_used_files_and_folders" , true )) {
7059 print ("Loading recently used files and folders" );
71- Linux .getRecentFiles (context);
60+ Linux .getRecentFiles (context).catchError ((e) {
61+ print ("Error loading recent files: $e " );
62+ return < ActionEntry > [];
63+ });
7264 }
7365
74- // if (configHandler.getValueUnsafe(
75- // "search_filter_favorite_files_and_folder_bookmarks", true)) {
76- // print("Loading favorite files and folder bookmarks");
77- // futures.add(Linux.getFavoriteFiles(context).timeout(timeoutDuration,
78- // onTimeout: () => _onTimeoutOfSearchLoadingModule("favoriteFiles")));
79- // }
80-
8166 if (configHandler.getValueUnsafe (
8267 "search_filter_favorite_files_and_folder_bookmarks" , true )) {
83- Linux .getFavoriteFiles (context);
68+ Linux .getFavoriteFiles (context).catchError ((e) {
69+ print ("Error loading favorite files: $e " );
70+ return < ActionEntry > [];
71+ });
8472 }
8573
86- // if (configHandler.getValueUnsafe("search_filter_bookmarks", true)) {
87- // print("Loading browser bookmarks");
88- // futures.add(Linux.getBrowserBookmarks(context).timeout(timeoutDuration,
89- // onTimeout: () =>
90- // _onTimeoutOfSearchLoadingModule("browserBookmarks")));
91- // }
92-
9374 if (configHandler.getValueUnsafe ("search_filter_bookmarks" , true )) {
9475 print ("Loading browser bookmarks" );
95- Linux .getBrowserBookmarks (context);
76+ Linux .getBrowserBookmarks (context).catchError ((e) {
77+ print ("Error loading browser bookmarks: $e " );
78+ return < ActionEntry > [];
79+ });
9680 }
9781
98- // Deinstallation Entries.
99- // if (configHandler.getValueUnsafe(
100- // "search_filter_uninstall_software", true)) {
101- // print("Loading uninstall entries");
102- // futures.add(Linux.getUninstallEntries(context).timeout(timeoutDuration,
103- // onTimeout: () =>
104- // _onTimeoutOfSearchLoadingModule("uninstall_entries")));
105- // }
10682 if (configHandler.getValueUnsafe (
10783 "search_filter_uninstall_software" , true )) {
10884 print ("Loading uninstall entries" );
109- Linux .getUninstallEntries (context);
85+ Linux .getUninstallEntries (context).catchError ((e) {
86+ print ("Error loading uninstall entries: $e " );
87+ return < ActionEntry > [];
88+ });
11089 }
11190
112- // ActionEntryList returnValue = ActionEntryList(entries: []);
113- // returnValue.entries.addAll(getRecommendations(context));
114- // returnValue.entries.addAll(getBasicEntries(context));
11591 List <ActionEntry > functionEntries = [];
11692 functionEntries.addAll (getRecommendations (context));
11793 functionEntries.addAll (getBasicEntries (context));
11894
119- // // Collect all Futures in our returnValue.
120- // for (Future<List<ActionEntry>> future in futures) {
121- // returnValue.entries.addAll(await future);
122- // }
123-
124- // if (configHandler.getValueUnsafe(
125- // "search_filter_recently_used_files_and_folders", true)) {
126- // print("Loading recently used files and folders");
127- // var additionalFolders =
128- // Linux.getFoldersOfActionEntries(context, ActionEntryListService.getEntries());
129- // print("Finished: search_filter_recently_used_files_and_folders");
130- // // returnValue.entries.addAll(additionalFolders);
131- // ActionEntryListService.addEntries(additionalFolders);
132- // }
133-
134- // Remove action entries for specific environments
13595 print ("Removing disabled entries" );
13696 List <ActionEntry > entriesToRemove = [];
13797 for (ActionEntry entry in functionEntries) {
13898 if (entry.disableEntryIf != null ) {
139- // If the disableEntryIf function of the entry gets true, remove:
14099 if (entry.disableEntryIf !()) {
141100 entriesToRemove.add (entry);
142101 }
143102 }
144103 }
145104 for (ActionEntry entry in entriesToRemove) {
146- // returnValue.entries.remove(entry);
147105 functionEntries.remove (entry);
148106 }
149107 ActionEntryListService .addEntries (functionEntries);
150108 print ("Initiating configHandler" );
151109 await configHandler.setValue ("runFirstStartUp" , false );
152110 await clearOldEntries;
153-
154- // EntryCache.saveEntries(returnValue.entries);
155-
156- // returnValue = EntryCache.loadEntries();
157-
158- // return returnValue;
159111 }
160112
161113 @override
162114 Widget build (BuildContext context) {
163- futureVoid = prepare ();
164115 return FutureBuilder <dynamic >(
165116 future: futureVoid,
166117 builder: (context, snapshot) {
0 commit comments