/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ 'use strict'; import { TPromise } from 'vs/base/common/winjs.base'; import Event, { buffer } from 'vs/base/common/event'; import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc'; import { IWindowsService } from './windows'; import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry'; export interface IWindowsChannel extends IChannel { call(command: 'event:onWindowOpen'): TPromise; call(command: 'event:onWindowFocus'): TPromise; call(command: 'pickFileFolderAndOpen', arg: [number, boolean, ITelemetryData]): TPromise; call(command: 'pickFileAndOpen', arg: [number, boolean, string, ITelemetryData]): TPromise; call(command: 'pickFolderAndOpen', arg: [number, boolean, ITelemetryData]): TPromise; call(command: 'pickFolder'): TPromise; call(command: 'reloadWindow', arg: number): TPromise; call(command: 'toggleDevTools', arg: number): TPromise; call(command: 'closeFolder', arg: number): TPromise; call(command: 'toggleFullScreen', arg: number): TPromise; call(command: 'setRepresentedFilename', arg: [number, string]): TPromise; call(command: 'addToRecentlyOpen', arg: { path: string, isFile?: boolean }[]): TPromise; call(command: 'removeFromRecentlyOpen', arg: string[]): TPromise; call(command: 'clearRecentPathsList'): TPromise; call(command: 'getRecentlyOpen', arg: number): TPromise<{ files: string[]; folders: string[]; }>; call(command: 'focusWindow', arg: number): TPromise; call(command: 'isFocused', arg: number): TPromise; call(command: 'isMaximized', arg: number): TPromise; call(command: 'maximizeWindow', arg: number): TPromise; call(command: 'unmaximizeWindow', arg: number): TPromise; call(command: 'onWindowTitleDoubleClick', arg: number): TPromise; call(command: 'setDocumentEdited', arg: [number, boolean]): TPromise; call(command: 'quit'): TPromise; call(command: 'openWindow', arg: [string[], { forceNewWindow?: boolean, forceReuseWindow?: boolean }]): TPromise; 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: 'relaunch', arg: { addArgs?: string[], removeArgs?: string[] }): TPromise; call(command: 'whenSharedProcessReady'): TPromise; call(command: 'toggleSharedProcess'): TPromise; call(command: 'log', arg: [string, string[]]): TPromise; call(command: 'closeExtensionHostWindow', arg: string[]): TPromise; call(command: 'showItemInFolder', arg: string): TPromise; call(command: 'openExternal', arg: string): TPromise; call(command: 'startCrashReporter', arg: Electron.CrashReporterStartOptions): TPromise; call(command: string, arg?: any): TPromise; } export class WindowsChannel implements IWindowsChannel { private onWindowOpen: Event; private onWindowFocus: Event; constructor(private service: IWindowsService) { this.onWindowOpen = buffer(service.onWindowOpen, true); this.onWindowFocus = buffer(service.onWindowFocus, true); } call(command: string, arg?: any): TPromise { switch (command) { case 'event:onWindowOpen': return eventToCall(this.onWindowOpen); case 'event:onWindowFocus': return eventToCall(this.onWindowFocus); case 'pickFileFolderAndOpen': return this.service.pickFileFolderAndOpen(arg[0], arg[1], arg[2]); case 'pickFileAndOpen': return this.service.pickFileAndOpen(arg[0], arg[1], arg[2], arg[3]); case 'pickFolderAndOpen': return this.service.pickFolderAndOpen(arg[0], arg[1], arg[2]); case 'pickFolder': return this.service.pickFolder(); case 'reloadWindow': return this.service.reloadWindow(arg); case 'openDevTools': return this.service.openDevTools(arg); case 'toggleDevTools': return this.service.toggleDevTools(arg); case 'closeFolder': return this.service.closeFolder(arg); case 'toggleFullScreen': return this.service.toggleFullScreen(arg); case 'setRepresentedFilename': return this.service.setRepresentedFilename(arg[0], arg[1]); case 'addToRecentlyOpen': return this.service.addToRecentlyOpen(arg); case 'removeFromRecentlyOpen': return this.service.removeFromRecentlyOpen(arg); case 'clearRecentPathsList': return this.service.clearRecentPathsList(); case 'getRecentlyOpen': return this.service.getRecentlyOpen(arg); case 'focusWindow': return this.service.focusWindow(arg); case 'isFocused': return this.service.isFocused(arg); case 'isMaximized': return this.service.isMaximized(arg); case 'maximizeWindow': return this.service.maximizeWindow(arg); case 'unmaximizeWindow': return this.service.unmaximizeWindow(arg); case 'onWindowTitleDoubleClick': return this.service.onWindowTitleDoubleClick(arg); case 'setDocumentEdited': return this.service.setDocumentEdited(arg[0], arg[1]); case 'openWindow': return this.service.openWindow(arg[0], arg[1]); 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 'relaunch': return this.service.relaunch(arg[0]); case 'whenSharedProcessReady': return this.service.whenSharedProcessReady(); case 'toggleSharedProcess': return this.service.toggleSharedProcess(); case 'quit': return this.service.quit(); case 'log': return this.service.log(arg[0], arg[1]); case 'closeExtensionHostWindow': return this.service.closeExtensionHostWindow(arg); case 'showItemInFolder': return this.service.showItemInFolder(arg); case 'openExternal': return this.service.openExternal(arg); case 'startCrashReporter': return this.service.startCrashReporter(arg); } return undefined; } } export class WindowsChannelClient implements IWindowsService { _serviceBrand: any; constructor(private channel: IWindowsChannel) { } private _onWindowOpen: Event = eventFromCall(this.channel, 'event:onWindowOpen'); get onWindowOpen(): Event { return this._onWindowOpen; } private _onWindowFocus: Event = eventFromCall(this.channel, 'event:onWindowFocus'); get onWindowFocus(): Event { return this._onWindowFocus; } pickFileFolderAndOpen(windowId: number, forceNewWindow?: boolean, data?: ITelemetryData): TPromise { return this.channel.call('pickFileFolderAndOpen', [windowId, forceNewWindow, data]); } pickFileAndOpen(windowId: number, forceNewWindow?: boolean, path?: string, data?: ITelemetryData): TPromise { return this.channel.call('pickFileAndOpen', [windowId, forceNewWindow, path, data]); } pickFolderAndOpen(windowId: number, forceNewWindow?: boolean, data?: ITelemetryData): TPromise { return this.channel.call('pickFolderAndOpen', [windowId, forceNewWindow, data]); } pickFolder(): TPromise { return this.channel.call('pickFolder'); } reloadWindow(windowId: number): TPromise { return this.channel.call('reloadWindow', windowId); } openDevTools(windowId: number): TPromise { return this.channel.call('openDevTools', windowId); } toggleDevTools(windowId: number): TPromise { return this.channel.call('toggleDevTools', windowId); } closeFolder(windowId: number): TPromise { return this.channel.call('closeFolder', windowId); } toggleFullScreen(windowId: number): TPromise { return this.channel.call('toggleFullScreen', windowId); } setRepresentedFilename(windowId: number, fileName: string): TPromise { return this.channel.call('setRepresentedFilename', [windowId, fileName]); } addToRecentlyOpen(paths: { path: string, isFile?: boolean }[]): TPromise { return this.channel.call('addToRecentlyOpen', paths); } removeFromRecentlyOpen(paths: string[]): TPromise { return this.channel.call('removeFromRecentlyOpen', paths); } clearRecentPathsList(): TPromise { return this.channel.call('clearRecentPathsList'); } getRecentlyOpen(windowId: number): TPromise<{ files: string[]; folders: string[]; }> { return this.channel.call('getRecentlyOpen', windowId); } focusWindow(windowId: number): TPromise { return this.channel.call('focusWindow', windowId); } isFocused(windowId: number): TPromise { return this.channel.call('isFocused', windowId); } isMaximized(windowId: number): TPromise { return this.channel.call('isMaximized', windowId); } maximizeWindow(windowId: number): TPromise { return this.channel.call('maximizeWindow', windowId); } unmaximizeWindow(windowId: number): TPromise { return this.channel.call('unmaximizeWindow', windowId); } onWindowTitleDoubleClick(windowId: number): TPromise { return this.channel.call('onWindowTitleDoubleClick', windowId); } setDocumentEdited(windowId: number, flag: boolean): TPromise { return this.channel.call('setDocumentEdited', [windowId, flag]); } quit(): TPromise { return this.channel.call('quit'); } relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise { return this.channel.call('relaunch', [options]); } whenSharedProcessReady(): TPromise { return this.channel.call('whenSharedProcessReady'); } toggleSharedProcess(): TPromise { return this.channel.call('toggleSharedProcess'); } openWindow(paths: string[], options?: { forceNewWindow?: boolean, forceReuseWindow?: boolean }): TPromise { return this.channel.call('openWindow', [paths, options]); } openNewWindow(): TPromise { return this.channel.call('openNewWindow'); } showWindow(windowId: number): TPromise { return this.channel.call('showWindow', windowId); } getWindows(): TPromise<{ id: number; path: string; title: string; }[]> { 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]); } closeExtensionHostWindow(extensionDevelopmentPaths: string[]): TPromise { return this.channel.call('closeExtensionHostWindow', extensionDevelopmentPaths); } showItemInFolder(path: string): TPromise { return this.channel.call('showItemInFolder', path); } openExternal(url: string): TPromise { return this.channel.call('openExternal', url); } startCrashReporter(config: Electron.CrashReporterStartOptions): TPromise { return this.channel.call('startCrashReporter', config); } }