Skip to content

Commit a05e996

Browse files
committed
Initialize backup service
- Fixes #399 - Fixes #332
1 parent dcf409a commit a05e996

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

packages/vscode/src/workbench.ts

+34-7
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,40 @@ 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";
31-
32+
import { SyncDescriptor } from "vs/platform/instantiation/common/descriptors";
33+
import { BackupMainService } from "vs/platform/backup/electron-main/backupMainService";
34+
import { IBackupMainService } from "vs/platform/backup/common/backup";
35+
import { IInstantiationService } from "vs/platform/instantiation/common/instantiation";
36+
37+
/**
38+
* Initializes VS Code and provides a way to call into general client
39+
* functionality.
40+
*/
3241
export class Workbench {
3342
public readonly retry = client.retry;
3443

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

48+
/**
49+
* Handles a drop event on the file explorer.
50+
*/
3951
public async handleExternalDrop(target: ExplorerItem | ExplorerModel, originalEvent: DragEvent): Promise<void> {
4052
await client.upload.uploadDropped(
4153
originalEvent,
4254
(target instanceof ExplorerItem ? target : target.roots[0]).resource,
4355
);
4456
}
4557

58+
/**
59+
* Handles a drop event on the editor.
60+
*/
4661
public handleDrop(event: DragEvent, resolveTargetGroup: () => IEditorGroup, afterDrop: (targetGroup: IEditorGroup) => void, targetIndex?: number): void {
47-
client.upload.uploadDropped(event, URI.file(paths.getWorkingDirectory())).then((paths) => {
62+
client.upload.uploadDropped(event, URI.file(paths.getWorkingDirectory())).then(async (paths) => {
4863
const uris = paths.map((p) => URI.file(p));
4964
if (uris.length) {
50-
(this.serviceCollection.get(IWindowsService) as IWindowsService).addRecentlyOpened(uris);
65+
await (this.serviceCollection.get(IWindowsService) as IWindowsService).addRecentlyOpened(uris);
5166
}
5267

5368
const editors: IResourceEditor[] = uris.map(uri => ({
@@ -59,10 +74,10 @@ export class Workbench {
5974
}));
6075

6176
const targetGroup = resolveTargetGroup();
62-
63-
(this.serviceCollection.get(IEditorService) as IEditorService).openEditors(editors, targetGroup).then(() => {
64-
afterDrop(targetGroup);
65-
});
77+
await (this.serviceCollection.get(IEditorService) as IEditorService).openEditors(editors, targetGroup);
78+
afterDrop(targetGroup);
79+
}).catch((error) => {
80+
logger.error(error.message);
6681
});
6782
}
6883

@@ -117,6 +132,15 @@ export class Workbench {
117132

118133
public set serviceCollection(collection: ServiceCollection) {
119134
this._serviceCollection = collection;
135+
136+
// TODO: If possible it might be better to start the app from vs/code/electron-main/app.
137+
// For now, manually initialize services from there as needed.
138+
const init = this._serviceCollection.get(IInstantiationService) as IInstantiationService;
139+
const backupMainService = init.createInstance(BackupMainService) as BackupMainService;
140+
backupMainService.initialize().catch((error) => {
141+
logger.error(error.message);
142+
});
143+
120144
client.progressService = {
121145
start: <T>(title: string, task: (progress: IProgress) => Promise<T>, onCancel: () => void): Promise<T> => {
122146
let lastProgress = 0;
@@ -166,6 +190,9 @@ export class Workbench {
166190
};
167191
}
168192

193+
/**
194+
* Start VS Code.
195+
*/
169196
public async initialize(): Promise<void> {
170197
this._clipboardContextKey = new RawContextKey("nativeClipboard", client.clipboard.isEnabled);
171198

0 commit comments

Comments
 (0)