/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { Event } from 'vs/base/common/event'; import { IChannel } from 'vs/base/parts/ipc/common/ipc'; import { IWindowsService, INativeOpenDialogOptions, IEnterWorkspaceResult, CrashReporterStartOptions, IMessageBoxResult, MessageBoxOptions, SaveDialogOptions, OpenDialogOptions, IDevToolsOptions, INewWindowOptions, IURIToOpen, IOpenSettings } from 'vs/platform/windows/common/windows'; import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, reviveWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces'; import { IRecentlyOpened, IRecent, isRecentWorkspace } from 'vs/platform/history/common/history'; import { ISerializableCommandAction } from 'vs/platform/actions/common/actions'; import { URI } from 'vs/base/common/uri'; import { ParsedArgs } from 'vs/platform/environment/common/environment'; import { IMainProcessService } from 'vs/platform/ipc/electron-browser/mainProcessService'; import { IProcessEnvironment } from 'vs/base/common/platform'; export class WindowsService implements IWindowsService { _serviceBrand: any; private channel: IChannel; constructor(@IMainProcessService mainProcessService: IMainProcessService) { this.channel = mainProcessService.getChannel('windows'); } get onWindowOpen(): Event { return this.channel.listen('onWindowOpen'); } get onWindowFocus(): Event { return this.channel.listen('onWindowFocus'); } get onWindowBlur(): Event { return this.channel.listen('onWindowBlur'); } get onWindowMaximize(): Event { return this.channel.listen('onWindowMaximize'); } get onWindowUnmaximize(): Event { return this.channel.listen('onWindowUnmaximize'); } get onRecentlyOpenedChange(): Event { return this.channel.listen('onRecentlyOpenedChange'); } pickFileFolderAndOpen(options: INativeOpenDialogOptions): Promise { return this.channel.call('pickFileFolderAndOpen', options); } pickFileAndOpen(options: INativeOpenDialogOptions): Promise { return this.channel.call('pickFileAndOpen', options); } pickFolderAndOpen(options: INativeOpenDialogOptions): Promise { return this.channel.call('pickFolderAndOpen', options); } pickWorkspaceAndOpen(options: INativeOpenDialogOptions): Promise { return this.channel.call('pickWorkspaceAndOpen', options); } showMessageBox(windowId: number, options: MessageBoxOptions): Promise { return this.channel.call('showMessageBox', [windowId, options]); } showSaveDialog(windowId: number, options: SaveDialogOptions): Promise { return this.channel.call('showSaveDialog', [windowId, options]); } showOpenDialog(windowId: number, options: OpenDialogOptions): Promise { return this.channel.call('showOpenDialog', [windowId, options]); } reloadWindow(windowId: number, args?: ParsedArgs): Promise { return this.channel.call('reloadWindow', [windowId, args]); } openDevTools(windowId: number, options?: IDevToolsOptions): Promise { return this.channel.call('openDevTools', [windowId, options]); } toggleDevTools(windowId: number): Promise { return this.channel.call('toggleDevTools', windowId); } closeWorkspace(windowId: number): Promise { return this.channel.call('closeWorkspace', windowId); } async enterWorkspace(windowId: number, path: URI): Promise { const result: IEnterWorkspaceResult = await this.channel.call('enterWorkspace', [windowId, path]); if (result) { result.workspace = reviveWorkspaceIdentifier(result.workspace); } return result; } toggleFullScreen(windowId: number): Promise { return this.channel.call('toggleFullScreen', windowId); } setRepresentedFilename(windowId: number, fileName: string): Promise { return this.channel.call('setRepresentedFilename', [windowId, fileName]); } addRecentlyOpened(recent: IRecent[]): Promise { return this.channel.call('addRecentlyOpened', recent); } removeFromRecentlyOpened(paths: Array): Promise { return this.channel.call('removeFromRecentlyOpened', paths); } clearRecentlyOpened(): Promise { return this.channel.call('clearRecentlyOpened'); } async getRecentlyOpened(windowId: number): Promise { const recentlyOpened: IRecentlyOpened = await this.channel.call('getRecentlyOpened', windowId); recentlyOpened.workspaces.forEach(recent => isRecentWorkspace(recent) ? recent.workspace = reviveWorkspaceIdentifier(recent.workspace) : recent.folderUri = URI.revive(recent.folderUri)); recentlyOpened.files.forEach(recent => recent.fileUri = URI.revive(recent.fileUri)); return recentlyOpened; } newWindowTab(): Promise { return this.channel.call('newWindowTab'); } showPreviousWindowTab(): Promise { return this.channel.call('showPreviousWindowTab'); } showNextWindowTab(): Promise { return this.channel.call('showNextWindowTab'); } moveWindowTabToNewWindow(): Promise { return this.channel.call('moveWindowTabToNewWindow'); } mergeAllWindowTabs(): Promise { return this.channel.call('mergeAllWindowTabs'); } toggleWindowTabsBar(): Promise { return this.channel.call('toggleWindowTabsBar'); } focusWindow(windowId: number): Promise { return this.channel.call('focusWindow', windowId); } closeWindow(windowId: number): Promise { return this.channel.call('closeWindow', windowId); } isFocused(windowId: number): Promise { return this.channel.call('isFocused', windowId); } isMaximized(windowId: number): Promise { return this.channel.call('isMaximized', windowId); } maximizeWindow(windowId: number): Promise { return this.channel.call('maximizeWindow', windowId); } unmaximizeWindow(windowId: number): Promise { return this.channel.call('unmaximizeWindow', windowId); } minimizeWindow(windowId: number): Promise { return this.channel.call('minimizeWindow', windowId); } onWindowTitleDoubleClick(windowId: number): Promise { return this.channel.call('onWindowTitleDoubleClick', windowId); } setDocumentEdited(windowId: number, flag: boolean): Promise { return this.channel.call('setDocumentEdited', [windowId, flag]); } quit(): Promise { return this.channel.call('quit'); } relaunch(options: { addArgs?: string[], removeArgs?: string[] }): Promise { return this.channel.call('relaunch', [options]); } whenSharedProcessReady(): Promise { return this.channel.call('whenSharedProcessReady'); } toggleSharedProcess(): Promise { return this.channel.call('toggleSharedProcess'); } openWindow(windowId: number, uris: IURIToOpen[], options: IOpenSettings): Promise { return this.channel.call('openWindow', [windowId, uris, options]); } openNewWindow(options?: INewWindowOptions): Promise { return this.channel.call('openNewWindow', options); } openExtensionDevelopmentHostWindow(args: ParsedArgs, env: IProcessEnvironment): Promise { return this.channel.call('openExtensionDevelopmentHostWindow', [args, env]); } async getWindows(): Promise<{ id: number; workspace?: IWorkspaceIdentifier; folderUri?: ISingleFolderWorkspaceIdentifier; title: string; filename?: string; }[]> { const result = await this.channel.call<{ id: number; workspace?: IWorkspaceIdentifier; folderUri?: ISingleFolderWorkspaceIdentifier; title: string; filename?: string; }[]>('getWindows'); for (const win of result) { if (win.folderUri) { win.folderUri = URI.revive(win.folderUri); } if (win.workspace) { win.workspace = reviveWorkspaceIdentifier(win.workspace); } } return result; } getWindowCount(): Promise { return this.channel.call('getWindowCount'); } log(severity: string, ...messages: string[]): Promise { return this.channel.call('log', [severity, messages]); } showItemInFolder(path: URI): Promise { return this.channel.call('showItemInFolder', path); } getActiveWindowId(): Promise { return this.channel.call('getActiveWindowId'); } openExternal(url: string): Promise { return this.channel.call('openExternal', url); } startCrashReporter(config: CrashReporterStartOptions): Promise { return this.channel.call('startCrashReporter', config); } updateTouchBar(windowId: number, items: ISerializableCommandAction[][]): Promise { return this.channel.call('updateTouchBar', [windowId, items]); } openAboutDialog(): Promise { return this.channel.call('openAboutDialog'); } resolveProxy(windowId: number, url: string): Promise { return Promise.resolve(this.channel.call('resolveProxy', [windowId, url])); } }