-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bb3131d
Showing
9 changed files
with
6,875 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.