Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions packages/vscode/src/workbench.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -28,26 +29,38 @@ 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;

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

/**
* Handle a drop event on the file explorer.
*/
public async handleExternalDrop(target: ExplorerItem | ExplorerModel, originalEvent: DragEvent): Promise<void> {
await client.upload.uploadDropped(
originalEvent,
(target instanceof ExplorerItem ? target : target.roots[0]).resource,
);
}

/**
* 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 => ({
Expand All @@ -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);
});
}

Expand Down Expand Up @@ -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: <T>(title: string, task: (progress: IProgress) => Promise<T>, onCancel: () => void): Promise<T> => {
let lastProgress = 0;
Expand Down Expand Up @@ -166,6 +188,9 @@ export class Workbench {
};
}

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

Expand Down
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