diff --git a/Focus.omnijs b/Focus.ts similarity index 68% rename from Focus.omnijs rename to Focus.ts index 67dd857..c0106e4 100644 --- a/Focus.omnijs +++ b/Focus.ts @@ -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] @@ -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) };