From c607015a26bb2dfde3532cb63ea6b825bb436e7e Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 3 Apr 2019 16:08:15 -0500 Subject: [PATCH] Initialize backup service (#419) - Fixes #399 - Fixes #332 --- packages/vscode/src/workbench.ts | 37 ++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/packages/vscode/src/workbench.ts b/packages/vscode/src/workbench.ts index 73fc77e9..dcd703e2 100644 --- a/packages/vscode/src/workbench.ts +++ b/packages/vscode/src/workbench.ts @@ -1,5 +1,6 @@ import * as os from "os"; import { IProgress, INotificationHandle } from "@coder/ide"; +import { logger } from "@coder/logger"; import { client } from "./client"; import "./fill/platform"; @@ -28,7 +29,13 @@ import { LogLevel } from "vs/platform/log/common/log"; import { RawContextKey, IContextKeyService } from "vs/platform/contextkey/common/contextkey"; import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection"; import { URI } from "vs/base/common/uri"; +import { BackupMainService } from "vs/platform/backup/electron-main/backupMainService"; +import { IInstantiationService } from "vs/platform/instantiation/common/instantiation"; +/** + * Initializes VS Code and provides a way to call into general client + * functionality. + */ export class Workbench { public readonly retry = client.retry; @@ -36,6 +43,9 @@ export class Workbench { private _serviceCollection: ServiceCollection | undefined; private _clipboardContextKey: RawContextKey | undefined; + /** + * Handle a drop event on the file explorer. + */ public async handleExternalDrop(target: ExplorerItem | ExplorerModel, originalEvent: DragEvent): Promise { await client.upload.uploadDropped( originalEvent, @@ -43,11 +53,14 @@ export class Workbench { ); } + /** + * Handle a drop event on the editor. + */ public handleDrop(event: DragEvent, resolveTargetGroup: () => IEditorGroup, afterDrop: (targetGroup: IEditorGroup) => void, targetIndex?: number): void { - client.upload.uploadDropped(event, URI.file(paths.getWorkingDirectory())).then((paths) => { + client.upload.uploadDropped(event, URI.file(paths.getWorkingDirectory())).then(async (paths) => { const uris = paths.map((p) => URI.file(p)); if (uris.length) { - (this.serviceCollection.get(IWindowsService) as IWindowsService).addRecentlyOpened(uris); + await (this.serviceCollection.get(IWindowsService) as IWindowsService).addRecentlyOpened(uris); } const editors: IResourceEditor[] = uris.map(uri => ({ @@ -59,10 +72,10 @@ export class Workbench { })); const targetGroup = resolveTargetGroup(); - - (this.serviceCollection.get(IEditorService) as IEditorService).openEditors(editors, targetGroup).then(() => { - afterDrop(targetGroup); - }); + await (this.serviceCollection.get(IEditorService) as IEditorService).openEditors(editors, targetGroup); + afterDrop(targetGroup); + }).catch((error) => { + logger.error(error.message); }); } @@ -117,6 +130,15 @@ export class Workbench { public set serviceCollection(collection: ServiceCollection) { this._serviceCollection = collection; + + // TODO: If possible it might be better to start the app from vs/code/electron-main/app. + // For now, manually initialize services from there as needed. + const inst = this._serviceCollection.get(IInstantiationService) as IInstantiationService; + const backupMainService = inst.createInstance(BackupMainService) as BackupMainService; + backupMainService.initialize().catch((error) => { + logger.error(error.message); + }); + client.progressService = { start: (title: string, task: (progress: IProgress) => Promise, onCancel: () => void): Promise => { let lastProgress = 0; @@ -166,6 +188,9 @@ export class Workbench { }; } + /** + * Start VS Code. + */ public async initialize(): Promise { this._clipboardContextKey = new RawContextKey("nativeClipboard", client.clipboard.isEnabled);