diff --git a/packages/vscode/src/workbench.ts b/packages/vscode/src/workbench.ts index 73fc77e96f7c..dcd703e205b5 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); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy