update module to newer and more aligned to template structure

This commit is contained in:
2025-01-14 11:42:29 +01:00
parent c7eccd3571
commit 9dc24f2d7b
13 changed files with 169 additions and 147 deletions

View File

@@ -15,4 +15,3 @@ jobs:
uses: bitfocus/actions/.github/workflows/module-checks.yaml@main uses: bitfocus/actions/.github/workflows/module-checks.yaml@main
# with: # 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 # upload-artifact: true # uncomment this to upload the built package as an artifact to this workflow that you can download and share with others

View File

@@ -6,9 +6,9 @@ name: CI
on: on:
# Triggers the workflow on push or pull request events but only for the main branch # Triggers the workflow on push or pull request events but only for the main branch
push: push:
branches: [ main ] branches: [main]
pull_request: pull_request:
branches: [ main ] branches: [main]
# Allows you to run this workflow manually from the Actions tab # Allows you to run this workflow manually from the Actions tab
workflow_dispatch: workflow_dispatch:
@@ -28,4 +28,3 @@ jobs:
# Runs a set of commands using the runners shell # Runs a set of commands using the runners shell
- name: Prettier Action - name: Prettier Action
uses: creyD/prettier_action@v3.3 uses: creyD/prettier_action@v3.3

7
.gitignore vendored
View File

@@ -1,5 +1,8 @@
node_modules/ node_modules/
package-lock.json package-lock.json
.nova
archive
.DS_Store .DS_Store
/pkg
/pkg.tgz
/dist
DEBUG-*
/.yarn

1
.yarnrc.yml Normal file
View File

@@ -0,0 +1 @@
nodeLinker: node-modules

View File

@@ -1,2 +1,3 @@
# companion-module-toggl-track # companion-module-toggl-track
See [HELP.md](./HELP.md) and [LICENSE](./LICENSE) See [HELP.md](./HELP.md) and [LICENSE](./LICENSE)

View File

@@ -1,51 +1,49 @@
export function updateActions() { export default function (self) {
let actions = {} self.setActionDefinitions({
startNewTimer: {
actions['startNewTimer'] = { name: 'Start New Timer',
name: 'Start New Timer', options: [
options: [ {
{ type: 'textinput',
type: 'textinput', label: 'Description',
label: 'Description', id: 'description',
id: 'description', default: '',
default: '', },
{
type: 'dropdown',
label: 'Project',
id: 'project',
default: '0',
choices: self.projects,
},
],
callback: ({ options }) => {
self.startTimer(options.project, options.description)
}, },
{ },
type: 'dropdown',
label: 'Project', getCurrentTimer: {
id: 'project', name: 'Get Current Timer',
default: '0', options: [],
choices: this.projects, callback: (action) => {
self.getCurrentTimer()
}, },
],
callback: ({ options }) => {
this.startTimer(options.project, options.description)
}, },
}
actions['getCurrentTimer'] = { stopCurrentTimer: {
name: 'Get Current Timer', name: 'Stop Current Timer',
options: [], options: [],
callback: (action) => { callback: (action) => {
this.getCurrentTimer() self.stopTimer()
},
}, },
}
actions['stopCurrentTimer'] = { refreshProjects: {
name: 'Stop Current Timer', name: 'Refresh Project List',
options: [], options: [],
callback: (action) => { callback: (action) => {
this.stopTimer() self.getWorkspace()
},
}, },
} })
actions['refreshProjects'] = {
name: 'Refresh Project List',
options: [],
callback: (action) => {
this.getWorkspace()
},
}
this.setActionDefinitions(actions)
} }

View File

@@ -35,12 +35,15 @@ Presets are available for **Start Timer** and **Stop Timer**.
## History ## History
### Version 1.0.0 ### Version 1.0.0
First release First release
### Version 1.0.1 ### Version 1.0.1
Fix broken link Fix broken link
### Version 1.0.2 ### Version 1.0.2
Allow a project to be specified when starting a new timer button Allow a project to be specified when starting a new timer button
Add an action to refresh the project list 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 Add 'Always start' configuration option
### Version 1.0.3 ### Version 1.0.3
Add variables for timerId and timerDescription Add variables for timerId and timerDescription
### Version 2.0.0 ### Version 2.0.0
Updated for Companion version 3 Updated for Companion version 3
Updated for toggl API version 9 Updated for toggl API version 9
### Version 2.0.1 ### Version 2.0.1
Make the API token config field required Make the API token config field required
Fix manifest file Fix manifest file

View File

@@ -10,6 +10,9 @@
"maintainers": [ "maintainers": [
{ {
"name": "Peter Daniel" "name": "Peter Daniel"
},
{
"name": "Matthias Kesler"
} }
], ],
"legacyIds": [], "legacyIds": [],
@@ -17,13 +20,9 @@
"type": "node18", "type": "node18",
"api": "nodejs-ipc", "api": "nodejs-ipc",
"apiVersion": "0.0.0", "apiVersion": "0.0.0",
"entrypoint": "../index.js" "entrypoint": "../main.js"
}, },
"manufacturer": "Toggl", "manufacturer": "Toggl",
"products": [ "products": ["Track"],
"Track" "keywords": ["Logging", "Timer", "Task Tracking", "Time Tracking", "Project Management"]
],
"keywords": [
"Logging", "Timer", "Task Tracking", "Time Tracking", "Project Management"
]
} }

View File

@@ -2,19 +2,16 @@
// Peter Daniel // Peter Daniel
import { InstanceBase, Regex, runEntrypoint, InstanceStatus } from '@companion-module/base' import { InstanceBase, Regex, runEntrypoint, InstanceStatus } from '@companion-module/base'
import { updateActions } from './actions.js' import UpdateActions from './actions.js'
import { updatePresets } from './presets.js' import UpdatePresets from './presets.js'
import { updateVariables } from './variables.js' import UpdateVariableDefinitions from './variables.js'
import { upgradeScripts } from './upgrades.js' import UpgradeScripts from './upgrades.js'
import got from 'got' import got from 'got'
class toggltrack extends InstanceBase { class toggltrack extends InstanceBase {
constructor(internal) { constructor(internal) {
super(internal) super(internal)
this.updateActions = updateActions.bind(this)
this.updatePresets = updatePresets.bind(this)
this.updateVariables = updateVariables.bind(this)
} }
getConfigFields() { getConfigFields() {
@@ -49,6 +46,8 @@ class toggltrack extends InstanceBase {
this.config = config this.config = config
this.updateStatus(InstanceStatus.Ok)
this.gotOptions = { this.gotOptions = {
responseType: 'json', responseType: 'json',
throwHttpErrors: false, throwHttpErrors: false,
@@ -60,7 +59,7 @@ class toggltrack extends InstanceBase {
this.workspaceName = null this.workspaceName = null
this.projects = [{ id: '0', label: 'None' }] this.projects = [{ id: '0', label: 'None' }]
this.updateVariables() this.updateVariableDefinitions()
this.updatePresets() this.updatePresets()
this.setVariableValues({ this.setVariableValues({
@@ -93,6 +92,21 @@ class toggltrack extends InstanceBase {
this.updateActions() this.updateActions()
this.updateVariables() this.updateVariables()
} }
updateActions() {
UpdateActions(this)
}
updateFeedbacks() {
UpdateFeedbacks(this)
}
updatePresets() {
UpdatePresets(this)
}
updateVariableDefinitions() {
UpdateVariableDefinitions(this)
}
auth() { auth() {
if (this.config.apiToken !== null && this.config.apiToken.length > 0) { if (this.config.apiToken !== null && this.config.apiToken.length > 0) {
@@ -355,7 +369,7 @@ class toggltrack extends InstanceBase {
} else { } else {
this.updateStatus( this.updateStatus(
InstanceStatus.UnknownError, 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}`) this.log('warn', `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}`)
return null return null
@@ -380,7 +394,7 @@ class toggltrack extends InstanceBase {
} else { } else {
this.updateStatus( this.updateStatus(
InstanceStatus.UnknownError, 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}`) this.log('warn', `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}`)
return null return null
@@ -405,7 +419,7 @@ class toggltrack extends InstanceBase {
} else { } else {
this.updateStatus( this.updateStatus(
InstanceStatus.UnknownError, 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}`) this.log('warn', `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}`)
return null return null
@@ -437,7 +451,7 @@ class toggltrack extends InstanceBase {
} else { } else {
this.updateStatus( this.updateStatus(
InstanceStatus.UnknownError, 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}`) this.log('warn', `Unexpected HTTP status code: ${response.statusCode} - ${response.body.error}`)
return null return null
@@ -454,4 +468,4 @@ class toggltrack extends InstanceBase {
} }
} }
runEntrypoint(toggltrack, upgradeScripts) runEntrypoint(toggltrack, UpgradeScripts)

View File

@@ -1,9 +1,11 @@
{ {
"name": "toggl-track", "name": "toggl-track",
"version": "2.0.1", "version": "2.0.2",
"main": "index.js", "main": "main.js",
"type": "module", "type": "module",
"scripts": { "scripts": {
"format": "prettier -w .",
"package": "companion-module-build",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"repository": { "repository": {
@@ -12,10 +14,12 @@
}, },
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@companion-module/base": "~1.4", "@companion-module/base": "~1.11",
"got": "~13.0.0" "got": "~13.0.0"
}, },
"devDependencies": { "devDependencies": {
"@companion-module/tools": "~1.1" "@companion-module/tools": "~2.1.0",
} "prettier": "^3.4.2"
},
"prettier": "@companion-module/tools/.prettierrc.json"
} }

View File

@@ -1,58 +1,56 @@
import { combineRgb } from '@companion-module/base' import { combineRgb } from '@companion-module/base'
export function updatePresets() { export default function (self) {
let presets = {} self.setPresetDefinitions({
Start: {
presets['Start'] = { type: 'button',
type: 'button', category: 'Timer',
category: 'Timer', name: 'Start',
name: 'Start', style: {
style: { text: 'Start Timer',
text: 'Start Timer', size: '18',
size: '18', color: combineRgb(255, 255, 255),
color: combineRgb(255, 255, 255), bgcolor: combineRgb(0, 0, 0),
bgcolor: combineRgb(0, 0, 0), },
}, steps: [
steps: [ {
{ down: [
down: [ {
{ actionId: 'startNewTimer',
actionId: 'startNewTimer', options: {
options: { description: '',
description: '', project: '0',
project: '0', },
}, },
}, ],
], up: [],
up: [], },
}, ],
], feedbacks: [],
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),
}, },
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: [],
},
})
} }

View File

@@ -1,7 +1,13 @@
export function upgradeScripts() { export default [
return { /*
updatedConfig: null, * Place your upgrade scripts here
updatedActions: [], * Remember that once it has been added it cannot be removed!
updatedFeedbacks: [], */
} // function (context, props) {
} // return {
// updatedConfig: null,
// updatedActions: [],
// updatedFeedbacks: [],
// }
// },
]

View File

@@ -1,7 +1,5 @@
export function updateVariables() { export default function (self) {
let variables = [] self.setVariableDefinitions([
variables.push(
{ {
name: 'Workspace', name: 'Workspace',
variableId: 'workspace', variableId: 'workspace',
@@ -21,8 +19,6 @@ export function updateVariables() {
{ {
name: 'Current Timer Description', name: 'Current Timer Description',
variableId: 'timerDescription', variableId: 'timerDescription',
} },
) ])
this.setVariableDefinitions(variables)
} }