Skip to content

Commit 21e5a94

Browse files
committed
proper window service: first steps
1 parent f993b7f commit 21e5a94

24 files changed

Lines changed: 240 additions & 69 deletions

File tree

src/vs/code/electron-main/launch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
'use strict';
77

8-
import { IWindowsService } from 'vs/code/electron-main/windows';
8+
import { IWindowsMainService } from 'vs/code/electron-main/windows';
99
import { VSCodeWindow } from 'vs/code/electron-main/window';
1010
import { TPromise } from 'vs/base/common/winjs.base';
1111
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
@@ -63,7 +63,7 @@ export class LaunchService implements ILaunchService {
6363

6464
constructor(
6565
@ILogService private logService: ILogService,
66-
@IWindowsService private windowsService: IWindowsService,
66+
@IWindowsMainService private windowsService: IWindowsMainService,
6767
@IURLService private urlService: IURLService
6868
) { }
6969

src/vs/code/electron-main/main.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import * as platform from 'vs/base/common/platform';
1212
import { parseMainProcessArgv, ParsedArgs } from 'vs/platform/environment/node/argv';
1313
import { mkdirp } from 'vs/base/node/pfs';
1414
import { validatePaths } from 'vs/code/electron-main/paths';
15-
import { IWindowsService, WindowsManager } from 'vs/code/electron-main/windows';
15+
import { IWindowsMainService, WindowsManager } from 'vs/code/electron-main/windows';
16+
import { IWindowsService } from 'vs/platform/windows/common/windows';
17+
import { WindowsChannel } from 'vs/platform/windows/common/windowsIpc';
18+
import { WindowsService } from 'vs/platform/windows/electron-main/windowsService';
1619
import { WindowEventChannel } from 'vs/code/common/windowsIpc';
1720
import { ILifecycleService, LifecycleService } from 'vs/code/electron-main/lifecycle';
1821
import { VSCodeMenu } from 'vs/code/electron-main/menus';
@@ -72,11 +75,11 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
7275
const instantiationService = accessor.get(IInstantiationService);
7376
const logService = accessor.get(ILogService);
7477
const environmentService = accessor.get(IEnvironmentService);
75-
const windowsService = accessor.get(IWindowsService);
78+
const windowsMainService = accessor.get(IWindowsMainService);
7679
const lifecycleService = accessor.get(ILifecycleService);
7780
const updateService = accessor.get(IUpdateService);
7881
const configurationService = accessor.get(IConfigurationService) as ConfigurationService<any>;
79-
const windowEventChannel = new WindowEventChannel(windowsService);
82+
const windowEventChannel = new WindowEventChannel(windowsMainService);
8083

8184
// We handle uncaught exceptions here to prevent electron from opening a dialog to the user
8285
process.on('uncaughtException', (err: any) => {
@@ -89,7 +92,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
8992
};
9093

9194
// handle on client side
92-
windowsService.sendToFocused('vscode:reportError', JSON.stringify(friendlyError));
95+
windowsMainService.sendToFocused('vscode:reportError', JSON.stringify(friendlyError));
9396
}
9497

9598
console.error('[uncaught exception in main]: ' + err);
@@ -130,6 +133,10 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
130133
const urlChannel = instantiationService.createInstance(URLChannel, urlService);
131134
electronIpcServer.registerChannel('url', urlChannel);
132135

136+
const windowsService = accessor.get(IWindowsService);
137+
const windowsChannel = new WindowsChannel(windowsService);
138+
electronIpcServer.registerChannel('windows', windowsChannel);
139+
133140
// Spawn shared process
134141
const initData = { args: environmentService.args };
135142
const options = {
@@ -190,7 +197,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
190197
lifecycleService.ready();
191198

192199
// Propagate to clients
193-
windowsService.ready(userEnv);
200+
windowsMainService.ready(userEnv);
194201

195202
// Install Menu
196203
const menu = instantiationService.createInstance(VSCodeMenu);
@@ -217,12 +224,12 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
217224
});
218225

219226
// Recent Folders
220-
const folders = windowsService.getRecentPathsList().folders;
227+
const folders = windowsMainService.getRecentPathsList().folders;
221228
if (folders.length > 0) {
222229
jumpList.push({
223230
type: 'custom',
224231
name: 'Recent Folders',
225-
items: windowsService.getRecentPathsList().folders.slice(0, 7 /* limit number of entries here */).map(folder => {
232+
items: windowsMainService.getRecentPathsList().folders.slice(0, 7 /* limit number of entries here */).map(folder => {
226233
return <Electron.JumpListItem>{
227234
type: 'task',
228235
title: getPathLabel(folder),
@@ -253,11 +260,11 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
253260

254261
// Open our first window
255262
if (environmentService.args['new-window'] && environmentService.args._.length === 0) {
256-
windowsService.open({ cli: environmentService.args, forceNewWindow: true, forceEmpty: true }); // new window if "-n" was used without paths
263+
windowsMainService.open({ cli: environmentService.args, forceNewWindow: true, forceEmpty: true }); // new window if "-n" was used without paths
257264
} else if (global.macOpenFiles && global.macOpenFiles.length && (!environmentService.args._ || !environmentService.args._.length)) {
258-
windowsService.open({ cli: environmentService.args, pathsToOpen: global.macOpenFiles }); // mac: open-file event received on startup
265+
windowsMainService.open({ cli: environmentService.args, pathsToOpen: global.macOpenFiles }); // mac: open-file event received on startup
259266
} else {
260-
windowsService.open({ cli: environmentService.args, forceNewWindow: environmentService.args['new-window'], diffMode: environmentService.args.diff }); // default: read paths from cli
267+
windowsMainService.open({ cli: environmentService.args, forceNewWindow: environmentService.args['new-window'], diffMode: environmentService.args.diff }); // default: read paths from cli
261268
}
262269
}
263270

@@ -445,7 +452,8 @@ function start(): void {
445452

446453
services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, args, process.execPath));
447454
services.set(ILogService, new SyncDescriptor(MainLogService));
448-
services.set(IWindowsService, new SyncDescriptor(WindowsManager));
455+
services.set(IWindowsMainService, new SyncDescriptor(WindowsManager));
456+
services.set(IWindowsService, new SyncDescriptor(WindowsService));
449457
services.set(ILifecycleService, new SyncDescriptor(LifecycleService));
450458
services.set(IStorageService, new SyncDescriptor(StorageService));
451459
services.set(IConfigurationService, new SyncDescriptor(ConfigurationService));

src/vs/code/electron-main/menus.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as platform from 'vs/base/common/platform';
1010
import * as arrays from 'vs/base/common/arrays';
1111
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1212
import { ipcMain as ipc, app, shell, dialog, Menu, MenuItem } from 'electron';
13-
import { IWindowsService } from 'vs/code/electron-main/windows';
13+
import { IWindowsMainService } from 'vs/code/electron-main/windows';
1414
import { IPath, VSCodeWindow } from 'vs/code/electron-main/window';
1515
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1616
import { IStorageService } from 'vs/code/electron-main/storage';
@@ -57,7 +57,7 @@ export class VSCodeMenu {
5757
@IStorageService private storageService: IStorageService,
5858
@IUpdateService private updateService: IUpdateService,
5959
@IConfigurationService private configurationService: IConfigurationService,
60-
@IWindowsService private windowsService: IWindowsService,
60+
@IWindowsMainService private windowsService: IWindowsMainService,
6161
@IEnvironmentService private environmentService: IEnvironmentService
6262
) {
6363
this.actionIdKeybindingRequests = [];

src/vs/code/electron-main/windows.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ const ReopenFoldersSetting = {
8686
NONE: 'none'
8787
};
8888

89-
export const IWindowsService = createDecorator<IWindowsService>('windowsService');
89+
export const IWindowsMainService = createDecorator<IWindowsMainService>('windowsMainService');
9090

91-
export interface IWindowsService {
91+
export interface IWindowsMainService {
9292
_serviceBrand: any;
9393

9494
// TODO make proper events
@@ -123,7 +123,7 @@ export interface IWindowsService {
123123
clearRecentPathsList(): void;
124124
}
125125

126-
export class WindowsManager implements IWindowsService, IWindowEventService {
126+
export class WindowsManager implements IWindowsMainService, IWindowEventService {
127127

128128
_serviceBrand: any;
129129

src/vs/platform/url/common/urlIpc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
99
import { IChannel, eventToCall, eventFromCall, Serializer, Deserializer } from 'vs/base/parts/ipc/common/ipc';
1010
import { IURLService } from './url';
1111
import Event, { filterEvent } from 'vs/base/common/event';
12-
import { IWindowsService } from 'vs/code/electron-main/windows';
12+
import { IWindowsMainService } from 'vs/code/electron-main/windows';
1313
import URI from 'vs/base/common/uri';
1414

1515
const URISerializer: Serializer<URI, any> = uri => uri.toJSON();
@@ -24,7 +24,7 @@ export class URLChannel implements IURLChannel {
2424

2525
constructor(
2626
private service: IURLService,
27-
@IWindowsService private windowsService: IWindowsService
27+
@IWindowsMainService private windowsService: IWindowsMainService
2828
) { }
2929

3030
call(command: string, arg?: any): TPromise<any> {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import { TPromise } from 'vs/base/common/winjs.base';
9+
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
10+
11+
export const IWindowsService = createDecorator<IWindowsService>('windowsService');
12+
13+
export interface IWindowsService {
14+
15+
_serviceBrand: any;
16+
17+
openFileFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void>;
18+
openFilePicker(windowId: number, forceNewWindow?: boolean): TPromise<void>;
19+
openFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void>;
20+
}
21+
22+
export const IWindowService = createDecorator<IWindowService>('windowService');
23+
24+
export interface IWindowService {
25+
26+
_serviceBrand: any;
27+
28+
openFileFolderPicker(forceNewWindow?: boolean): TPromise<void>;
29+
openFilePicker(forceNewWindow?: boolean): TPromise<void>;
30+
openFolderPicker(forceNewWindow?: boolean): TPromise<void>;
31+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import { TPromise } from 'vs/base/common/winjs.base';
9+
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
10+
import { IWindowsService } from './windows';
11+
12+
export interface IWindowsChannel extends IChannel {
13+
call(command: 'openFileFolderPicker', args: [number, boolean]): TPromise<void>;
14+
call(command: 'openFilePicker', args: [number, boolean]): TPromise<void>;
15+
call(command: 'openFolderPicker', args: [number, boolean]): TPromise<void>;
16+
call(command: string, arg?: any): TPromise<any>;
17+
}
18+
19+
export class WindowsChannel implements IWindowsChannel {
20+
21+
constructor(private service: IWindowsService) { }
22+
23+
call(command: string, arg?: any): TPromise<any> {
24+
switch (command) {
25+
case 'openFileFolderPicker': return this.service.openFileFolderPicker(arg[0], arg[1]);
26+
case 'openFilePicker': return this.service.openFilePicker(arg[0], arg[1]);
27+
case 'openFolderPicker': return this.service.openFolderPicker(arg[0], arg[1]);
28+
}
29+
}
30+
}
31+
32+
export class WindowsChannelClient implements IWindowsService {
33+
34+
_serviceBrand: any;
35+
36+
constructor(private channel: IWindowsChannel) { }
37+
38+
openFileFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void> {
39+
return this.channel.call('openFileFolderPicker', [windowId, forceNewWindow]);
40+
}
41+
42+
openFilePicker(windowId: number, forceNewWindow?: boolean): TPromise<void> {
43+
return this.channel.call('openFilePicker', [windowId, forceNewWindow]);
44+
}
45+
46+
openFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void> {
47+
return this.channel.call('openFolderPicker', [windowId, forceNewWindow]);
48+
}
49+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import { TPromise } from 'vs/base/common/winjs.base';
9+
import { IWindowService, IWindowsService } from 'vs/platform/windows/common/windows';
10+
11+
export class WindowService implements IWindowService {
12+
13+
_serviceBrand: any;
14+
15+
constructor(
16+
private windowId: number,
17+
@IWindowsService private windowsService: IWindowsService
18+
) { }
19+
20+
openFileFolderPicker(forceNewWindow?: boolean): TPromise<void> {
21+
return this.windowsService.openFileFolderPicker(this.windowId, forceNewWindow);
22+
}
23+
24+
openFilePicker(forceNewWindow?: boolean): TPromise<void> {
25+
return this.windowsService.openFilePicker(this.windowId, forceNewWindow);
26+
}
27+
28+
openFolderPicker(forceNewWindow?: boolean): TPromise<void> {
29+
return this.windowsService.openFolderPicker(this.windowId, forceNewWindow);
30+
}
31+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import { TPromise } from 'vs/base/common/winjs.base';
9+
import { IWindowsService } from 'vs/platform/windows/common/windows';
10+
11+
// TODO@Joao: remove this dependency, move all implementation to this class
12+
import { IWindowsMainService } from 'vs/code/electron-main/windows';
13+
14+
export class WindowsService implements IWindowsService {
15+
16+
_serviceBrand: any;
17+
18+
constructor(
19+
@IWindowsMainService private windowsMainService: IWindowsMainService
20+
) { }
21+
22+
openFileFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void> {
23+
this.windowsMainService.openFileFolderPicker(forceNewWindow);
24+
return TPromise.as(null);
25+
}
26+
27+
openFilePicker(windowId: number, forceNewWindow?: boolean): TPromise<void> {
28+
this.windowsMainService.openFilePicker(forceNewWindow);
29+
return TPromise.as(null);
30+
}
31+
32+
openFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void> {
33+
this.windowsMainService.openFolderPicker(forceNewWindow);
34+
return TPromise.as(null);
35+
}
36+
}

0 commit comments

Comments
 (0)