Skip to content

Commit

Permalink
Set icon only after png download finishes
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-pennyworth committed Dec 8, 2020
1 parent 2362a18 commit 0325031
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions emoji-kitchen/emoji-kitchen.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,19 @@ function download(pngUrl, downloadMonitor) {
let pngPath = `${KITCHEN_DATA_DIR}/${pngName}`;

if (!fs.existsSync(pngPath)) {
const stream = fs.createWriteStream(pngPath);
const fileStream = fs.createWriteStream(pngPath);
const getter = pngUrl.startsWith('https:') ? https : http;
console.log(`Downloading ${pngUrl}`);
getter.get(pngUrl, REQUEST_OPTS, (response) => {
console.log(`Downloading ${pngUrl}`);
response.pipe(stream);
downloadMonitor.set(pngUrl, true);
// Set icon to itself so that when dragging from
// Alfred's results, you see the sticker and not
// the generic png icon.
spawn(`${WF_DIR}/set_icon.sh`, [pngPath, pngPath]);
response.pipe(fileStream);
fileStream.on('finish', () => {
downloadMonitor.set(pngUrl, true);
// Set icon to itself so that when dragging from
// Alfred's results, you see the sticker and not
// the generic png icon.
spawn(`${WF_DIR}/set_icon.sh`, [pngPath, pngPath]);
console.log(`Finished download: ${pngPath}`);
});
});
} else {
downloadMonitor.set(pngUrl, true);
Expand Down
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ xattr -d com.apple.quarantine ./impbcopy 2> /dev/null > /dev/null
</dict>
</dict>
<key>version</key>
<string>0.1.2</string>
<string>0.1.3</string>
<key>webaddress</key>
<string>https://github.com/mr-pennyworth/alfred-fastest-emoji</string>
</dict>
Expand Down

0 comments on commit 0325031

Please sign in to comment.