-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
46 lines (35 loc) · 1.07 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const moment = require('moment');
const AlfredNode = require('alfred-workflow-nodejs');
const guessCarrier = require('shipit').guessCarrier;
const clients = require('./config/clients');
const actionHandler = AlfredNode.actionHandler;
const workflow = AlfredNode.workflow;
const Item = AlfredNode.Item;
workflow.setName('trackit-alfred-workflow');
function buildItems(err, data) {
const recent = data.activities[0];
const recentItem = new Item({
title: recent.details,
subtitle: `${moment(recent.timestamp).fromNow()} (${recent.location})`,
icon: AlfredNode.ICONS.INFO
});
const etaItem = new Item({
title: `Arrives ${moment(data.eta).calendar().replace(' at ', ' by ')}`,
icon: AlfredNode.ICONS.CLOCK
});
workflow.addItem(recentItem);
workflow.addItem(etaItem);
workflow.feedback();
}
(function main() {
actionHandler.onAction('track', function(query) {
const carrier = guessCarrier(query)[0];
const options = {
carrier: carrier,
query: query
};
clients(options, buildItems);
});
AlfredNode.run();
})();