-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
159 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
part of 'main.dart'; | ||
|
||
final AlfredWorkflow _workflow = AlfredWorkflow(); | ||
|
||
final AlfredUpdater _updater = AlfredUpdater( | ||
githubRepositoryUrl: Config.githubRepositoryUrl, | ||
currentVersion: Config.version, | ||
updateInterval: Duration(days: 7), | ||
); | ||
|
||
|
||
const _updateItem = AlfredItem( | ||
title: 'Auto-Update available!', | ||
subtitle: 'Press <enter> to auto-update to a new version of this workflow.', | ||
arg: 'update:workflow', | ||
match: | ||
'Auto-Update available! Press <enter> to auto-update to a new version of this workflow.', | ||
icon: AlfredItemIcon(path: 'alfredhatcog.png'), | ||
valid: true, | ||
); | ||
|
||
void _showPlaceholder() { | ||
_workflow.addItem( | ||
const AlfredItem( | ||
title: 'Search the Django docs...', | ||
icon: AlfredItemIcon(path: 'icon.png'), | ||
), | ||
); | ||
} | ||
|
||
Future<void> _performSearch(String query, {String? version}) async { | ||
final AlgoliaQuerySnapshot snapshot = await AlgoliaSearch.query( | ||
query, | ||
version: version, | ||
); | ||
|
||
if (snapshot.nbHits > 0) { | ||
final AlfredItems items = AlfredItems( | ||
snapshot.hits.map((snapshot) => SearchResult.fromJson(snapshot.data)).map( | ||
(result) { | ||
return 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, | ||
); | ||
}, | ||
).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(), | ||
), | ||
quickLookUrl: url.toString(), | ||
icon: AlfredItemIcon(path: 'google.png'), | ||
valid: true, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters