Skip to content

Commit

Permalink
init first steps
Browse files Browse the repository at this point in the history
  • Loading branch information
kahl-dev committed Sep 8, 2017
0 parents commit bb3131d
Show file tree
Hide file tree
Showing 9 changed files with 6,875 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# alfred-tyme

> Handle Tyme2

## Install

```
$ npm install --global alfred-tyme
```

*Requires [Node.js](https://nodejs.org) 4+ and the Alfred [Powerpack](https://www.alfredapp.com/powerpack/).*


## Usage

In Alfred, type `ty`, <kbd>Enter</kbd>, and your query.


## License

MIT © [Patrick Kahl](https://github.com/patrickkahl)
61 changes: 61 additions & 0 deletions cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';
const alfy = require('alfy');
const tyme = require('./tyme');
const runJxa = require('run-jxa');
const [id = undefined, action, subaction = 'all'] = process.argv[2].split(':');

// :cache:timerStartedForTaskRecord
// :cache:timerStoppedForTaskRecord
// :cache:timeoutDetectedForTaskRecord
// :cache:projectCompletedChanged
// :cache:taskCompletedChanged

switch (true) {
case action === 'cache' && subaction === 'updateTaskForTaskRecordId':
{
tyme
.getTaskRecordIds(id)
.then(data => {
return tyme.taskRecordsForTaskId(data.taskRecord.relatedtaskid);
})
.then(data => {
alfy.cache.set(
`taskRecordsForTaskId:${data.taskRecords[0].relatedtaskid}`,
data.taskRecords
);
})
.catch(console.log);
}
break;
case action === 'cache' && subaction === 'all':
{
alfy.log('all');
runJxa(() => {
const tyme = Application('Tyme2');

const tymeProjects = tyme.projects.whose({ completed: false });
const projects = [];
const tasks = [];
for (projectIndex in tymeProjects) {
projects.push(tymeProjects[projectIndex].properties());

const tymeTasks = tyme.projects[projectIndex].tasks.whose({
completed: false,
});
for (taskIndex in tymeTasks) {
tasks.push(tymeTasks[taskIndex].properties());
}
}

return { projects, tasks };
})
.then(data => {
alfy.cache.set('projects', data.projects);
alfy.cache.set('tasks', data.tasks);

console.log('successfully cached data');
})
.catch(console.log);
}
break;
}
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
'use strict';
// @TODO auto cp tyme2 hook scpt
// @TODO add export // external workflow
// @TODO creat tasks from browser
// @TODO archive multiple
// @TODO fix start-id with mutated vowel
// @TODO Convert to UTF-8

const alfy = require('alfy');
const tyme = require('./tyme');
const project = process.env.project
? JSON.parse(process.env.project)
: undefined;
const task = process.env.task ? JSON.parse(process.env.task) : undefined;
const key = process.argv[2];
const action = process.argv[3];

switch (true) {
case action === 'start-task':
{
// @TODO sort latest uses
const projects = alfy.cache.get('projects');
const tasks = alfy.cache.get('tasks');

const items = tasks.map(task => {
const index = projects.findIndex(
obj => obj.id === task.relatedprojectid
);
const project = projects[index];
return {
title: task.name,
autocomplete: task.name,
subtitle: project.name,
variables: {
project: JSON.stringify(project),
task: JSON.stringify(task),
},
};
});

alfy.output(items);
}
break;
case action === 'start-note':
{
const taskRecords = alfy.cache.get(`taskRecordsForTaskId:${task.id}`);
const items = [
{
title: 'Write new Note',
},
...(taskRecords
? taskRecords
.slice(-20)
.map(taskRecord => taskRecord.note)
.filter((elem, pos, arr) => {
return arr.indexOf(elem) == pos;
})
.map(note => ({
title: note,
arg: note,
}))
: []),
];

alfy.output(items);
}
break;
case action === 'start-id':
{
// @TODO add note to respond message
tyme
.startTrackerForTaskId(task.id, key)
.then(data => {
if (data.task && data.successful) {
console.log(`Task "${data.task.name}" successfully started.`);
} else if (data.task === null && !data.successful) {
console.log('No tracking task to start.');
} else {
console.log('Something went wrong');
}
})
.catch(console.log);
}
break;
case action === 'stop': {
tyme
.stopTrackerFortTaskId()
.then(data => {
if (data.task && data.successful) {
console.log(`Task "${data.task.name}" successfully stopped.`);
} else if (data.task === null && !data.successful) {
console.log('No tracking task to stop.');
} else {
console.log('Something went wrong');
}
})
.catch(console.log);
}
}
Loading

0 comments on commit bb3131d

Please sign in to comment.