diff --git a/commands/AlfredTime.class.php b/commands/AlfredTime.class.php index db1cb5da..310fdf59 100644 --- a/commands/AlfredTime.class.php +++ b/commands/AlfredTime.class.php @@ -36,8 +36,23 @@ public function startTimer($description = '', $projectsDefault = null, $tagsDefa { $startType = $startDefault === true ? 'start_default' : 'start'; $atLeastOneServiceStarted = false; + $implementedServices = $this->implementedServicesForFeature($startType); - foreach ($this->implementedServicesForFeature($startType) as $service) { + /** + * When starting a new timer, all the services timer IDs have to be put to null + * so that when the user uses the UNDO feature, it doesn't delete old previous + * other services timers. The timer IDs are used for the UNDO feature and + * should then contain the IDs of the last starts through the workflow, not + * through each individual service + */ + if (empty($implementedServices) === false) { + foreach ($this->activatedServices() as $service) { + $this->config['workflow']['timer_' . $service . '_id'] = null; + $this->saveConfiguration(); + } + } + + foreach ($implementedServices as $service) { $defaultProjectId = isset($projectsDefault[$service]) ? $projectsDefault[$service] : null; $defaultTags = isset($tagsDefault[$service]) ? $tagsDefault[$service] : null; diff --git "a/commands/time (Guillaume\342\200\231s iMac's conflicted copy 2017-04-13).php" "b/commands/time (Guillaume\342\200\231s iMac's conflicted copy 2017-04-13).php" new file mode 100644 index 00000000..d35ae5a1 --- /dev/null +++ "b/commands/time (Guillaume\342\200\231s iMac's conflicted copy 2017-04-13).php" @@ -0,0 +1,53 @@ +generateDefaultConfigurationFile(); + exec('open "' . getenv('alfred_workflow_data') . '/config.json"'); +} elseif (substr($query, 0, 4) === 'sync') { + $message = $alfredTime->syncOnlineDataToLocalCache(); +} elseif (substr($query, 0, 5) === 'edit') { + exec('open "' . getenv('alfred_workflow_data') . '/config.json"'); +} elseif (substr($query, 0, 4) === 'undo') { + $message = $alfredTime->UndoTimer(); +} elseif (substr($query, 0, 6) === 'delete') { + /** + * For now, only handle Toggl + */ + $timerData = json_decode(getenv('timer_data'), true); + $message = $alfredTime->deleteTimer($timerData['id']); +} elseif (substr($query, 0, 8) === 'continue') { + $timerData = json_decode(getenv('timer_data'), true); + $project = ['toggl' => $timerData['pid']]; + $tags = empty($timerData['tags']) === true ? [] : $timerData['tags']; + $tag = ['toggl' => implode(', ', $tags)]; + $message = $alfredTime->startTimer($timerData['description'], $project, $tag); +} elseif (substr($query, 0, 6) === 'start ') { + $description = substr($query, 6); + + /** + * For now, only handle Toggl projects and tags + */ + $project = [ + 'toggl' => getenv('project_id'), + ]; + + $tag = [ + 'toggl' => getenv('tag_name') + ]; + + $message = $alfredTime->startTimer($description, $project, $tag); +} elseif (substr($query, 0, 14) === 'start_default ') { + $description = substr($query, 14); + $message = $alfredTime->startTimerWithDefaultOptions($description); +} elseif (substr($query, 0, 4) === 'stop') { + $message = $alfredTime->stopRunningTimer(); +} + +echo $message;