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
# 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

View File

@@ -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

7
.gitignore vendored
View File

@@ -1,5 +1,8 @@
node_modules/
package-lock.json
.nova
archive
.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
See [HELP.md](./HELP.md) and [LICENSE](./LICENSE)

View File

@@ -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)
})
}

View File

@@ -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

View File

@@ -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"]
}

View File

@@ -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)

View File

@@ -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"
}
"@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'
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: [],
},
})
}

View File

@@ -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: [],
// }
// },
]

View File

@@ -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)
},
])
}