diff --git a/src/vs/workbench/services/files/electron-browser/fileService.ts b/src/vs/workbench/services/files/electron-browser/fileService.ts index f1be736dffc49c53afc07210b87dae5f93149677..219dd9ff8a947c30376a7f001b7ebcc908eda94e 100644 --- a/src/vs/workbench/services/files/electron-browser/fileService.ts +++ b/src/vs/workbench/services/files/electron-browser/fileService.ts @@ -18,7 +18,7 @@ import * as arrays from 'vs/base/common/arrays'; import { TPromise } from 'vs/base/common/winjs.base'; import * as objects from 'vs/base/common/objects'; import * as extfs from 'vs/base/node/extfs'; -import { nfcall, ThrottledDelayer } from 'vs/base/common/async'; +import { nfcall, ThrottledDelayer, asWinJsPromise } from 'vs/base/common/async'; import uri from 'vs/base/common/uri'; import * as nls from 'vs/nls'; import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform'; @@ -43,7 +43,6 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; import { onUnexpectedError } from 'vs/base/common/errors'; import product from 'vs/platform/node/product'; -import { shell } from 'electron'; import { IEncodingOverride, ResourceEncodings } from 'vs/workbench/services/files/electron-browser/encoding'; import { createReadableOfSnapshot } from 'vs/workbench/services/files/electron-browser/streams'; @@ -906,22 +905,25 @@ export class FileService implements IFileService { public del(resource: uri, useTrash?: boolean): TPromise { if (useTrash) { - return this.doMoveItemToTrash(resource); + return asWinJsPromise(() => this.doMoveItemToTrash(resource)); } return this.doDelete(resource); } - private doMoveItemToTrash(resource: uri): TPromise { + private doMoveItemToTrash(resource: uri): Promise { const absolutePath = resource.fsPath; - const result = shell.moveItemToTrash(absolutePath); - if (!result) { - return TPromise.wrapError(new Error(isWindows ? nls.localize('binFailed', "Failed to move '{0}' to the recycle bin", paths.basename(absolutePath)) : nls.localize('trashFailed', "Failed to move '{0}' to the trash", paths.basename(absolutePath)))); - } - this._onAfterOperation.fire(new FileOperationEvent(resource, FileOperation.DELETE)); + return (import('electron')).then(electron => { // workaround for https://github.com/Microsoft/vscode/issues/48205 + const result = electron.shell.moveItemToTrash(absolutePath); + if (!result) { + return TPromise.wrapError(new Error(isWindows ? nls.localize('binFailed', "Failed to move '{0}' to the recycle bin", paths.basename(absolutePath)) : nls.localize('trashFailed', "Failed to move '{0}' to the trash", paths.basename(absolutePath)))); + } - return TPromise.as(null); + this._onAfterOperation.fire(new FileOperationEvent(resource, FileOperation.DELETE)); + + return TPromise.wrap(null); + }); } private doDelete(resource: uri): TPromise {