浏览代码

Delay load some services until needed

main
Eric Amodio 1年前
父节点
当前提交
a470ac8590
共有 3 个文件被更改,包括 42 次插入20 次删除
  1. +21
    -11
      src/container.ts
  2. +12
    -4
      src/plus/workspaces/workspacesService.ts
  3. +9
    -5
      src/views/workspacesView.ts

+ 21
- 11
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;
}

+ 12
- 4
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<string>('workspaceId');
this._currentWorkspaceId = getCurrentWorkspaceId();
this._currentWorkspaceAutoAddSetting =
workspace.getConfiguration('gitkraken')?.get<WorkspaceAutoAddSetting>('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<string>('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<T>(scheme: string, metadata?: T): string {
return `${scheme}${metadata != null ? `+${encodeUtf8Hex(JSON.stringify(metadata))}` : ''}`;

+ 9
- 5
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<void> {
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);
}

正在加载...
取消
保存