diff --git a/.github/workflows/companion-module-checks.yaml b/.github/workflows/companion-module-checks.yaml index bc8d44e..1f6c187 100644 --- a/.github/workflows/companion-module-checks.yaml +++ b/.github/workflows/companion-module-checks.yaml @@ -15,4 +15,3 @@ jobs: uses: bitfocus/actions/.github/workflows/module-checks.yaml@main # with: # upload-artifact: true # uncomment this to upload the built package as an artifact to this workflow that you can download and share with others - diff --git a/.github/workflows/prittier.yml b/.github/workflows/prettier.yml similarity index 95% rename from .github/workflows/prittier.yml rename to .github/workflows/prettier.yml index 32ac9a9..dc95df3 100644 --- a/.github/workflows/prittier.yml +++ b/.github/workflows/prettier.yml @@ -6,9 +6,9 @@ name: CI on: # Triggers the workflow on push or pull request events but only for the main branch push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -28,4 +28,3 @@ jobs: # Runs a set of commands using the runners shell - name: Prettier Action uses: creyD/prettier_action@v3.3 - diff --git a/.gitignore b/.gitignore index 8cf7a42..94ff50b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ node_modules/ package-lock.json -.nova -archive .DS_Store +/pkg +/pkg.tgz +/dist +DEBUG-* +/.yarn \ No newline at end of file diff --git a/.yarnrc.yml b/.yarnrc.yml new file mode 100644 index 0000000..3186f3f --- /dev/null +++ b/.yarnrc.yml @@ -0,0 +1 @@ +nodeLinker: node-modules diff --git a/README.md b/README.md index 5837bac..f1893a5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # companion-module-toggl-track -See [HELP.md](./HELP.md) and [LICENSE](./LICENSE) \ No newline at end of file + +See [HELP.md](./HELP.md) and [LICENSE](./LICENSE) diff --git a/actions.js b/actions.js index b1b001a..f298950 100644 --- a/actions.js +++ b/actions.js @@ -1,51 +1,49 @@ -export function updateActions() { - let actions = {} - - actions['startNewTimer'] = { - name: 'Start New Timer', - options: [ - { - type: 'textinput', - label: 'Description', - id: 'description', - default: '', +export default function (self) { + self.setActionDefinitions({ + startNewTimer: { + name: 'Start New Timer', + options: [ + { + type: 'textinput', + label: 'Description', + id: 'description', + default: '', + }, + { + type: 'dropdown', + label: 'Project', + id: 'project', + default: '0', + choices: self.projects, + }, + ], + callback: ({ options }) => { + self.startTimer(options.project, options.description) }, - { - type: 'dropdown', - label: 'Project', - id: 'project', - default: '0', - choices: this.projects, + }, + + getCurrentTimer: { + name: 'Get Current Timer', + options: [], + callback: (action) => { + self.getCurrentTimer() }, - ], - callback: ({ options }) => { - this.startTimer(options.project, options.description) }, - } - actions['getCurrentTimer'] = { - name: 'Get Current Timer', - options: [], - callback: (action) => { - this.getCurrentTimer() + stopCurrentTimer: { + name: 'Stop Current Timer', + options: [], + callback: (action) => { + self.stopTimer() + }, }, - } - actions['stopCurrentTimer'] = { - name: 'Stop Current Timer', - options: [], - callback: (action) => { - this.stopTimer() + refreshProjects: { + name: 'Refresh Project List', + options: [], + callback: (action) => { + self.getWorkspace() + }, }, - } - - actions['refreshProjects'] = { - name: 'Refresh Project List', - options: [], - callback: (action) => { - this.getWorkspace() - }, - } - - this.setActionDefinitions(actions) + }) } diff --git a/companion/HELP.md b/companion/HELP.md index a70c560..a030480 100644 --- a/companion/HELP.md +++ b/companion/HELP.md @@ -12,7 +12,7 @@ Paste this token into the config page of this module and click save. If all is w ## Actions -**Start New Timer** +**Start New Timer** Start a new timer running with the description set in the action and store the ID. If a list of projects has been retrieved on startup you can choose a project. By default a new timer can't be started if one is already running. This behaviour can be changed by ticking the 'Always Start' option in the module configuration. @@ -35,12 +35,15 @@ Presets are available for **Start Timer** and **Stop Timer**. ## History ### Version 1.0.0 + First release ### Version 1.0.1 + Fix broken link ### Version 1.0.2 + Allow a project to be specified when starting a new timer button Add an action to refresh the project list @@ -48,16 +51,17 @@ Add an action to refresh the project list Add 'Always start' configuration option ### Version 1.0.3 + Add variables for timerId and timerDescription ### Version 2.0.0 + Updated for Companion version 3 Updated for toggl API version 9 ### Version 2.0.1 + Make the API token config field required Fix manifest file - - diff --git a/companion/manifest.json b/companion/manifest.json index 6494f79..78aeafb 100644 --- a/companion/manifest.json +++ b/companion/manifest.json @@ -10,6 +10,9 @@ "maintainers": [ { "name": "Peter Daniel" + }, + { + "name": "Matthias Kesler" } ], "legacyIds": [], @@ -17,13 +20,9 @@ "type": "node18", "api": "nodejs-ipc", "apiVersion": "0.0.0", - "entrypoint": "../index.js" + "entrypoint": "../main.js" }, "manufacturer": "Toggl", - "products": [ - "Track" - ], - "keywords": [ - "Logging", "Timer", "Task Tracking", "Time Tracking", "Project Management" - ] + "products": ["Track"], + "keywords": ["Logging", "Timer", "Task Tracking", "Time Tracking", "Project Management"] } diff --git a/index.js b/main.js similarity index 95% rename from index.js rename to main.js index 75647b4..49667dc 100644 --- a/index.js +++ b/main.js @@ -2,19 +2,16 @@ // Peter Daniel import { InstanceBase, Regex, runEntrypoint, InstanceStatus } from '@companion-module/base' -import { updateActions } from './actions.js' -import { updatePresets } from './presets.js' -import { updateVariables } from './variables.js' -import { upgradeScripts } from './upgrades.js' +import UpdateActions from './actions.js' +import UpdatePresets from './presets.js' +import UpdateVariableDefinitions from './variables.js' +import UpgradeScripts from './upgrades.js' + import got from 'got' class toggltrack extends InstanceBase { constructor(internal) { super(internal) - - this.updateActions = updateActions.bind(this) - this.updatePresets = updatePresets.bind(this) - this.updateVariables = updateVariables.bind(this) } getConfigFields() { @@ -49,6 +46,8 @@ class toggltrack extends InstanceBase { this.config = config + this.updateStatus(InstanceStatus.Ok) + this.gotOptions = { responseType: 'json', throwHttpErrors: false, @@ -60,7 +59,7 @@ class toggltrack extends InstanceBase { this.workspaceName = null this.projects = [{ id: '0', label: 'None' }] - this.updateVariables() + this.updateVariableDefinitions() this.updatePresets() this.setVariableValues({ @@ -93,6 +92,21 @@ class toggltrack extends InstanceBase { this.updateActions() this.updateVariables() } + updateActions() { + UpdateActions(this) + } + + updateFeedbacks() { + UpdateFeedbacks(this) + } + + updatePresets() { + UpdatePresets(this) + } + + updateVariableDefinitions() { + UpdateVariableDefinitions(this) + } auth() { if (this.config.apiToken !== null && this.config.apiToken.length > 0) { @@ -355,7 +369,7 @@ class toggltrack extends InstanceBase { } else { this.updateStatus( InstanceStatus.UnknownError, - `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}` + `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}`, ) this.log('warn', `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}`) return null @@ -380,7 +394,7 @@ class toggltrack extends InstanceBase { } else { this.updateStatus( InstanceStatus.UnknownError, - `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}` + `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}`, ) this.log('warn', `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}`) return null @@ -405,7 +419,7 @@ class toggltrack extends InstanceBase { } else { this.updateStatus( InstanceStatus.UnknownError, - `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}` + `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}`, ) this.log('warn', `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}`) return null @@ -437,7 +451,7 @@ class toggltrack extends InstanceBase { } else { this.updateStatus( InstanceStatus.UnknownError, - `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}` + `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}`, ) this.log('warn', `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}`) return null @@ -454,4 +468,4 @@ class toggltrack extends InstanceBase { } } -runEntrypoint(toggltrack, upgradeScripts) +runEntrypoint(toggltrack, UpgradeScripts) diff --git a/package.json b/package.json index a9025ac..5d7953f 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,11 @@ { "name": "toggl-track", - "version": "2.0.1", - "main": "index.js", + "version": "2.0.2", + "main": "main.js", "type": "module", "scripts": { + "format": "prettier -w .", + "package": "companion-module-build", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { @@ -12,10 +14,12 @@ }, "license": "MIT", "dependencies": { - "@companion-module/base": "~1.4", + "@companion-module/base": "~1.11", "got": "~13.0.0" }, "devDependencies": { - "@companion-module/tools": "~1.1" - } -} \ No newline at end of file + "@companion-module/tools": "~2.1.0", + "prettier": "^3.4.2" + }, + "prettier": "@companion-module/tools/.prettierrc.json" +} diff --git a/presets.js b/presets.js index 9900c3f..c4eeff6 100644 --- a/presets.js +++ b/presets.js @@ -1,58 +1,56 @@ import { combineRgb } from '@companion-module/base' -export function updatePresets() { - let presets = {} - - presets['Start'] = { - type: 'button', - category: 'Timer', - name: 'Start', - style: { - text: 'Start Timer', - size: '18', - color: combineRgb(255, 255, 255), - bgcolor: combineRgb(0, 0, 0), - }, - steps: [ - { - down: [ - { - actionId: 'startNewTimer', - options: { - description: '', - project: '0', +export default function (self) { + self.setPresetDefinitions({ + Start: { + type: 'button', + category: 'Timer', + name: 'Start', + style: { + text: 'Start Timer', + size: '18', + color: combineRgb(255, 255, 255), + bgcolor: combineRgb(0, 0, 0), + }, + steps: [ + { + down: [ + { + actionId: 'startNewTimer', + options: { + description: '', + project: '0', + }, }, - }, - ], - up: [], - }, - ], - feedbacks: [], - } - - presets['Stop'] = { - type: 'button', - category: 'Timer', - name: 'Stop', - style: { - text: 'Stop Timer', - size: '18', - color: combineRgb(255, 255, 255), - bgcolor: combineRgb(0, 0, 0), + ], + up: [], + }, + ], + feedbacks: [], }, - steps: [ - { - down: [ - { - actionId: 'stopCurrentTimer', - options: {}, - }, - ], - up: [], - }, - ], - feedbacks: [], - } - this.setPresetDefinitions(presets) + Stop: { + type: 'button', + category: 'Timer', + name: 'Stop', + style: { + text: 'Stop Timer', + size: '18', + color: combineRgb(255, 255, 255), + bgcolor: combineRgb(0, 0, 0), + }, + steps: [ + { + down: [ + { + actionId: 'stopCurrentTimer', + options: {}, + }, + ], + up: [], + }, + ], + feedbacks: [], + }, + }) } diff --git a/upgrades.js b/upgrades.js index 806abc8..006a02f 100644 --- a/upgrades.js +++ b/upgrades.js @@ -1,7 +1,13 @@ -export function upgradeScripts() { - return { - updatedConfig: null, - updatedActions: [], - updatedFeedbacks: [], - } -} +export default [ + /* + * Place your upgrade scripts here + * Remember that once it has been added it cannot be removed! + */ + // function (context, props) { + // return { + // updatedConfig: null, + // updatedActions: [], + // updatedFeedbacks: [], + // } + // }, +] diff --git a/variables.js b/variables.js index d3ef14c..3f55750 100644 --- a/variables.js +++ b/variables.js @@ -1,7 +1,5 @@ -export function updateVariables() { - let variables = [] - - variables.push( +export default function (self) { + self.setVariableDefinitions([ { name: 'Workspace', variableId: 'workspace', @@ -21,8 +19,6 @@ export function updateVariables() { { name: 'Current Timer Description', variableId: 'timerDescription', - } - ) - - this.setVariableDefinitions(variables) + }, + ]) }