diff --git a/src/container.ts b/src/container.ts index 16e39f2..8e80f67 100644 --- a/src/container.ts +++ b/src/container.ts @@ -33,7 +33,7 @@ import { } from './plus/webviews/graph/registration'; import { GraphStatusBarController } from './plus/webviews/graph/statusbar'; import { registerTimelineWebviewPanel, registerTimelineWebviewView } from './plus/webviews/timeline/registration'; -import { WorkspacesService } from './plus/workspaces/workspacesService'; +import { scheduleAddMissingCurrentWorkspaceRepos, WorkspacesService } from './plus/workspaces/workspacesService'; import { StatusBarController } from './statusbar/statusBarController'; import { executeCommand } from './system/command'; import { configuration } from './system/configuration'; @@ -166,6 +166,7 @@ export class Container { }, }; + private readonly _connection: ServerConnection; private _disposables: Disposable[]; private _terminalLinks: GitTerminalLinkProvider | undefined; private _webviews: WebviewsController; @@ -191,16 +192,15 @@ export class Container { this._richRemoteProviders = new RichRemoteProviderService(this); - const connection = new ServerConnection(this); - this._disposables.push(connection); + this._disposables.push((this._connection = new ServerConnection(this))); - this._disposables.push((this._accountAuthentication = new AccountAuthenticationProvider(this, connection))); - this._disposables.push((this._subscription = new SubscriptionService(this, connection, previousVersion))); - this._disposables.push((this._workspaces = new WorkspacesService(this, connection))); + this._disposables.push( + (this._accountAuthentication = new AccountAuthenticationProvider(this, this._connection)), + ); + this._disposables.push((this._subscription = new SubscriptionService(this, this._connection, previousVersion))); this._disposables.push((this._git = new GitProviderService(this))); this._disposables.push(new GitFileSystemProvider(this)); - this._disposables.push((this._repositoryPathMapping = getSupportedRepositoryPathMappingProvider(this))); this._disposables.push((this._uri = new UriService(this))); @@ -212,7 +212,6 @@ export class Container { this._disposables.push((this._keyboard = new Keyboard())); this._disposables.push((this._vsls = new VslsController(this))); this._disposables.push((this._eventBus = new EventBus())); - this._disposables.push((this._ai = new AIProviderService(this))); this._disposables.push((this._fileAnnotationController = new FileAnnotationController(this))); this._disposables.push((this._lineAnnotationController = new LineAnnotationController(this))); @@ -274,6 +273,8 @@ export class Container { context.subscriptions.push({ dispose: () => this._disposables.reverse().forEach(d => void d.dispose()), }); + + scheduleAddMissingCurrentWorkspaceRepos(this); } deactivate() { @@ -334,8 +335,11 @@ export class Container { return this._actionRunners; } - private readonly _ai: AIProviderService; + private _ai: AIProviderService | undefined; get ai() { + if (this._ai == null) { + this._disposables.push((this._ai = new AIProviderService(this))); + } return this._ai; } @@ -529,8 +533,11 @@ export class Container { return this._lineTracker; } - private readonly _repositoryPathMapping: RepositoryPathMappingProvider; + private _repositoryPathMapping: RepositoryPathMappingProvider | undefined; get repositoryPathMapping() { + if (this._repositoryPathMapping == null) { + this._disposables.push((this._repositoryPathMapping = getSupportedRepositoryPathMappingProvider(this))); + } return this._repositoryPathMapping; } @@ -632,8 +639,11 @@ export class Container { return this._vsls; } - private _workspaces: WorkspacesService; + private _workspaces: WorkspacesService | undefined; get workspaces() { + if (this._workspaces == null) { + this._disposables.push((this._workspaces = new WorkspacesService(this, this._connection))); + } return this._workspaces; } diff --git a/src/plus/workspaces/workspacesService.ts b/src/plus/workspaces/workspacesService.ts index 8740767..02c88f9 100644 --- a/src/plus/workspaces/workspacesService.ts +++ b/src/plus/workspaces/workspacesService.ts @@ -60,14 +60,11 @@ export class WorkspacesService implements Disposable { ) { this._workspacesApi = new WorkspacesApi(this.container, this.connection); this._workspacesPathProvider = getSupportedWorkspacesPathMappingProvider(); - this._currentWorkspaceId = workspace.getConfiguration('gitkraken')?.get('workspaceId'); + this._currentWorkspaceId = getCurrentWorkspaceId(); this._currentWorkspaceAutoAddSetting = workspace.getConfiguration('gitkraken')?.get('workspaceAutoAddSetting') ?? WorkspaceAutoAddSetting.Disabled; this._disposable = Disposable.from(container.subscription.onDidChange(this.onSubscriptionChanged, this)); - if (this._currentWorkspaceId != null) { - setTimeout(() => this.addMissingCurrentWorkspaceRepos(), 10000); - } } dispose(): void { @@ -1342,6 +1339,17 @@ function getRemoteDescriptor(remote: GitRemote): RemoteDescriptor | undefined { }; } +function getCurrentWorkspaceId(): string | undefined { + return workspace.getConfiguration('gitkraken')?.get('workspaceId'); +} + +export function scheduleAddMissingCurrentWorkspaceRepos(container: Container) { + const currentWorkspaceId = getCurrentWorkspaceId(); + if (currentWorkspaceId == null) return; + + setTimeout(() => container.workspaces.addMissingCurrentWorkspaceRepos(), 10000); +} + // TODO: Add back in once we think through virtual repository support a bit more. /* function encodeAuthority(scheme: string, metadata?: T): string { return `${scheme}${metadata != null ? `+${encodeUtf8Hex(JSON.stringify(metadata))}` : ''}`; diff --git a/src/views/workspacesView.ts b/src/views/workspacesView.ts index 35e38aa..cb3e023 100644 --- a/src/views/workspacesView.ts +++ b/src/views/workspacesView.ts @@ -18,19 +18,16 @@ import { registerViewCommand } from './viewCommands'; export class WorkspacesView extends ViewBase<'workspaces', WorkspacesViewNode, RepositoriesViewConfig> { protected readonly configKey = 'repositories'; - private _disposable: Disposable; + private _disposable: Disposable | undefined; constructor(container: Container) { super(container, 'workspaces', 'Workspaces', 'workspaceView'); - this._disposable = Disposable.from( - this.container.workspaces.onDidResetWorkspaces(() => void this.ensureRoot().triggerChange(true)), - ); this.description = `PREVIEW\u00a0\u00a0☁️`; } override dispose() { - this._disposable.dispose(); + this._disposable?.dispose(); super.dispose(); } @@ -44,6 +41,13 @@ export class WorkspacesView extends ViewBase<'workspaces', WorkspacesViewNode, R override async show(options?: { preserveFocus?: boolean | undefined }): Promise { if (!(await ensurePlusFeaturesEnabled())) return; + + if (this._disposable == null) { + this._disposable = Disposable.from( + this.container.workspaces.onDidResetWorkspaces(() => void this.ensureRoot().triggerChange(true)), + ); + } + return super.show(options); }