@@ -27,79 +27,85 @@ const updateItem = AlfredItem(
27
27
);
28
28
29
29
Future <void > _performSearch (String query) async {
30
- final AlgoliaQuerySnapshot snapshot = await AlgoliaSearch .query (query);
30
+ try {
31
+ final SearchResponse searchResponse = await AlgoliaSearch .query (query);
31
32
32
- if (snapshot.nbHits > 0 ) {
33
- final AlfredItems items = AlfredItems (
34
- await Future .wait (snapshot.hits
35
- .map ((snapshot) => SearchResult .fromJson (snapshot.data))
36
- .map ((result) async {
37
- final File ? image = await EmojiDownloader (
38
- emoji: result.emoji,
39
- ).downloadImage ();
33
+ if (searchResponse.nbHits > 0 ) {
34
+ final AlfredItems items = AlfredItems (
35
+ await Future .wait (searchResponse.hits
36
+ .map ((Hit hit) => SearchResult .fromJson (
37
+ < String , dynamic > {...hit, 'objectID' : hit.objectID}))
38
+ .map ((SearchResult result) async {
39
+ final File ? image = await EmojiDownloader (
40
+ emoji: result.emoji,
41
+ ).downloadImage ();
40
42
41
- return AlfredItem (
42
- uid: result.objectID,
43
- title: result.code,
44
- subtitle: result.description,
45
- arg: result.code,
46
- match: '${result .name } ${result .description }' ,
47
- text: AlfredItemText (
48
- copy: result.code,
49
- largeType: result.code,
50
- ),
51
- icon: AlfredItemIcon (
52
- path: image != null ? image.absolute.path : 'question.png' ,
53
- ),
54
- mods: {
55
- {AlfredItemModKey .alt}: AlfredItemMod (
56
- subtitle: 'Copy "${result .emoji }" to clipboard' ,
57
- arg: result.emoji,
58
- icon:
59
- AlfredItemIcon (path: image? .absolute.path ?? 'question.png' ),
60
- ),
61
- {AlfredItemModKey .shift}: AlfredItemMod (
62
- subtitle: 'Copy Python source of "${result .emoji }" to clipboard' ,
63
- arg: 'u"\\ U000'
64
- '${result .emoji .runes .first .toRadixString (16 ).toUpperCase ()}'
65
- '${result .emoji .runes .toList ().sublist (1 ).map (
66
- (int i ) => '\\ u${i .toRadixString (16 ).toUpperCase ()}' ,
67
- ).join ()}"' ,
68
- icon:
69
- AlfredItemIcon (path: image? .absolute.path ?? 'question.png' ),
43
+ return AlfredItem (
44
+ uid: result.objectID,
45
+ title: result.code,
46
+ subtitle: result.description,
47
+ arg: result.code,
48
+ match: '${result .name } ${result .description }' ,
49
+ text: AlfredItemText (
50
+ copy: result.code,
51
+ largeType: result.code,
70
52
),
71
- {AlfredItemModKey .ctrl}: AlfredItemMod (
72
- subtitle: 'Copy HTML Entity of "${result .emoji }" to clipboard' ,
73
- arg: result.emoji.runes
74
- .map ((int i) => '&#x${i .toRadixString (16 )};' )
75
- .join (),
76
- icon:
77
- AlfredItemIcon (path: image? .absolute.path ?? 'question.png' ),
53
+ icon: AlfredItemIcon (
54
+ path: image != null ? image.absolute.path : 'question.png' ,
78
55
),
79
- {AlfredItemModKey .ctrl, AlfredItemModKey .shift}: AlfredItemMod (
80
- subtitle:
81
- 'Copy formal Unicode notation of "${result .emoji }" to clipboard' ,
82
- arg: result.emoji.runes
83
- .map ((int i) => 'U+${i .toRadixString (16 ).toUpperCase ()}' )
84
- .join (', ' ),
85
- icon:
86
- AlfredItemIcon (path: image? .absolute.path ?? 'question.png' ),
87
- ),
88
- },
89
- valid: true ,
90
- );
91
- }).toList ()),
92
- );
93
- _workflow.addItems (items.items);
94
- } else {
95
- _workflow.addItem (
96
- AlfredItem (
97
- title: 'No matching gitmoji found' ,
98
- icon: AlfredItemIcon (
99
- path: 'question.png' ,
56
+ mods: {
57
+ {AlfredItemModKey .alt}: AlfredItemMod (
58
+ subtitle: 'Copy "${result .emoji }" to clipboard' ,
59
+ arg: result.emoji,
60
+ icon: AlfredItemIcon (
61
+ path: image? .absolute.path ?? 'question.png' ),
62
+ ),
63
+ {AlfredItemModKey .shift}: AlfredItemMod (
64
+ subtitle:
65
+ 'Copy Python source of "${result .emoji }" to clipboard' ,
66
+ arg: 'u"\\ U000'
67
+ '${result .emoji .runes .first .toRadixString (16 ).toUpperCase ()}'
68
+ '${result .emoji .runes .toList ().sublist (1 ).map (
69
+ (int i ) => '\\ u${i .toRadixString (16 ).toUpperCase ()}' ,
70
+ ).join ()}"' ,
71
+ icon: AlfredItemIcon (
72
+ path: image? .absolute.path ?? 'question.png' ),
73
+ ),
74
+ {AlfredItemModKey .ctrl}: AlfredItemMod (
75
+ subtitle: 'Copy HTML Entity of "${result .emoji }" to clipboard' ,
76
+ arg: result.emoji.runes
77
+ .map ((int i) => '&#x${i .toRadixString (16 )};' )
78
+ .join (),
79
+ icon: AlfredItemIcon (
80
+ path: image? .absolute.path ?? 'question.png' ),
81
+ ),
82
+ {AlfredItemModKey .ctrl, AlfredItemModKey .shift}: AlfredItemMod (
83
+ subtitle:
84
+ 'Copy formal Unicode notation of "${result .emoji }" to clipboard' ,
85
+ arg: result.emoji.runes
86
+ .map ((int i) => 'U+${i .toRadixString (16 ).toUpperCase ()}' )
87
+ .join (', ' ),
88
+ icon: AlfredItemIcon (
89
+ path: image? .absolute.path ?? 'question.png' ),
90
+ ),
91
+ },
92
+ valid: true ,
93
+ );
94
+ }).toList ()),
95
+ );
96
+ _workflow.addItems (items.items);
97
+ } else {
98
+ _workflow.addItem (
99
+ AlfredItem (
100
+ title: 'No matching gitmoji found' ,
101
+ icon: AlfredItemIcon (
102
+ path: 'question.png' ,
103
+ ),
104
+ valid: false ,
100
105
),
101
- valid: false ,
102
- ),
103
- );
106
+ );
107
+ }
108
+ } finally {
109
+ AlgoliaSearch .dispose ();
104
110
}
105
111
}
0 commit comments