Skip to content

Commit

Permalink
refactor connect
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Mar 3, 2023
1 parent 62c67de commit 7aa6377
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions extension/src/connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Connect extends BaseRepository<ConnectData> {
void this.getSecret(STUDIO_ACCESS_TOKEN_KEY).then(
async studioAccessToken => {
this.studioAccessToken = studioAccessToken
await this.setContext()
await this.updateIsStudioConnected()
this.deferred.resolve()
}
)
Expand All @@ -46,8 +46,9 @@ export class Connect extends BaseRepository<ConnectData> {
if (e.key !== STUDIO_ACCESS_TOKEN_KEY) {
return
}

this.studioAccessToken = await this.getSecret(STUDIO_ACCESS_TOKEN_KEY)
return this.setContext()
return this.updateIsStudioConnected()
})
)

Expand Down Expand Up @@ -133,17 +134,16 @@ export class Connect extends BaseRepository<ConnectData> {
return openUrl(`${STUDIO_URL}/user/_/profile?section=accessToken`)
}

private setContext() {
private updateIsStudioConnected() {
const storedToken = this.getStudioAccessToken()
if (isStudioAccessToken(storedToken)) {
this.studioIsConnected = true
this.sendWebviewMessage()
return setContextValue(ContextKey.STUDIO_CONNECTED, true)
}
const isConnected = isStudioAccessToken(storedToken)
return this.setStudioIsConnected(isConnected)
}

this.studioIsConnected = false
private setStudioIsConnected(isConnected: boolean) {
this.studioIsConnected = isConnected
this.sendWebviewMessage()
return setContextValue(ContextKey.STUDIO_CONNECTED, false)
return setContextValue(ContextKey.STUDIO_CONNECTED, isConnected)
}

private getSecret(key: string) {
Expand Down

0 comments on commit 7aa6377

Please sign in to comment.