windowsIpc.ts 6.6 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

J
Joao Moreno 已提交
6
import { Event } from 'vs/base/common/event';
7
import { IServerChannel } from 'vs/base/parts/ipc/common/ipc';
M
Martin Aeschlimann 已提交
8
import { IWindowsService, IURIToOpen, IOpenSettings, isWorkspaceToOpen, isFolderToOpen } from 'vs/platform/windows/common/windows';
9
import { reviveWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
J
Joao Moreno 已提交
10
import { URI } from 'vs/base/common/uri';
11
import { IRecent, isRecentFile, isRecentFolder } from 'vs/platform/history/common/history';
J
Joao Moreno 已提交
12

J
Joao Moreno 已提交
13
export class WindowsChannel implements IServerChannel {
J
Joao Moreno 已提交
14

15 16 17 18 19 20
	private readonly onWindowOpen: Event<number>;
	private readonly onWindowFocus: Event<number>;
	private readonly onWindowBlur: Event<number>;
	private readonly onWindowMaximize: Event<number>;
	private readonly onWindowUnmaximize: Event<number>;
	private readonly onRecentlyOpenedChange: Event<void>;
J
Joao Moreno 已提交
21

22
	constructor(private readonly service: IWindowsService) {
J
Joao Moreno 已提交
23 24 25 26 27 28
		this.onWindowOpen = Event.buffer(service.onWindowOpen, true);
		this.onWindowFocus = Event.buffer(service.onWindowFocus, true);
		this.onWindowBlur = Event.buffer(service.onWindowBlur, true);
		this.onWindowMaximize = Event.buffer(service.onWindowMaximize, true);
		this.onWindowUnmaximize = Event.buffer(service.onWindowUnmaximize, true);
		this.onRecentlyOpenedChange = Event.buffer(service.onRecentlyOpenedChange, true);
J
Joao Moreno 已提交
29
	}
J
Joao Moreno 已提交
30

31
	listen(_: unknown, event: string): Event<any> {
J
Joao Moreno 已提交
32 33 34 35 36 37 38 39 40
		switch (event) {
			case 'onWindowOpen': return this.onWindowOpen;
			case 'onWindowFocus': return this.onWindowFocus;
			case 'onWindowBlur': return this.onWindowBlur;
			case 'onWindowMaximize': return this.onWindowMaximize;
			case 'onWindowUnmaximize': return this.onWindowUnmaximize;
			case 'onRecentlyOpenedChange': return this.onRecentlyOpenedChange;
		}

41
		throw new Error(`Event not found: ${event}`);
J
Joao Moreno 已提交
42 43
	}

44
	call(_: unknown, command: string, arg?: any): Promise<any> {
J
Joao Moreno 已提交
45
		switch (command) {
B
fix npe  
Benjamin Pasero 已提交
46 47 48
			case 'pickFileFolderAndOpen': return this.service.pickFileFolderAndOpen(arg);
			case 'pickFileAndOpen': return this.service.pickFileAndOpen(arg);
			case 'pickFolderAndOpen': return this.service.pickFolderAndOpen(arg);
49
			case 'pickWorkspaceAndOpen': return this.service.pickWorkspaceAndOpen(arg);
50 51 52
			case 'showMessageBox': return this.service.showMessageBox(arg[0], arg[1]);
			case 'showSaveDialog': return this.service.showSaveDialog(arg[0], arg[1]);
			case 'showOpenDialog': return this.service.showOpenDialog(arg[0], arg[1]);
53
			case 'reloadWindow': return this.service.reloadWindow(arg[0], arg[1]);
54
			case 'openDevTools': return this.service.openDevTools(arg[0], arg[1]);
J
Joao Moreno 已提交
55
			case 'toggleDevTools': return this.service.toggleDevTools(arg);
56
			case 'closeWorkspace': return this.service.closeWorkspace(arg);
M
Martin Aeschlimann 已提交
57
			case 'enterWorkspace': return this.service.enterWorkspace(arg[0], URI.revive(arg[1]));
J
Joao Moreno 已提交
58
			case 'toggleFullScreen': return this.service.toggleFullScreen(arg);
59
			case 'setRepresentedFilename': return this.service.setRepresentedFilename(arg[0], arg[1]);
M
Martin Aeschlimann 已提交
60 61 62 63 64 65 66
			case 'addRecentlyOpened': return this.service.addRecentlyOpened(arg.map((recent: IRecent) => {
				if (isRecentFile(recent)) {
					recent.fileUri = URI.revive(recent.fileUri);
				} else if (isRecentFolder(recent)) {
					recent.folderUri = URI.revive(recent.folderUri);
				} else {
					recent.workspace = reviveWorkspaceIdentifier(recent.workspace);
S
Sandeep Somavarapu 已提交
67
				}
M
Martin Aeschlimann 已提交
68 69 70
				return recent;
			}));
			case 'removeFromRecentlyOpened': return this.service.removeFromRecentlyOpened(arg.map(URI.revive));
B
Benjamin Pasero 已提交
71
			case 'clearRecentlyOpened': return this.service.clearRecentlyOpened();
72
			case 'newWindowTab': return this.service.newWindowTab();
73 74 75 76 77
			case 'showPreviousWindowTab': return this.service.showPreviousWindowTab();
			case 'showNextWindowTab': return this.service.showNextWindowTab();
			case 'moveWindowTabToNewWindow': return this.service.moveWindowTabToNewWindow();
			case 'mergeAllWindowTabs': return this.service.mergeAllWindowTabs();
			case 'toggleWindowTabsBar': return this.service.toggleWindowTabsBar();
78
			case 'updateTouchBar': return this.service.updateTouchBar(arg[0], arg[1]);
B
Benjamin Pasero 已提交
79
			case 'getRecentlyOpened': return this.service.getRecentlyOpened(arg);
J
Joao Moreno 已提交
80
			case 'focusWindow': return this.service.focusWindow(arg);
81
			case 'closeWindow': return this.service.closeWindow(arg);
82
			case 'isFocused': return this.service.isFocused(arg);
83 84 85
			case 'isMaximized': return this.service.isMaximized(arg);
			case 'maximizeWindow': return this.service.maximizeWindow(arg);
			case 'unmaximizeWindow': return this.service.unmaximizeWindow(arg);
86
			case 'minimizeWindow': return this.service.minimizeWindow(arg);
87
			case 'onWindowTitleDoubleClick': return this.service.onWindowTitleDoubleClick(arg);
J
Joao Moreno 已提交
88
			case 'setDocumentEdited': return this.service.setDocumentEdited(arg[0], arg[1]);
M
Martin Aeschlimann 已提交
89 90 91
			case 'openWindow': {
				const urisToOpen: IURIToOpen[] = arg[1];
				const options: IOpenSettings = arg[2];
M
Martin Aeschlimann 已提交
92 93 94 95 96 97 98 99 100
				urisToOpen.forEach(r => {
					if (isWorkspaceToOpen(r)) {
						r.workspaceUri = URI.revive(r.workspaceUri);
					} else if (isFolderToOpen(r)) {
						r.folderUri = URI.revive(r.folderUri);
					} else {
						r.fileUri = URI.revive(r.fileUri);
					}
				});
M
Martin Aeschlimann 已提交
101 102 103
				options.waitMarkerFileURI = options.waitMarkerFileURI && URI.revive(options.waitMarkerFileURI);
				return this.service.openWindow(arg[0], urisToOpen, options);
			}
M
Martin Aeschlimann 已提交
104
			case 'openNewWindow': return this.service.openNewWindow(arg);
105
			case 'openExtensionDevelopmentHostWindow': return this.service.openExtensionDevelopmentHostWindow(arg[0], arg[1]);
J
Joao Moreno 已提交
106
			case 'getWindows': return this.service.getWindows();
107
			case 'getWindowCount': return this.service.getWindowCount();
J
Johannes Rieken 已提交
108
			case 'relaunch': return this.service.relaunch(arg[0]);
109
			case 'whenSharedProcessReady': return this.service.whenSharedProcessReady();
110
			case 'toggleSharedProcess': return this.service.toggleSharedProcess();
111
			case 'quit': return this.service.quit();
J
Joao Moreno 已提交
112
			case 'log': return this.service.log(arg[0], arg[1]);
M
Martin Aeschlimann 已提交
113
			case 'showItemInFolder': return this.service.showItemInFolder(URI.revive(arg));
J
Joao Moreno 已提交
114
			case 'getActiveWindowId': return this.service.getActiveWindowId();
J
Joao Moreno 已提交
115
			case 'openExternal': return this.service.openExternal(arg);
116
			case 'startCrashReporter': return this.service.startCrashReporter(arg);
J
Joao Moreno 已提交
117
			case 'openAboutDialog': return this.service.openAboutDialog();
118
			case 'resolveProxy': return this.service.resolveProxy(arg[0], arg[1]);
J
Joao Moreno 已提交
119
		}
120 121

		throw new Error(`Call not found: ${command}`);
J
Joao Moreno 已提交
122
	}
123
}