|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php'; |
|
4
|
|
|
|
|
5
|
|
|
use AlfredTime\Timer; |
|
6
|
|
|
use AlfredTime\Config; |
|
7
|
|
|
use Alfred\Workflows\Workflow; |
|
8
|
|
|
use AlfredTime\WorkflowHandler; |
|
9
|
|
|
|
|
10
|
|
|
$workflow = new Workflow(); |
|
11
|
|
|
$config = new Config(getenv('alfred_workflow_data') . '/config.json'); |
|
12
|
|
|
$timer = new Timer($config); |
|
13
|
|
|
$workflowHandler = new WorkflowHandler($config); |
|
14
|
|
|
|
|
15
|
|
|
$query = getenv('description'); |
|
16
|
|
|
|
|
17
|
|
|
$type = substr($argv[1], 0, -1); |
|
18
|
|
|
|
|
19
|
|
|
$items = call_user_func([$workflowHandler, 'get' . ucfirst($argv[1])]); |
|
20
|
|
|
|
|
21
|
|
|
if (substr($query, 0, 6) === 'start ') { |
|
22
|
|
|
$workflow->result() |
|
23
|
|
|
->arg(json_encode([])) |
|
24
|
|
|
->title('No ' . $type) |
|
25
|
|
|
->subtitle('Timer will be created without a ' . $type) |
|
26
|
|
|
->type('default') |
|
27
|
|
|
->valid(true); |
|
28
|
|
|
|
|
29
|
|
|
$items = array_filter($items, function ($value) use ($timer) { |
|
30
|
|
|
return isset($value[$timer->getPrimaryService()]); |
|
31
|
|
|
}); |
|
32
|
|
|
} elseif (substr($query, 0, 10) === 'start_all ') { |
|
33
|
|
|
$activatedServices = $config->activatedServices(); |
|
34
|
|
|
|
|
35
|
|
|
foreach ($items as $name => $services) { |
|
36
|
|
|
if (count($activatedServices) !== count($services)) { |
|
37
|
|
|
unset($items[$name]); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
foreach ($items as $name => $ids) { |
|
43
|
|
|
$subtitle = ucfirst($type) . ' available for ' . implode(' and ', array_map(function ($value) { |
|
44
|
|
|
return ucfirst($value); |
|
45
|
|
|
}, array_keys($ids))); |
|
46
|
|
|
|
|
47
|
|
|
$item = $workflow->result() |
|
48
|
|
|
->arg(json_encode($ids)) |
|
49
|
|
|
->title($name) |
|
50
|
|
|
->subtitle($subtitle) |
|
51
|
|
|
->type('default') |
|
52
|
|
|
->valid(true); |
|
53
|
|
|
|
|
54
|
|
|
if (count($ids) === 1) { |
|
55
|
|
|
$item->icon('icons/' . key($ids) . '.png'); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
echo $workflow->output(); |
|
60
|
|
|
|