diff --git a/src/vs/platform/windows/common/windows.ts b/src/vs/platform/windows/common/windows.ts index 855ba57f2de3224b51fb9fc4f6060b9319409ba8..ec3b736429de1c13717e7941ca9e6aabe5b5b23c 100644 --- a/src/vs/platform/windows/common/windows.ts +++ b/src/vs/platform/windows/common/windows.ts @@ -44,6 +44,7 @@ export interface IWindowsService { openNewWindow(): TPromise; showWindow(windowId: number): TPromise; getWindows(): TPromise<{ id: number; path: string; title: string; }[]>; + getWindowCount(): TPromise; log(severity: string, ...messages: string[]): TPromise; // TODO@joao: what? closeExtensionHostWindow(extensionDevelopmentPath: string): TPromise; diff --git a/src/vs/platform/windows/common/windowsIpc.ts b/src/vs/platform/windows/common/windowsIpc.ts index 55e70ee622a784ec800178deff15e5fe85577f02..9b24d363900554233cccfab2cebdf98d1c05dc8b 100644 --- a/src/vs/platform/windows/common/windowsIpc.ts +++ b/src/vs/platform/windows/common/windowsIpc.ts @@ -34,6 +34,7 @@ export interface IWindowsChannel extends IChannel { call(command: 'openNewWindow'): TPromise; call(command: 'showWindow', arg: number): TPromise; call(command: 'getWindows'): TPromise<{ id: number; path: string; title: string; }[]>; + call(command: 'getWindowCount'): TPromise; call(command: 'log', arg: [string, string[]]): TPromise; call(command: 'closeExtensionHostWindow', arg: string): TPromise; call(command: 'showItemInFolder', arg: string): TPromise; @@ -78,6 +79,7 @@ export class WindowsChannel implements IWindowsChannel { case 'openNewWindow': return this.service.openNewWindow(); case 'showWindow': return this.service.showWindow(arg); case 'getWindows': return this.service.getWindows(); + case 'getWindowCount': return this.service.getWindowCount(); case 'log': return this.service.log(arg[0], arg[1]); case 'closeExtensionHostWindow': return this.service.closeExtensionHostWindow(arg); case 'showItemInFolder': return this.service.showItemInFolder(arg); @@ -187,6 +189,10 @@ export class WindowsChannelClient implements IWindowsService { return this.channel.call('getWindows'); } + getWindowCount(): TPromise { + return this.channel.call('getWindowCount'); + } + log(severity: string, ...messages: string[]): TPromise { return this.channel.call('log', [severity, messages]); } diff --git a/src/vs/platform/windows/electron-main/windowsService.ts b/src/vs/platform/windows/electron-main/windowsService.ts index 45d23674bd844afdae2e7a629f1e0193a365490d..a2f664cd414a28e37eb05b80c05dc80bd61b299d 100644 --- a/src/vs/platform/windows/electron-main/windowsService.ts +++ b/src/vs/platform/windows/electron-main/windowsService.ts @@ -226,6 +226,10 @@ export class WindowsService implements IWindowsService, IDisposable { return TPromise.as(result); } + getWindowCount(): TPromise { + return TPromise.as(this.windowsMainService.getWindows().length); + } + log(severity: string, ...messages: string[]): TPromise { console[severity].apply(console, ...messages); return TPromise.as(null); diff --git a/src/vs/workbench/services/backup/common/backup.ts b/src/vs/workbench/services/backup/common/backup.ts index 029dcfb0b6afb965bcd254be3a153ed5daaa5c10..b956c4091bf37f4adb59d6e7648980c078c2707e 100644 --- a/src/vs/workbench/services/backup/common/backup.ts +++ b/src/vs/workbench/services/backup/common/backup.ts @@ -35,13 +35,6 @@ export interface IBackupService { export interface IBackupFileService { _serviceBrand: any; - /** - * Gets the set of active workspace backup paths being tracked for restoration. - * - * @return The set of active workspace backup paths being tracked for restoration. - */ - getWorkspaceBackupPaths(): TPromise; - /** * Gets whether a text file has a backup to restore. * diff --git a/src/vs/workbench/services/backup/node/backupFileService.ts b/src/vs/workbench/services/backup/node/backupFileService.ts index 230c09cde84a105f71ba8c2186ddc8c3f17e2ff8..2100efea90bc61308d1ebfc9f9c6670469903da7 100644 --- a/src/vs/workbench/services/backup/node/backupFileService.ts +++ b/src/vs/workbench/services/backup/node/backupFileService.ts @@ -9,7 +9,6 @@ import * as path from 'path'; import * as crypto from 'crypto'; import pfs = require('vs/base/node/pfs'); import Uri from 'vs/base/common/uri'; -import { IBackupWorkspacesFormat } from 'vs/platform/backup/common/backup'; import { IBackupFileService } from 'vs/workbench/services/backup/common/backup'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IFileService } from 'vs/platform/files/common/files'; @@ -31,16 +30,6 @@ export class BackupFileService implements IBackupFileService { this.workspacesJsonPath = environmentService.backupWorkspacesPath; } - public getWorkspaceBackupPaths(): TPromise { - if (this.environmentService.isExtensionDevelopment) { - return TPromise.as([]); - } - - return this.loadWorkspaces().then(workspacesJsonContent => { - return workspacesJsonContent.folderWorkspaces; - }); - } - public hasBackup(resource: Uri): TPromise { const backupResource = this.getBackupResource(resource); if (!backupResource) { @@ -103,29 +92,4 @@ export class BackupFileService implements IBackupFileService { return this.fileService.del(Uri.file(this.getWorkspaceBackupDirectory())); } - - private loadWorkspaces(): TPromise { - return pfs.readFile(this.workspacesJsonPath, 'utf8').then(content => { - let result: IBackupWorkspacesFormat; - try { - result = JSON.parse(content.toString()); - // Ensure folderWorkspaces is a string[] - if (result.folderWorkspaces) { - const fws = result.folderWorkspaces; - if (!Array.isArray(fws) || fws.some(f => typeof f !== 'string')) { - result = Object.create(null); - } - } - } catch (ex) { - result = Object.create(null); - } - - if (!result.folderWorkspaces) { - result.folderWorkspaces = []; - } - return result; - }, () => { - return { folderWorkspaces: [] }; - }); - } } \ No newline at end of file diff --git a/src/vs/workbench/services/backup/node/backupService.ts b/src/vs/workbench/services/backup/node/backupService.ts index 9fa6bee1d6018abe4dc502365bbf5c33b5313007..564f6cb3660a8286dec627d95d4e10c88d2d7417 100644 --- a/src/vs/workbench/services/backup/node/backupService.ts +++ b/src/vs/workbench/services/backup/node/backupService.ts @@ -16,6 +16,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { TPromise } from 'vs/base/common/winjs.base'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { IWindowsService } from 'vs/platform/windows/common/windows'; export class BackupService implements IBackupService { @@ -34,7 +35,8 @@ export class BackupService implements IBackupService { @IFileService private fileService: IFileService, @IUntitledEditorService private untitledEditorService: IUntitledEditorService, @IWorkspaceContextService private contextService: IWorkspaceContextService, - @IEnvironmentService private environmentService: IEnvironmentService + @IEnvironmentService private environmentService: IEnvironmentService, + @IWindowsService private windowsService: IWindowsService ) { this.toDispose = []; @@ -98,12 +100,12 @@ export class BackupService implements IBackupService { return TPromise.as({ didBackup: false }); } - return this.backupFileService.getWorkspaceBackupPaths().then(workspaceBackupPaths => { + return this.windowsService.getWindowCount().then(windowCount => { // When quit is requested skip the confirm callback and attempt to backup all workspaces. // When quit is not requested the confirm callback should be shown when the window being // closed is the only VS Code window open, except for on Mac where hot exit is only // ever activated when quit is requested. - if (!quitRequested && (workspaceBackupPaths.length > 1 || platform.isMacintosh)) { + if (!quitRequested && (windowCount > 1 || platform.isMacintosh)) { return TPromise.as({ didBackup: false }); } diff --git a/src/vs/workbench/services/backup/test/backupFileService.test.ts b/src/vs/workbench/services/backup/test/backupFileService.test.ts index bdfbc8c2a5517bf5032e6ef4265f30477ab5956e..a50e706788471e7b8267c5b9a7f3042bcaac2ed4 100644 --- a/src/vs/workbench/services/backup/test/backupFileService.test.ts +++ b/src/vs/workbench/services/backup/test/backupFileService.test.ts @@ -156,64 +156,4 @@ suite('BackupFileService', () => { }); }); }); - - test('getWorkspaceBackupPaths should return [] when workspaces.json doesn\'t exist', () => { - fs.unlinkSync(workspacesJsonPath); - service.getWorkspaceBackupPaths().then(paths => assert.deepEqual(paths, [])); - }); - - test('getWorkspaceBackupPathsSync should return [] when workspaces.json is not properly formed JSON #1', () => { - fs.writeFileSync(workspacesJsonPath, ''); - service.getWorkspaceBackupPaths().then(paths => assert.deepEqual(paths, [])); - }); - - test('getWorkspaceBackupPathsSync should return [] when workspaces.json is not properly formed JSON #1', () => { - fs.writeFileSync(workspacesJsonPath, '{]'); - service.getWorkspaceBackupPaths().then(paths => assert.deepEqual(paths, [])); - }); - - test('getWorkspaceBackupPathsSync should return [] when workspaces.json is not properly formed JSON #1', () => { - fs.writeFileSync(workspacesJsonPath, 'foo'); - service.getWorkspaceBackupPaths().then(paths => assert.deepEqual(paths, [])); - }); - - test('getWorkspaceBackupPathsSync should return [] when folderWorkspaces in workspaces.json is absent', () => { - fs.writeFileSync(workspacesJsonPath, '{}'); - service.getWorkspaceBackupPaths().then(paths => assert.deepEqual(paths, [])); - }); - - test('getWorkspaceBackupPaths should return [] when folderWorkspaces in workspaces.json is not a string array #1', () => { - fs.writeFileSync(workspacesJsonPath, '{"folderWorkspaces":{}}'); - service.getWorkspaceBackupPaths().then(paths => assert.deepEqual(paths, [])); - }); - - test('getWorkspaceBackupPaths should return [] when folderWorkspaces in workspaces.json is not a string array #2', () => { - fs.writeFileSync(workspacesJsonPath, '{"folderWorkspaces":{"foo": ["bar"]}}'); - service.getWorkspaceBackupPaths().then(paths => assert.deepEqual(paths, [])); - }); - - test('getWorkspaceBackupPaths should return [] when folderWorkspaces in workspaces.json is not a string array #3', () => { - fs.writeFileSync(workspacesJsonPath, '{"folderWorkspaces":{"foo": []}}'); - service.getWorkspaceBackupPaths().then(paths => assert.deepEqual(paths, [])); - }); - - test('getWorkspaceBackupPaths should return [] when folderWorkspaces in workspaces.json is not a string array #4', () => { - fs.writeFileSync(workspacesJsonPath, '{"folderWorkspaces":{"foo": "bar"}}'); - service.getWorkspaceBackupPaths().then(paths => assert.deepEqual(paths, [])); - }); - - test('getWorkspaceBackupPaths should return [] when folderWorkspaces in workspaces.json is not a string array #5', () => { - fs.writeFileSync(workspacesJsonPath, '{"folderWorkspaces":"foo"}'); - service.getWorkspaceBackupPaths().then(paths => assert.deepEqual(paths, [])); - }); - - test('getWorkspaceBackupPaths should return [] when folderWorkspaces in workspaces.json is not a string array #6', () => { - fs.writeFileSync(workspacesJsonPath, '{"folderWorkspaces":1}'); - service.getWorkspaceBackupPaths().then(paths => assert.deepEqual(paths, [])); - }); - - test('getWorkspaceBackupPaths should return the contents of folderWorkspaces in workspaces.json', () => { - fs.writeFileSync(workspacesJsonPath, '{"folderWorkspaces":["foo", "bar"]}'); - service.getWorkspaceBackupPaths().then(paths => assert.deepEqual(paths, ['foo', 'bar'])); - }); }); \ No newline at end of file