Skip to content

Commit

Permalink
⏰ Generate time values from the script (fixes #11)
Browse files Browse the repository at this point in the history
  • Loading branch information
igrybkov committed Jan 9, 2019
1 parent a67e97a commit dc13b28
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 80 deletions.
8 changes: 7 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ program.command('menu:tasklist')
.action(async () => {
const taskList = require('./src/taskList')
alfy.output(taskList.getList())
// alfy.log('Tasklist showed')
})

program.command('menu:time')
.description('Show menu with list of time ranges')
.action(async () => {
const taskList = require('./src/timeList')
alfy.output(taskList.getList())
})

program.command('scenario:work:start')
Expand Down
Binary file added images/time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 changes: 57 additions & 79 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,6 @@
<false/>
</dict>
</array>
<key>60414749-4849-4B64-9DF8-53F5836EE370</key>
<array>
<dict>
<key>destinationuid</key>
<string>E2BDCA6C-9F6E-4CD3-A009-9953538552DB</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>62534FE0-1E85-4E87-87E4-52A87E2124BF</key>
<array>
<dict>
Expand Down Expand Up @@ -155,7 +142,7 @@
<array>
<dict>
<key>destinationuid</key>
<string>ADC01FCA-1739-4F57-8DEE-BB1A3E92C717</string>
<string>E108C268-F184-4558-9BB6-35136285627A</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
Expand Down Expand Up @@ -205,11 +192,13 @@
<false/>
</dict>
</array>
<key>ADC01FCA-1739-4F57-8DEE-BB1A3E92C717</key>
<key>BF643073-D76C-4993-985F-EFBC744BB8A9</key>
<array/>
<key>D9B36286-D868-4C63-92F7-9E19970612C8</key>
<array>
<dict>
<key>destinationuid</key>
<string>60414749-4849-4B64-9DF8-53F5836EE370</string>
<string>0DD8BC29-2D43-4AFA-A900-FDB0EF528EB6</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
Expand All @@ -218,13 +207,11 @@
<false/>
</dict>
</array>
<key>BF643073-D76C-4993-985F-EFBC744BB8A9</key>
<array/>
<key>D9B36286-D868-4C63-92F7-9E19970612C8</key>
<key>E108C268-F184-4558-9BB6-35136285627A</key>
<array>
<dict>
<key>destinationuid</key>
<string>0DD8BC29-2D43-4AFA-A900-FDB0EF528EB6</string>
<string>E2BDCA6C-9F6E-4CD3-A009-9953538552DB</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
Expand Down Expand Up @@ -679,33 +666,6 @@ echo "$file"</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>2</integer>
<key>fixedorder</key>
<true/>
<key>items</key>
<string>[{"title":"25 minutes","arg":"25","subtitle":""},{"title":"2 minutes","arg":"2"},{"title":"45 minutes","arg":"45","subtitle":""},{"title":"5 minutes","arg":"5","subtitle":""},{"title":"10 minutes","arg":"10","subtitle":""},{"title":"15 minutes","arg":"15","subtitle":""},{"title":"60 minutes","arg":"60","subtitle":"1 hour"},{"title":"90 minutes","arg":"90","subtitle":"1.5 hour"}]</string>
<key>runningsubtext</key>
<string></string>
<key>subtext</key>
<string></string>
<key>title</key>
<string>How long to you plan to work?</string>
<key>withspace</key>
<false/>
</dict>
<key>type</key>
<string>alfred.workflow.input.listfilter</string>
<key>uid</key>
<string>ADC01FCA-1739-4F57-8DEE-BB1A3E92C717</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand All @@ -732,33 +692,60 @@ echo "$file"</string>
<dict>
<key>config</key>
<dict>
<key>argument</key>
<key>alfredfiltersresults</key>
<true/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>1</integer>
<key>escaping</key>
<integer>102</integer>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>2</integer>
<key>runningsubtext</key>
<string>Searching...</string>
<key>script</key>
<string>./node_modules/.bin/run-node app.js menu:time</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string>app.js</string>
<key>subtext</key>
<string></string>
<key>variables</key>
<dict/>
<key>title</key>
<string>Choose a task...</string>
<key>type</key>
<integer>0</integer>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.utility.argument</string>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>8801E017-3F32-4942-AFB1-46357798901D</string>
<string>E108C268-F184-4558-9BB6-35136285627A</string>
<key>version</key>
<integer>1</integer>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argument</key>
<string></string>
<key>variables</key>
<dict>
<key>time</key>
<string>{query}</string>
</dict>
<dict/>
</dict>
<key>type</key>
<string>alfred.workflow.utility.argument</string>
<key>uid</key>
<string>60414749-4849-4B64-9DF8-53F5836EE370</string>
<string>8801E017-3F32-4942-AFB1-46357798901D</string>
<key>version</key>
<integer>1</integer>
</dict>
Expand Down Expand Up @@ -994,17 +981,6 @@ echo $?</string>
<key>ypos</key>
<integer>600</integer>
</dict>
<key>60414749-4849-4B64-9DF8-53F5836EE370</key>
<dict>
<key>colorindex</key>
<integer>7</integer>
<key>note</key>
<string>Save time to variable</string>
<key>xpos</key>
<integer>510</integer>
<key>ypos</key>
<integer>830</integer>
</dict>
<key>62534FE0-1E85-4E87-87E4-52A87E2124BF</key>
<dict>
<key>colorindex</key>
Expand Down Expand Up @@ -1091,15 +1067,6 @@ echo $?</string>
<key>ypos</key>
<integer>1070</integer>
</dict>
<key>ADC01FCA-1739-4F57-8DEE-BB1A3E92C717</key>
<dict>
<key>colorindex</key>
<integer>7</integer>
<key>xpos</key>
<integer>340</integer>
<key>ypos</key>
<integer>800</integer>
</dict>
<key>BF643073-D76C-4993-985F-EFBC744BB8A9</key>
<dict>
<key>colorindex</key>
Expand Down Expand Up @@ -1132,6 +1099,17 @@ echo $?</string>
<key>ypos</key>
<integer>40</integer>
</dict>
<key>E108C268-F184-4558-9BB6-35136285627A</key>
<dict>
<key>colorindex</key>
<integer>7</integer>
<key>note</key>
<string>Get tasks</string>
<key>xpos</key>
<integer>400</integer>
<key>ypos</key>
<integer>810</integer>
</dict>
<key>E2BDCA6C-9F6E-4CD3-A009-9953538552DB</key>
<dict>
<key>colorindex</key>
Expand Down Expand Up @@ -1173,7 +1151,7 @@ echo $?</string>
</dict>
</dict>
<key>version</key>
<string>0.0.10</string>
<string>0.0.9</string>
<key>webaddress</key>
<string>https://github.com/igrybkov/alfred-focus-on-work#readme</string>
</dict>
Expand Down
76 changes: 76 additions & 0 deletions src/timeList/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use strict'

exports.getList = () => {
const maxTime = 12 * 60 // 8 hours
const range = []
const convert = n => {
const hours = parseInt(`${n / 60 ^ 0}`.slice(-2), 10)
const minutes = parseInt(`${n % 60}`.slice(-2), 10)
let title = ''
let subtitle = ''
let match = ''
if (hours !== 0) {
if (hours === 1) {
title += '1 hour'
} else {
title += `${hours} hours`
}
subtitle += `${hours}h`
}

if (minutes !== 0) {
if (minutes === 1) {
title += '1 minute'
} else {
title += ` ${minutes} minutes`
}
subtitle += `${minutes}m`
}

if (hours === 0 && minutes === 25) {
subtitle += ` (Pomodoro session)`
match += ` Pomodoro`
}

return {
title: title.trim(),
subtitle: subtitle.trim(),
match: [title, subtitle, match].join(' ')
}
}
for (let i = 2; i <= maxTime;) {
const data = convert(i)
range.push(
{
uid: `time_list_entry_${i}`,
title: data.title,
subtitle: data.subtitle,
match: data.match,
arg: i,
icon: {
path: 'images/time.png'
},
variables: {
time: i
}
}
)
if (i === 2) {
i = 5
} else if (i < 30) {
i += 5
} else if (i === 30) {
i = 40
} else if (i === 40) {
i = 45
} else if (i < 180) {
i += 15
// 6 hours
} else if (i < 360) {
i += 30
} else {
i += 60
}
}
return range
}

0 comments on commit dc13b28

Please sign in to comment.