fix startup new instance

This commit is contained in:
Peter Daniel
2023-06-29 12:58:49 +01:00
parent 3f50c7e71a
commit b9e7695675

View File

@@ -19,7 +19,7 @@ class toggltrack extends InstanceBase {
} }
getConfigFields() { getConfigFields() {
console.log('config fields') // console.log('config fields')
return [ return [
{ {
type: 'textinput', type: 'textinput',
@@ -62,13 +62,6 @@ class toggltrack extends InstanceBase {
this.updateVariables() this.updateVariables()
this.updatePresets() this.updatePresets()
this.gotOptions.headers = this.auth()
this.getWorkspace()
this.getCurrentTimer().then((timerId) => {
console.log('Init current timer id: ' + timerId)
})
this.setVariableValues({ this.setVariableValues({
timerId: null, timerId: null,
timerDuration: null, timerDuration: null,
@@ -77,6 +70,14 @@ class toggltrack extends InstanceBase {
workspace: null, workspace: null,
}) })
this.gotOptions.headers = this.auth()
if (this.gotOptions.headers != null) {
this.getWorkspace().then(
this.getCurrentTimer()
)
}
this.updateActions() this.updateActions()
} }
@@ -85,7 +86,7 @@ class toggltrack extends InstanceBase {
console.log('config updated') console.log('config updated')
this.config = config this.config = config
this.auth() this.gotOptions.headers = this.auth()
this.getWorkspace() this.getWorkspace()
this.updateActions() this.updateActions()
this.updateVariables() this.updateVariables()
@@ -97,7 +98,6 @@ class toggltrack extends InstanceBase {
let headers = {} let headers = {}
headers['Content-Type'] = 'application/json' headers['Content-Type'] = 'application/json'
headers['authorization'] = 'Basic ' + auth headers['authorization'] = 'Basic ' + auth
console.log(headers)
return headers return headers
} else { } else {
this.log('warn', 'Please enter your toggl API token') this.log('warn', 'Please enter your toggl API token')
@@ -109,7 +109,7 @@ class toggltrack extends InstanceBase {
async getCurrentTimer() { async getCurrentTimer() {
console.log('function: getCurrentTimer') console.log('function: getCurrentTimer')
if (this.gotOptions.headers.authorization == undefined) { if (this.gotOptions.headers == null) {
this.log('warn', 'Not authorized') this.log('warn', 'Not authorized')
return return
} }
@@ -150,11 +150,11 @@ class toggltrack extends InstanceBase {
}) })
} }
getWorkspace() { async getWorkspace() {
let cmd = 'workspaces' let cmd = 'workspaces'
console.log('function: getWorkspace') console.log('function: getWorkspace')
if (this.gotOptions.headers.authorization == undefined) { if (this.gotOptions.headers == null) {
this.log('warn', 'Not authorized') this.log('warn', 'Not authorized')
return return
} }
@@ -287,7 +287,7 @@ class toggltrack extends InstanceBase {
'","created_with":"companion","project_id":' + project + '","created_with":"companion","project_id":' + project +
',"start":"' + startTime.toISOString() + '","duration":-1}' ',"start":"' + startTime.toISOString() + '","duration":-1}'
} }
console.log(body) // console.log(body)
this.sendPostCommand(cmd, body).then((result) => { this.sendPostCommand(cmd, body).then((result) => {
if (typeof result === 'object' && result !== null) { if (typeof result === 'object' && result !== null) {
this.log('info', 'New timer started ' + result.id + " " + result.description) this.log('info', 'New timer started ' + result.id + " " + result.description)