Skip to content

Commit

Permalink
convert Focus script to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Sep 9, 2022
1 parent 64e7624 commit 110655a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Focus.omnijs → Focus.ts
Expand Up @@ -4,14 +4,14 @@
"author": "Brian Hicks",
"identifier": "zone.bytes.focus",
"version": "1.0",
"description": "Start and log a pomodoro for the selected task",
"description": "Start a pomodoro for the selected task",
"label": "Focus",
"shortLabel": "Focus",
"paletteLabel": "Focus",
"image": "clock"
}*/
(() => {
var action = new PlugIn.Action(async (selection, sender) => {
var action = new PlugIn.Action(async (selection: Selection, sender: any) => {
try {
let task = selection.tasks[0]

Expand Down Expand Up @@ -39,16 +39,26 @@
focusForm.addField(new Form.Field.String("project", "Project", task.containingProject ? task.containingProject.name : null));
focusForm.addField(new Form.Field.Option("category", "Category", possibleCategories, possibleCategories, defaultCategory));
focusForm.addField(new Form.Field.String("minutes", "Minutes", "25"));

await focusForm.show("Focus on…", "Start");
let values = focusForm.values as {
project: string,
category: string,
minutes: string,
};

let sessionUrl = URL.fromString(`session:///start?intent=${encodeURIComponent(focusForm.values.project)}&categoryName=${encodeURIComponent(focusForm.values.category)}&duration=${encodeURIComponent(focusForm.values.minutes)}`)
let rawSessionUrl = `session:///start?intent=${encodeURIComponent(values.project)}&categoryName=${encodeURIComponent(values.category)}&duration=${encodeURIComponent(values.minutes)}`
let sessionUrl = URL.fromString(rawSessionUrl)
if (sessionUrl === null) {
throw `failed to parse session string ("${rawSessionUrl}") into a URL`
}
sessionUrl.open();
} catch (err) {
console.error(err);
}
});

action.validate = function(selection, sender){
action.validate = function(selection: Selection, sender: any){
return (selection.tasks.length === 1)
};

Expand Down

0 comments on commit 110655a

Please sign in to comment.