@@ -16,7 +16,7 @@ import { WebviewMessages } from './webview/messages'
1616import { validateTokenInput } from './inputBox'
1717import { findPythonBinForInstall } from './autoInstall'
1818import { run , runWithRecheck , runWorkspace } from './runner'
19- import { isStudioAccessToken } from './token '
19+ import { Studio } from './studio '
2020import {
2121 PYTHON_EXTENSION_ACTION ,
2222 pickFocusedProjects ,
@@ -51,13 +51,7 @@ import { createFileSystemWatcher } from '../fileSystem/watcher'
5151import { EventName } from '../telemetry/constants'
5252import { WorkspaceScale } from '../telemetry/collect'
5353import { gitPath } from '../cli/git/constants'
54- import {
55- Flag ,
56- ConfigKey ,
57- DOT_DVC ,
58- Args ,
59- SubCommand
60- } from '../cli/dvc/constants'
54+ import { DOT_DVC , Args , SubCommand } from '../cli/dvc/constants'
6155import { GLOBAL_WEBVIEW_DVCROOT } from '../webview/factory'
6256import { getValidInput } from '../vscode/inputBox'
6357import { Title } from '../vscode/title'
@@ -87,6 +81,7 @@ export class Setup
8781 private readonly config : Config
8882 private readonly status : Status
8983 private readonly internalCommands : InternalCommands
84+ private readonly studio : Studio
9085
9186 private readonly webviewMessages : WebviewMessages
9287 private readonly getHasData : ( ) => boolean | undefined
@@ -103,9 +98,6 @@ export class Setup
10398 new EventEmitter ( )
10499 )
105100
106- private readonly studioConnectionChanged : EventEmitter < void > =
107- this . dispose . track ( new EventEmitter ( ) )
108-
109101 private readonly onDidChangeWorkspace : Event < void > =
110102 this . workspaceChanged . event
111103
@@ -117,10 +109,6 @@ export class Setup
117109
118110 private dotFolderWatcher ?: Disposer
119111
120- private studioAccessToken : string | undefined = undefined
121- private studioIsConnected = false
122- private shareLiveToStudio : boolean | undefined = undefined
123-
124112 private focusedSection : SetupSection | undefined = undefined
125113
126114 constructor (
@@ -155,11 +143,13 @@ export class Setup
155143 }
156144
157145 this . collectWorkspaceScale = collectWorkspaceScale
158- this . onDidChangeStudioConnection = this . studioConnectionChanged . event
159146
160147 this . setCommandsAvailability ( false )
161148 this . setProjectAvailability ( )
162149
150+ this . studio = new Studio ( internalCommands , ( ) => this . getCwd ( ) )
151+ this . onDidChangeStudioConnection = this . studio . onDidChangeStudioConnection
152+
163153 this . webviewMessages = this . createWebviewMessageHandler ( )
164154
165155 void this . sendDataToWebview ( )
@@ -311,34 +301,12 @@ export class Setup
311301 }
312302 }
313303
314- public async removeStudioAccessToken ( ) {
304+ public removeStudioAccessToken ( ) {
315305 if ( ! this . getCliCompatible ( ) ) {
316306 return
317307 }
318308
319- if ( this . dvcRoots . length !== 1 ) {
320- const cwd = getFirstWorkspaceFolder ( )
321- if ( ! cwd ) {
322- return
323- }
324- return await this . accessConfig (
325- cwd ,
326- Flag . GLOBAL ,
327- Flag . UNSET ,
328- ConfigKey . STUDIO_TOKEN
329- )
330- }
331-
332- const cwd = this . dvcRoots [ 0 ]
333-
334- await this . accessConfig ( cwd , Flag . LOCAL , Flag . UNSET , ConfigKey . STUDIO_TOKEN )
335-
336- return await this . accessConfig (
337- cwd ,
338- Flag . GLOBAL ,
339- Flag . UNSET ,
340- ConfigKey . STUDIO_TOKEN
341- )
309+ return this . studio . removeStudioAccessToken ( this . dvcRoots )
342310 }
343311
344312 public async saveStudioAccessToken ( ) {
@@ -357,12 +325,12 @@ export class Setup
357325 return
358326 }
359327
360- await this . accessConfig ( cwd , Flag . GLOBAL , ConfigKey . STUDIO_TOKEN , token )
328+ await this . studio . saveStudioAccessTokenInConfig ( cwd , token )
361329 return this . updateStudioAndSend ( )
362330 }
363331
364332 public getStudioAccessToken ( ) {
365- return this . studioAccessToken
333+ return this . studio . getStudioAccessToken ( )
366334 }
367335
368336 public sendInitialWebviewData ( ) {
@@ -438,14 +406,14 @@ export class Setup
438406 isPythonEnvironmentGlobal,
439407 isPythonExtensionInstalled : this . config . isPythonExtensionInstalled ( ) ,
440408 isPythonExtensionUsed,
441- isStudioConnected : this . studioIsConnected ,
409+ isStudioConnected : this . studio . getStudioIsConnected ( ) ,
442410 needsGitCommit,
443411 needsGitInitialized,
444412 projectInitialized,
445413 pythonBinPath : getBinDisplayText ( pythonBinPath ) ,
446414 remoteList,
447415 sectionCollapsed : collectSectionCollapsed ( this . focusedSection ) ,
448- shareLiveToStudio : ! ! this . shareLiveToStudio
416+ shareLiveToStudio : ! ! this . studio . getShareLiveToStudio ( )
449417 } )
450418 this . focusedSection = undefined
451419 }
@@ -454,7 +422,7 @@ export class Setup
454422 const webviewMessages = new WebviewMessages (
455423 ( ) => this . getWebview ( ) ,
456424 ( ) => this . initializeGit ( ) ,
457- ( offline : boolean ) => this . updateStudioOffline ( offline ) ,
425+ ( offline : boolean ) => this . studio . updateStudioOffline ( offline ) ,
458426 ( ) => this . isPythonExtensionUsed ( ) ,
459427 ( ) => this . updatePythonEnvironment ( )
460428 )
@@ -707,18 +675,10 @@ export class Setup
707675 }
708676
709677 private async updateStudioAndSend ( ) {
710- await this . updateIsStudioConnected ( )
678+ await this . studio . updateIsStudioConnected ( )
711679 return this . sendDataToWebview ( )
712680 }
713681
714- private async updateIsStudioConnected ( ) {
715- await this . setStudioValues ( )
716- const storedToken = this . getStudioAccessToken ( )
717- const isConnected = isStudioAccessToken ( storedToken )
718- this . studioIsConnected = isConnected
719- return setContextValue ( ContextKey . STUDIO_CONNECTED , isConnected )
720- }
721-
722682 private watchDvcConfigs ( ) {
723683 const createWatcher = ( watchedPath : string ) =>
724684 createFileSystemWatcher (
@@ -760,51 +720,6 @@ export class Setup
760720 ] )
761721 }
762722
763- private async setStudioValues ( ) {
764- const cwd = this . getCwd ( )
765-
766- const previousStudioAccessToken = this . studioAccessToken
767-
768- if ( ! cwd ) {
769- this . studioAccessToken = undefined
770- this . shareLiveToStudio = undefined
771-
772- if ( previousStudioAccessToken ) {
773- this . studioConnectionChanged . fire ( )
774- }
775- return
776- }
777-
778- const [ studioAccessToken , shareLiveToStudio ] = await Promise . all ( [
779- this . accessConfig ( cwd , ConfigKey . STUDIO_TOKEN ) ,
780- ( await this . accessConfig ( cwd , ConfigKey . STUDIO_OFFLINE ) ) !== 'true'
781- ] )
782-
783- this . studioAccessToken = studioAccessToken
784- this . shareLiveToStudio = shareLiveToStudio
785-
786- if ( previousStudioAccessToken !== this . studioAccessToken ) {
787- this . studioConnectionChanged . fire ( )
788- }
789- }
790-
791- private async updateStudioOffline ( shareLive : boolean ) {
792- const offline = ! shareLive
793-
794- const cwd = this . getCwd ( )
795-
796- if ( ! cwd ) {
797- return
798- }
799-
800- await this . accessConfig (
801- cwd ,
802- Flag . GLOBAL ,
803- ConfigKey . STUDIO_OFFLINE ,
804- String ( offline )
805- )
806- }
807-
808723 private getCwd ( ) {
809724 if ( ! this . getCliCompatible ( ) ) {
810725 return
@@ -814,14 +729,6 @@ export class Setup
814729 : getFirstWorkspaceFolder ( )
815730 }
816731
817- private accessConfig ( cwd : string , ...args : Args ) {
818- return this . internalCommands . executeCommand (
819- AvailableCommands . CONFIG ,
820- cwd ,
821- ...args
822- )
823- }
824-
825732 private accessRemote ( cwd : string , ...args : Args ) {
826733 return this . internalCommands . executeCommand (
827734 AvailableCommands . REMOTE ,
0 commit comments