parent
217515344e
commit
c607015a26
@ -1,5 +1,6 @@
|
|||||||
import * as os from "os";
|
import * as os from "os";
|
||||||
import { IProgress, INotificationHandle } from "@coder/ide";
|
import { IProgress, INotificationHandle } from "@coder/ide";
|
||||||
|
import { logger } from "@coder/logger";
|
||||||
import { client } from "./client";
|
import { client } from "./client";
|
||||||
|
|
||||||
import "./fill/platform";
|
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 { RawContextKey, IContextKeyService } from "vs/platform/contextkey/common/contextkey";
|
||||||
import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection";
|
import { ServiceCollection } from "vs/platform/instantiation/common/serviceCollection";
|
||||||
import { URI } from "vs/base/common/uri";
|
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 {
|
export class Workbench {
|
||||||
public readonly retry = client.retry;
|
public readonly retry = client.retry;
|
||||||
|
|
||||||
@ -36,6 +43,9 @@ export class Workbench {
|
|||||||
private _serviceCollection: ServiceCollection | undefined;
|
private _serviceCollection: ServiceCollection | undefined;
|
||||||
private _clipboardContextKey: RawContextKey<boolean> | undefined;
|
private _clipboardContextKey: RawContextKey<boolean> | undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle a drop event on the file explorer.
|
||||||
|
*/
|
||||||
public async handleExternalDrop(target: ExplorerItem | ExplorerModel, originalEvent: DragEvent): Promise<void> {
|
public async handleExternalDrop(target: ExplorerItem | ExplorerModel, originalEvent: DragEvent): Promise<void> {
|
||||||
await client.upload.uploadDropped(
|
await client.upload.uploadDropped(
|
||||||
originalEvent,
|
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 {
|
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));
|
const uris = paths.map((p) => URI.file(p));
|
||||||
if (uris.length) {
|
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 => ({
|
const editors: IResourceEditor[] = uris.map(uri => ({
|
||||||
@ -59,10 +72,10 @@ export class Workbench {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
const targetGroup = resolveTargetGroup();
|
const targetGroup = resolveTargetGroup();
|
||||||
|
await (this.serviceCollection.get(IEditorService) as IEditorService).openEditors(editors, targetGroup);
|
||||||
(this.serviceCollection.get(IEditorService) as IEditorService).openEditors(editors, targetGroup).then(() => {
|
afterDrop(targetGroup);
|
||||||
afterDrop(targetGroup);
|
}).catch((error) => {
|
||||||
});
|
logger.error(error.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +130,15 @@ export class Workbench {
|
|||||||
|
|
||||||
public set serviceCollection(collection: ServiceCollection) {
|
public set serviceCollection(collection: ServiceCollection) {
|
||||||
this._serviceCollection = collection;
|
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 = {
|
client.progressService = {
|
||||||
start: <T>(title: string, task: (progress: IProgress) => Promise<T>, onCancel: () => void): Promise<T> => {
|
start: <T>(title: string, task: (progress: IProgress) => Promise<T>, onCancel: () => void): Promise<T> => {
|
||||||
let lastProgress = 0;
|
let lastProgress = 0;
|
||||||
@ -166,6 +188,9 @@ export class Workbench {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start VS Code.
|
||||||
|
*/
|
||||||
public async initialize(): Promise<void> {
|
public async initialize(): Promise<void> {
|
||||||
this._clipboardContextKey = new RawContextKey("nativeClipboard", client.clipboard.isEnabled);
|
this._clipboardContextKey = new RawContextKey("nativeClipboard", client.clipboard.isEnabled);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user