diff --git a/src/feedbacks.ts b/src/feedbacks.ts new file mode 100644 index 0000000..1c64025 --- /dev/null +++ b/src/feedbacks.ts @@ -0,0 +1,29 @@ +import { combineRgb } from '@companion-module/base' +import type { TogglTrack } from './main.js' + +export function UpdateFeedbacks(self: TogglTrack): void { + self.setFeedbackDefinitions({ + ProjectRunningState: { + name: 'Project Counting', + type: 'boolean', + defaultStyle: { + bgcolor: combineRgb(255, 0, 0), + color: combineRgb(0, 0, 0), + }, + options: [ + { + id: 'project', + type: 'dropdown', + label: 'Project', + default: -1, + choices: [{ id: -1, label: 'None' }].concat(self.projects!), + }, + ], + callback: (feedback) => { + const projID = self.getVariableValue('timerProjectID') + self.log('debug', 'check if ' + feedback.options.project + '=' + projID) + return feedback.options.project == projID + }, + }, + }) +} diff --git a/src/main.ts b/src/main.ts index 8732e06..ddb0db4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,6 +7,7 @@ import UpdateActions from './actions.js' import UpdatePresets from './presets.js' import UpdateVariableDefinitions from './variables.js' import UpgradeScripts from './upgrades.js' +import { UpdateFeedbacks } from './feedbacks.js' import { Toggl, ITimeEntry, IWorkspaceProject } from 'toggl-track' import { togglGetWorkspaces } from './toggl-extend.js' @@ -56,6 +57,7 @@ export class TogglTrack extends InstanceBase { await this.initToggleConnection() this.updateActions() + this.updateFeedbacks() if (this.toggl && this.workspaceId) { this.updateStatus(InstanceStatus.Ok) @@ -105,6 +107,9 @@ export class TogglTrack extends InstanceBase { updateActions(): void { UpdateActions(this) } + updateFeedbacks(): void { + UpdateFeedbacks(this) + } updatePresets(): void { UpdatePresets(this) @@ -149,6 +154,18 @@ export class TogglTrack extends InstanceBase { clearInterval(this.intervalId) } + private setCurrentProject(projectID: number | undefined): void { + let pName: string | undefined + if (typeof projectID === 'number') { + pName = this.projects!.find((v) => v.id == projectID)?.label + } + this.setVariableValues({ + timerProject: pName, + timerProjectID: projectID, + }) + this.checkFeedbacks('ProjectRunningState') + } + async getCurrentTimer(): Promise { this.log('debug', 'function: getCurrentTimer') @@ -167,6 +184,7 @@ export class TogglTrack extends InstanceBase { timerDescription: entry.description, timerDuration: entry.duration, }) + this.setCurrentProject(entry.project_id) return entry.id } else { @@ -176,6 +194,7 @@ export class TogglTrack extends InstanceBase { timerDescription: undefined, timerDuration: undefined, }) + this.setCurrentProject(undefined) return null } } @@ -289,6 +308,7 @@ export class TogglTrack extends InstanceBase { timerDescription: newEntry.description, timerDuration: newEntry.duration, }) + this.setCurrentProject(newEntry.project_id) } else { this.log('info', 'A timer is already running ' + currentId + ' not starting a new one!') } @@ -314,6 +334,7 @@ export class TogglTrack extends InstanceBase { timerDuration: undefined, lastTimerDuration: updated.duration, }) + this.setCurrentProject(undefined) } else { this.log('warn', 'No running timer to stop or running timer id unknown') } diff --git a/src/variables.ts b/src/variables.ts index 3599c1a..dd7ac63 100644 --- a/src/variables.ts +++ b/src/variables.ts @@ -22,5 +22,13 @@ export default function (self: TogglTrack): void { name: 'Current Timer Description', variableId: 'timerDescription', }, + { + name: 'Current Timer Project ID', + variableId: 'timerProjectID', + }, + { + name: 'Current Timer Project', + variableId: 'timerProject', + }, ]) }