diff --git a/extension/src/setup/index.ts b/extension/src/setup/index.ts index bfc02bdc12..524732deae 100644 --- a/extension/src/setup/index.ts +++ b/extension/src/setup/index.ts @@ -407,7 +407,7 @@ export class Setup const webviewMessages = new WebviewMessages( () => this.getWebview(), () => this.initializeGit(), - (offline: boolean) => this.setStudioOffline(offline) + (offline: boolean) => this.updateStudioOffline(offline) ) this.dispose.track( this.onDidReceivedWebviewMessage(message => @@ -673,46 +673,24 @@ export class Setup } private async setStudioValues() { - if (!this.getCliCompatible()) { + const cwd = this.getCwd() + + if (!cwd) { this.studioAccessToken = undefined this.shareLiveToStudio = undefined return } - if (this.dvcRoots.length !== 1) { - const cwd = getFirstWorkspaceFolder() - if (!cwd) { - this.studioAccessToken = undefined - this.shareLiveToStudio = undefined - return - } - - ;[this.studioAccessToken] = await Promise.all([ - this.accessConfig(cwd, ConfigKey.STUDIO_TOKEN), - this.getStudioShareLive(cwd) - ]) - return - } - - ;[this.studioAccessToken] = await Promise.all([ - this.accessConfig(this.dvcRoots[0], ConfigKey.STUDIO_TOKEN), - this.getStudioShareLive(this.dvcRoots[0]) - ]) - } - - private async getStudioShareLive(cwd: string) { - this.shareLiveToStudio = + ;[this.studioAccessToken, this.shareLiveToStudio] = await Promise.all([ + this.accessConfig(cwd, ConfigKey.STUDIO_TOKEN), (await this.accessConfig(cwd, ConfigKey.STUDIO_OFFLINE)) !== 'true' + ]) } - private async setStudioOffline(shareLive: boolean) { + private async updateStudioOffline(shareLive: boolean) { const offline = !shareLive - if (!this.getCliCompatible()) { - return - } - const cwd = - this.dvcRoots.length === 1 ? this.dvcRoots[0] : getFirstWorkspaceFolder() + const cwd = this.getCwd() if (!cwd) { return @@ -726,6 +704,15 @@ export class Setup ) } + private getCwd() { + if (!this.getCliCompatible()) { + return + } + return this.dvcRoots.length === 1 + ? this.dvcRoots[0] + : getFirstWorkspaceFolder() + } + private accessConfig(cwd: string, ...args: Args) { return this.accessDvc(AvailableCommands.CONFIG, cwd, ...args) } diff --git a/extension/src/setup/webview/messages.ts b/extension/src/setup/webview/messages.ts index f4352ba73b..2f8ca8475c 100644 --- a/extension/src/setup/webview/messages.ts +++ b/extension/src/setup/webview/messages.ts @@ -19,16 +19,16 @@ import { openUrl } from '../../vscode/external' export class WebviewMessages { private readonly getWebview: () => BaseWebview | undefined private readonly initializeGit: () => void - private readonly setStudioOffline: (offline: boolean) => Promise + private readonly updateStudioOffline: (offline: boolean) => Promise constructor( getWebview: () => BaseWebview | undefined, initializeGit: () => void, - setStudioOffline: (shareLive: boolean) => Promise + updateStudioOffline: (shareLive: boolean) => Promise ) { this.getWebview = getWebview this.initializeGit = initializeGit - this.setStudioOffline = setStudioOffline + this.updateStudioOffline = updateStudioOffline } public sendWebviewMessage({ @@ -102,7 +102,7 @@ export class WebviewMessages { RegisteredCommands.REMOVE_STUDIO_ACCESS_TOKEN ) case MessageFromWebviewType.SET_STUDIO_SHARE_EXPERIMENTS_LIVE: - return this.setStudioOffline(message.payload) + return this.updateStudioOffline(message.payload) case MessageFromWebviewType.OPEN_EXPERIMENTS_WEBVIEW: return commands.executeCommand(RegisteredCommands.EXPERIMENT_SHOW) case MessageFromWebviewType.REMOTE_ADD: