Skip to content

Commit c607015

Browse files
authored
Initialize backup service (#419)
- Fixes #399 - Fixes #332
1 parent 2175153 commit c607015

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

packages/vscode/src/workbench.ts

+31-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as os from "os";
22
import { IProgress, INotificationHandle } from "@coder/ide";
3+
import { logger } from "@coder/logger";
34
import { client } from "./client";
45

56
import "./fill/platform";
@@ -28,26 +29,38 @@ import { LogLevel } from "vs/platform/log/common/log";
2829
import { RawContextKey, IContextKeyService } from "vs/platform/contextkey/common/contextkey";
2930
import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection";
3031
import { URI } from "vs/base/common/uri";
32+
import { BackupMainService } from "vs/platform/backup/electron-main/backupMainService";
33+
import { IInstantiationService } from "vs/platform/instantiation/common/instantiation";
3134

35+
/**
36+
* Initializes VS Code and provides a way to call into general client
37+
* functionality.
38+
*/
3239
export class Workbench {
3340
public readonly retry = client.retry;
3441

3542
private readonly windowId = parseInt(new Date().toISOString().replace(/[-:.TZ]/g, ""), 10);
3643
private _serviceCollection: ServiceCollection | undefined;
3744
private _clipboardContextKey: RawContextKey<boolean> | undefined;
3845

46+
/**
47+
* Handle a drop event on the file explorer.
48+
*/
3949
public async handleExternalDrop(target: ExplorerItem | ExplorerModel, originalEvent: DragEvent): Promise<void> {
4050
await client.upload.uploadDropped(
4151
originalEvent,
4252
(target instanceof ExplorerItem ? target : target.roots[0]).resource,
4353
);
4454
}
4555

56+
/**
57+
* Handle a drop event on the editor.
58+
*/
4659
public handleDrop(event: DragEvent, resolveTargetGroup: () => IEditorGroup, afterDrop: (targetGroup: IEditorGroup) => void, targetIndex?: number): void {
47-
client.upload.uploadDropped(event, URI.file(paths.getWorkingDirectory())).then((paths) => {
60+
client.upload.uploadDropped(event, URI.file(paths.getWorkingDirectory())).then(async (paths) => {
4861
const uris = paths.map((p) => URI.file(p));
4962
if (uris.length) {
50-
(this.serviceCollection.get(IWindowsService) as IWindowsService).addRecentlyOpened(uris);
63+
await (this.serviceCollection.get(IWindowsService) as IWindowsService).addRecentlyOpened(uris);
5164
}
5265

5366
const editors: IResourceEditor[] = uris.map(uri => ({
@@ -59,10 +72,10 @@ export class Workbench {
5972
}));
6073

6174
const targetGroup = resolveTargetGroup();
62-
63-
(this.serviceCollection.get(IEditorService) as IEditorService).openEditors(editors, targetGroup).then(() => {
64-
afterDrop(targetGroup);
65-
});
75+
await (this.serviceCollection.get(IEditorService) as IEditorService).openEditors(editors, targetGroup);
76+
afterDrop(targetGroup);
77+
}).catch((error) => {
78+
logger.error(error.message);
6679
});
6780
}
6881

@@ -117,6 +130,15 @@ export class Workbench {
117130

118131
public set serviceCollection(collection: ServiceCollection) {
119132
this._serviceCollection = collection;
133+
134+
// TODO: If possible it might be better to start the app from vs/code/electron-main/app.
135+
// For now, manually initialize services from there as needed.
136+
const inst = this._serviceCollection.get(IInstantiationService) as IInstantiationService;
137+
const backupMainService = inst.createInstance(BackupMainService) as BackupMainService;
138+
backupMainService.initialize().catch((error) => {
139+
logger.error(error.message);
140+
});
141+
120142
client.progressService = {
121143
start: <T>(title: string, task: (progress: IProgress) => Promise<T>, onCancel: () => void): Promise<T> => {
122144
let lastProgress = 0;
@@ -166,6 +188,9 @@ export class Workbench {
166188
};
167189
}
168190

191+
/**
192+
* Start VS Code.
193+
*/
169194
public async initialize(): Promise<void> {
170195
this._clipboardContextKey = new RawContextKey("nativeClipboard", client.clipboard.isEnabled);
171196

0 commit comments

Comments
 (0)