diff --git a/bin/main_helpers.dart b/bin/main_helpers.dart index 9c77ce6..5eb4d90 100644 --- a/bin/main_helpers.dart +++ b/bin/main_helpers.dart @@ -29,52 +29,58 @@ void _showPlaceholder() { } Future _performSearch(String query, {String? version}) async { - final SearchResponse searchResponse = await AlgoliaSearch.query( - query, - version: version, - ); + try { + final SearchResponse searchResponse = await AlgoliaSearch.query( + query, + version: version, + ); - if (searchResponse.nbHits > 0) { - final AlfredItems items = AlfredItems( - searchResponse.hits - .map((Hit hit) => SearchResult.fromJson( - {...hit, 'objectID': hit.objectID})) - .map( - (SearchResult result) => AlfredItem( - uid: result.objectID, - title: result.prettyTitle, - subtitle: result.content.isNotEmpty - ? result.content.truncate(75) - : result.id, - arg: result.permalink, - text: AlfredItemText( - largeType: result.id, - copy: result.id, + if (searchResponse.nbHits > 0) { + final AlfredItems items = AlfredItems( + searchResponse.hits + .map((Hit hit) => + SearchResult.fromJson( + {...hit, 'objectID': hit.objectID})) + .map( + (SearchResult result) => + AlfredItem( + uid: result.objectID, + title: result.prettyTitle, + subtitle: result.content.isNotEmpty + ? result.content.truncate(75) + : result.id, + arg: result.permalink, + text: AlfredItemText( + largeType: result.id, + copy: result.id, + ), + quickLookUrl: result.permalink, + icon: AlfredItemIcon(path: 'icon.png'), + valid: true, ), - quickLookUrl: result.permalink, - icon: AlfredItemIcon(path: 'icon.png'), - valid: true, - ), - ) - .toList(), - ); - _workflow.addItems(items.items); - } else { - final Uri url = - Uri.https('www.google.com', '/search', {'q': 'Django $query'}); + ) + .toList(), + ); + _workflow.addItems(items.items); + } else { + final Uri url = + Uri.https('www.google.com', '/search', {'q': 'Django $query'}); - _workflow.addItem( - AlfredItem( - title: 'No matching answers found', - subtitle: 'Shall I try and search Google?', - arg: url.toString(), - text: AlfredItemText( - copy: url.toString(), + _workflow.addItem( + AlfredItem( + title: 'No matching answers found', + subtitle: 'Shall I try and search Google?', + arg: url.toString(), + text: AlfredItemText( + copy: url.toString(), + ), + quickLookUrl: url.toString(), + icon: AlfredItemIcon(path: 'google.png'), + valid: true, ), - quickLookUrl: url.toString(), - icon: AlfredItemIcon(path: 'google.png'), - valid: true, - ), - ); + ); + } + } finally { + AlgoliaSearch.dispose(); } } diff --git a/pubspec.yaml b/pubspec.yaml index f15e502..f9ddd73 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: Search the Django documentation using Alfred # Prevent accidental publishing to pub.dev. publish_to: 'none' -version: 2.1.10 +version: 2.1.11 environment: sdk: '>=3.2.0 <4.0.0'