Skip to content

Commit

Permalink
fix #64596
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Dec 11, 2018
1 parent 31b6323 commit d6b26a5
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 104 deletions.
41 changes: 23 additions & 18 deletions src/vs/code/electron-main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,7 @@ export class CodeApplication extends Disposable {
// Create Electron IPC Server
this.electronIpcServer = new ElectronIPCServer();

// Resolve unique machine ID
this.logService.trace('Resolving machine identifier...');
return this.resolveMachineId().then(machineId => {
const startupWithMachineId = (machineId: string) => {
this.logService.trace(`Resolved machine identifier: ${machineId}`);

// Spawn shared process
Expand Down Expand Up @@ -447,6 +445,28 @@ export class CodeApplication extends Disposable {
this.stopTracingEventually(windows);
}
});
};

// Resolve unique machine ID
this.logService.trace('Resolving machine identifier...');
const resolvedMachineId = this.resolveMachineId();
if (typeof resolvedMachineId === 'string') {
return startupWithMachineId(resolvedMachineId);
} else {
return resolvedMachineId.then(machineId => startupWithMachineId(machineId));
}
}

private resolveMachineId(): string | TPromise<string> {
const machineId = this.stateService.getItem<string>(CodeApplication.MACHINE_ID_KEY);
if (machineId) {
return machineId;
}

return getMachineId().then(machineId => {
this.stateService.setItem(CodeApplication.MACHINE_ID_KEY, machineId);

return machineId;
});
}

Expand Down Expand Up @@ -485,21 +505,6 @@ export class CodeApplication extends Disposable {
});
}

private resolveMachineId(): TPromise<string> {
const machineId = this.stateService.getItem<string>(CodeApplication.MACHINE_ID_KEY);
if (machineId) {
return TPromise.wrap(machineId);
}

return getMachineId().then(machineId => {

// Remember in global storage
this.stateService.setItem(CodeApplication.MACHINE_ID_KEY, machineId);

return machineId;
});
}

private initServices(machineId: string): Thenable<IInstantiationService> {
const services = new ServiceCollection();

Expand Down
6 changes: 3 additions & 3 deletions src/vs/code/electron-main/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2029,11 +2029,11 @@ class WorkspacesManager {

private isValidTargetWorkspacePath(window: ICodeWindow, path?: string): TPromise<boolean> {
if (!path) {
return TPromise.wrap(true);
return Promise.resolve(true);
}

if (window.openedWorkspace && window.openedWorkspace.configPath === path) {
return TPromise.wrap(false); // window is already opened on a workspace with that path
return Promise.resolve(false); // window is already opened on a workspace with that path
}

// Prevent overwriting a workspace that is currently opened in another window
Expand All @@ -2050,7 +2050,7 @@ class WorkspacesManager {
return this.windowsMainService.showMessageBox(options, this.windowsMainService.getFocusedWindow()).then(() => false);
}

return TPromise.wrap(true); // OK
return Promise.resolve(true); // OK
}

private doSaveAndOpenWorkspace(window: ICodeWindow, workspace: IWorkspaceIdentifier, path?: string): TPromise<IEnterWorkspaceResult> {
Expand Down
7 changes: 3 additions & 4 deletions src/vs/platform/windows/electron-main/windowsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,18 +551,17 @@ export class WindowsService implements IWindowsService, IURLHandler, IDisposable
// Catch file URLs
if (uri.authority === Schemas.file && !!uri.path) {
this.openFileForURI(URI.file(uri.fsPath));
return TPromise.as(true);
return Promise.resolve(true);
}

return TPromise.wrap(false);
return Promise.resolve(false);
}

private openFileForURI(uri: URI): TPromise<boolean> {
private openFileForURI(uri: URI): void {
const cli = assign(Object.create(null), this.environmentService.args, { goto: true });
const urisToOpen = [uri];

this.windowsMainService.open({ context: OpenContext.API, cli, urisToOpen });
return TPromise.wrap(true);
}

resolveProxy(windowId: number, url: string): Promise<string | undefined> {
Expand Down
98 changes: 49 additions & 49 deletions src/vs/platform/windows/node/windowsIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,79 +137,79 @@ export class WindowsChannelClient implements IWindowsService {
get onRecentlyOpenedChange(): Event<void> { return this.channel.listen('onRecentlyOpenedChange'); }

pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
return TPromise.wrap(this.channel.call('pickFileFolderAndOpen', options));
return this.channel.call('pickFileFolderAndOpen', options);
}

pickFileAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
return TPromise.wrap(this.channel.call('pickFileAndOpen', options));
return this.channel.call('pickFileAndOpen', options);
}

pickFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
return TPromise.wrap(this.channel.call('pickFolderAndOpen', options));
return this.channel.call('pickFolderAndOpen', options);
}

pickWorkspaceAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
return TPromise.wrap(this.channel.call('pickWorkspaceAndOpen', options));
return this.channel.call('pickWorkspaceAndOpen', options);
}

showMessageBox(windowId: number, options: MessageBoxOptions): TPromise<IMessageBoxResult> {
return TPromise.wrap(this.channel.call('showMessageBox', [windowId, options]));
return this.channel.call('showMessageBox', [windowId, options]);
}

showSaveDialog(windowId: number, options: SaveDialogOptions): TPromise<string> {
return TPromise.wrap(this.channel.call('showSaveDialog', [windowId, options]));
return this.channel.call('showSaveDialog', [windowId, options]);
}

showOpenDialog(windowId: number, options: OpenDialogOptions): TPromise<string[]> {
return TPromise.wrap(this.channel.call('showOpenDialog', [windowId, options]));
return this.channel.call('showOpenDialog', [windowId, options]);
}

reloadWindow(windowId: number, args?: ParsedArgs): TPromise<void> {
return TPromise.wrap(this.channel.call('reloadWindow', [windowId, args]));
return this.channel.call('reloadWindow', [windowId, args]);
}

openDevTools(windowId: number, options?: IDevToolsOptions): TPromise<void> {
return TPromise.wrap(this.channel.call('openDevTools', [windowId, options]));
return this.channel.call('openDevTools', [windowId, options]);
}

toggleDevTools(windowId: number): TPromise<void> {
return TPromise.wrap(this.channel.call('toggleDevTools', windowId));
return this.channel.call('toggleDevTools', windowId);
}

closeWorkspace(windowId: number): TPromise<void> {
return TPromise.wrap(this.channel.call('closeWorkspace', windowId));
return this.channel.call('closeWorkspace', windowId);
}

enterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult> {
return TPromise.wrap(this.channel.call('enterWorkspace', [windowId, path]));
return this.channel.call('enterWorkspace', [windowId, path]);
}

createAndEnterWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
return TPromise.wrap(this.channel.call('createAndEnterWorkspace', [windowId, folders, path]));
return this.channel.call('createAndEnterWorkspace', [windowId, folders, path]);
}

saveAndEnterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult> {
return TPromise.wrap(this.channel.call('saveAndEnterWorkspace', [windowId, path]));
return this.channel.call('saveAndEnterWorkspace', [windowId, path]);
}

toggleFullScreen(windowId: number): TPromise<void> {
return TPromise.wrap(this.channel.call('toggleFullScreen', windowId));
return this.channel.call('toggleFullScreen', windowId);
}

setRepresentedFilename(windowId: number, fileName: string): TPromise<void> {
return TPromise.wrap(this.channel.call('setRepresentedFilename', [windowId, fileName]));
return this.channel.call('setRepresentedFilename', [windowId, fileName]);
}

addRecentlyOpened(files: URI[]): TPromise<void> {
return TPromise.wrap(this.channel.call('addRecentlyOpened', files));
return this.channel.call('addRecentlyOpened', files);
}

removeFromRecentlyOpened(paths: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | URI)[]): TPromise<void> {
return TPromise.wrap(this.channel.call('removeFromRecentlyOpened', paths));
return this.channel.call('removeFromRecentlyOpened', paths);
}

clearRecentlyOpened(): TPromise<void> {
return TPromise.wrap(this.channel.call('clearRecentlyOpened'));
return this.channel.call('clearRecentlyOpened');
}

getRecentlyOpened(windowId: number): TPromise<IRecentlyOpened> {
Expand All @@ -222,127 +222,127 @@ export class WindowsChannelClient implements IWindowsService {
}

newWindowTab(): TPromise<void> {
return TPromise.wrap(this.channel.call('newWindowTab'));
return this.channel.call('newWindowTab');
}

showPreviousWindowTab(): TPromise<void> {
return TPromise.wrap(this.channel.call('showPreviousWindowTab'));
return this.channel.call('showPreviousWindowTab');
}

showNextWindowTab(): TPromise<void> {
return TPromise.wrap(this.channel.call('showNextWindowTab'));
return this.channel.call('showNextWindowTab');
}

moveWindowTabToNewWindow(): TPromise<void> {
return TPromise.wrap(this.channel.call('moveWindowTabToNewWindow'));
return this.channel.call('moveWindowTabToNewWindow');
}

mergeAllWindowTabs(): TPromise<void> {
return TPromise.wrap(this.channel.call('mergeAllWindowTabs'));
return this.channel.call('mergeAllWindowTabs');
}

toggleWindowTabsBar(): TPromise<void> {
return TPromise.wrap(this.channel.call('toggleWindowTabsBar'));
return this.channel.call('toggleWindowTabsBar');
}

focusWindow(windowId: number): TPromise<void> {
return TPromise.wrap(this.channel.call('focusWindow', windowId));
return this.channel.call('focusWindow', windowId);
}

closeWindow(windowId: number): TPromise<void> {
return TPromise.wrap(this.channel.call('closeWindow', windowId));
return this.channel.call('closeWindow', windowId);
}

isFocused(windowId: number): TPromise<boolean> {
return TPromise.wrap(this.channel.call('isFocused', windowId));
return this.channel.call('isFocused', windowId);
}

isMaximized(windowId: number): TPromise<boolean> {
return TPromise.wrap(this.channel.call('isMaximized', windowId));
return this.channel.call('isMaximized', windowId);
}

maximizeWindow(windowId: number): TPromise<void> {
return TPromise.wrap(this.channel.call('maximizeWindow', windowId));
return this.channel.call('maximizeWindow', windowId);
}

unmaximizeWindow(windowId: number): TPromise<void> {
return TPromise.wrap(this.channel.call('unmaximizeWindow', windowId));
return this.channel.call('unmaximizeWindow', windowId);
}

minimizeWindow(windowId: number): TPromise<void> {
return TPromise.wrap(this.channel.call('minimizeWindow', windowId));
return this.channel.call('minimizeWindow', windowId);
}

onWindowTitleDoubleClick(windowId: number): TPromise<void> {
return TPromise.wrap(this.channel.call('onWindowTitleDoubleClick', windowId));
return this.channel.call('onWindowTitleDoubleClick', windowId);
}

setDocumentEdited(windowId: number, flag: boolean): TPromise<void> {
return TPromise.wrap(this.channel.call('setDocumentEdited', [windowId, flag]));
return this.channel.call('setDocumentEdited', [windowId, flag]);
}

quit(): TPromise<void> {
return TPromise.wrap(this.channel.call('quit'));
return this.channel.call('quit');
}

relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise<void> {
return TPromise.wrap(this.channel.call('relaunch', [options]));
return this.channel.call('relaunch', [options]);
}

whenSharedProcessReady(): TPromise<void> {
return TPromise.wrap(this.channel.call('whenSharedProcessReady'));
return this.channel.call('whenSharedProcessReady');
}

toggleSharedProcess(): TPromise<void> {
return TPromise.wrap(this.channel.call('toggleSharedProcess'));
return this.channel.call('toggleSharedProcess');
}

openWindow(windowId: number, paths: URI[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean, forceOpenWorkspaceAsFile?: boolean, args?: ParsedArgs }): TPromise<void> {
return TPromise.wrap(this.channel.call('openWindow', [windowId, paths, options]));
return this.channel.call('openWindow', [windowId, paths, options]);
}

openNewWindow(options?: INewWindowOptions): TPromise<void> {
return this.channel.call('openNewWindow', options);
}

showWindow(windowId: number): TPromise<void> {
return TPromise.wrap(this.channel.call('showWindow', windowId));
return this.channel.call('showWindow', windowId);
}

getWindows(): TPromise<{ id: number; workspace?: IWorkspaceIdentifier; folderUri?: ISingleFolderWorkspaceIdentifier; title: string; filename?: string; }[]> {
return TPromise.wrap(this.channel.call<{ id: number; workspace?: IWorkspaceIdentifier; folderUri?: ISingleFolderWorkspaceIdentifier; title: string; filename?: string; }[]>('getWindows').then(result => { result.forEach(win => win.folderUri = win.folderUri ? URI.revive(win.folderUri) : win.folderUri); return result; }));
return this.channel.call<{ id: number; workspace?: IWorkspaceIdentifier; folderUri?: ISingleFolderWorkspaceIdentifier; title: string; filename?: string; }[]>('getWindows').then(result => { result.forEach(win => win.folderUri = win.folderUri ? URI.revive(win.folderUri) : win.folderUri); return result; });
}

getWindowCount(): TPromise<number> {
return TPromise.wrap(this.channel.call('getWindowCount'));
return this.channel.call('getWindowCount');
}

log(severity: string, ...messages: string[]): TPromise<void> {
return TPromise.wrap(this.channel.call('log', [severity, messages]));
return this.channel.call('log', [severity, messages]);
}

showItemInFolder(path: string): TPromise<void> {
return TPromise.wrap(this.channel.call('showItemInFolder', path));
return this.channel.call('showItemInFolder', path);
}

getActiveWindowId(): TPromise<number | undefined> {
return TPromise.wrap(this.channel.call('getActiveWindowId'));
return this.channel.call('getActiveWindowId');
}

openExternal(url: string): TPromise<boolean> {
return TPromise.wrap(this.channel.call('openExternal', url));
return this.channel.call('openExternal', url);
}

startCrashReporter(config: CrashReporterStartOptions): TPromise<void> {
return TPromise.wrap(this.channel.call('startCrashReporter', config));
return this.channel.call('startCrashReporter', config);
}

updateTouchBar(windowId: number, items: ISerializableCommandAction[][]): TPromise<void> {
return TPromise.wrap(this.channel.call('updateTouchBar', [windowId, items]));
return this.channel.call('updateTouchBar', [windowId, items]);
}

openAboutDialog(): TPromise<void> {
return TPromise.wrap(this.channel.call('openAboutDialog'));
return this.channel.call('openAboutDialog');
}

resolveProxy(windowId: number, url: string): Promise<string | undefined> {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/workspaces/node/workspacesIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ export class WorkspacesChannelClient implements IWorkspacesService {
constructor(private channel: IChannel) { }

createWorkspace(folders?: IWorkspaceFolderCreationData[]): TPromise<IWorkspaceIdentifier> {
return TPromise.wrap(this.channel.call('createWorkspace', folders));
return this.channel.call('createWorkspace', folders);
}
}
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/parts/editor/editorControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class EditorControl extends Disposable {

// Call into editor control
const editorWillChange = !inputMatches;
return TPromise.wrap(control.setInput(editor, options, operation.token)).then(() => {
return control.setInput(editor, options, operation.token).then(() => {

// Focus (unless prevented or another operation is running)
if (operation.isCurrent()) {
Expand Down
Loading

0 comments on commit d6b26a5

Please sign in to comment.