Skip to content

Commit 2937cb0

Browse files
author
Benjamin Pasero
committed
debt - introduce and use workbench environment service
1 parent ddd47f9 commit 2937cb0

54 files changed

Lines changed: 260 additions & 241 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/vs/platform/driver/electron-browser/driver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ export async function registerWindowDriver(accessor: ServicesAccessor): Promise<
226226
const windowDriverRegistryChannel = mainProcessService.getChannel('windowDriverRegistry');
227227
const windowDriverRegistry = new WindowDriverRegistryChannelClient(windowDriverRegistryChannel);
228228

229-
await windowDriverRegistry.registerWindowDriver(windowService.getCurrentWindowId());
229+
await windowDriverRegistry.registerWindowDriver(windowService.windowId);
230230
// const options = await windowDriverRegistry.registerWindowDriver(windowId);
231231

232232
// if (options.verbose) {
233233
// windowDriver.openDevTools();
234234
// }
235235

236-
return toDisposable(() => windowDriverRegistry.reloadWindowDriver(windowService.getCurrentWindowId()));
236+
return toDisposable(() => windowDriverRegistry.reloadWindowDriver(windowService.windowId));
237237
}

src/vs/platform/ipc/electron-browser/sharedProcessService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class SharedProcessService implements ISharedProcessService {
3333
@IEnvironmentService environmentService: IEnvironmentService
3434
) {
3535
this.withSharedProcessConnection = windowsService.whenSharedProcessReady()
36-
.then(() => connect(environmentService.sharedIPCHandle, `window:${windowService.getCurrentWindowId()}`));
36+
.then(() => connect(environmentService.sharedIPCHandle, `window:${windowService.windowId}`));
3737
}
3838

3939
getChannel(channelName: string): IChannel {

src/vs/platform/lifecycle/electron-browser/lifecycleService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class LifecycleService extends AbstractLifecycleService {
5353
}
5454

5555
private registerListeners(): void {
56-
const windowId = this.windowService.getCurrentWindowId();
56+
const windowId = this.windowService.windowId;
5757

5858
// Main side indicates that window is about to unload, check for vetos
5959
ipc.on('vscode:onBeforeUnload', (_event: unknown, reply: { okChannel: string, cancelChannel: string, reason: ShutdownReason }) => {

src/vs/platform/windows/common/windows.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ export interface IWindowService {
226226

227227
readonly hasFocus: boolean;
228228

229-
getConfiguration(): IWindowConfiguration;
230-
getCurrentWindowId(): number;
229+
readonly windowId: number;
230+
231231
pickFileFolderAndOpen(options: INativeOpenDialogOptions): Promise<void>;
232232
pickFileAndOpen(options: INativeOpenDialogOptions): Promise<void>;
233233
pickFolderAndOpen(options: INativeOpenDialogOptions): Promise<void>;

src/vs/workbench/browser/actions/workspaceActions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ADD_ROOT_FOLDER_COMMAND_ID, ADD_ROOT_FOLDER_LABEL, PICK_WORKSPACE_FOLDE
1616
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
1717
import { INotificationService } from 'vs/platform/notification/common/notification';
1818
import { Schemas } from 'vs/base/common/network';
19+
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1920

2021
export class OpenFileAction extends Action {
2122

@@ -289,14 +290,15 @@ export class DuplicateWorkspaceInNewWindowAction extends Action {
289290
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
290291
@IWorkspaceEditingService private readonly workspaceEditingService: IWorkspaceEditingService,
291292
@IWindowService private readonly windowService: IWindowService,
292-
@IWorkspacesService private readonly workspacesService: IWorkspacesService
293+
@IWorkspacesService private readonly workspacesService: IWorkspacesService,
294+
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService
293295
) {
294296
super(id, label);
295297
}
296298

297299
run(): Promise<any> {
298300
const folders = this.workspaceContextService.getWorkspace().folders;
299-
const remoteAuthority = this.windowService.getConfiguration().remoteAuthority;
301+
const remoteAuthority = this.environmentService.configuration.remoteAuthority;
300302

301303
return this.workspacesService.createUntitledWorkspace(folders, remoteAuthority).then(newWorkspace => {
302304
return this.workspaceEditingService.copyWorkspaceSettings(newWorkspace).then(() => {

src/vs/workbench/browser/contextkeys.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { Event } from 'vs/base/common/event';
77
import { Disposable } from 'vs/base/common/lifecycle';
88
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
99
import { InputFocusedContext } from 'vs/platform/contextkey/common/contextkeys';
10-
import { IWindowService, IWindowsConfiguration } from 'vs/platform/windows/common/windows';
10+
import { IWindowsConfiguration } from 'vs/platform/windows/common/windows';
1111
import { ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, TEXT_DIFF_EDITOR_ID, SplitEditorsVertically, InEditorZenModeContext } from 'vs/workbench/common/editor';
1212
import { IsMacContext, IsLinuxContext, IsWindowsContext, HasMacNativeTabsContext, IsDevelopmentContext, SupportsWorkspacesContext, SupportsOpenFileFolderContext, WorkbenchStateContext, WorkspaceFolderCountContext, IsRemoteContext } from 'vs/workbench/common/contextkeys';
1313
import { trackFocus, addDisposableListener, EventType } from 'vs/base/browser/dom';
1414
import { preferredSideBySideGroupDirection, GroupDirection, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
1515
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
16-
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
16+
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1717
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
1818
import { WorkbenchState, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
1919
import { SideBarVisibleContext } from 'vs/workbench/common/viewlet';
@@ -43,8 +43,7 @@ export class WorkbenchContextKeysHandler extends Disposable {
4343
@IContextKeyService private contextKeyService: IContextKeyService,
4444
@IWorkspaceContextService private contextService: IWorkspaceContextService,
4545
@IConfigurationService private configurationService: IConfigurationService,
46-
@IEnvironmentService private environmentService: IEnvironmentService,
47-
@IWindowService private windowService: IWindowService,
46+
@IWorkbenchEnvironmentService private environmentService: IWorkbenchEnvironmentService,
4847
@IEditorService private editorService: IEditorService,
4948
@IEditorGroupsService private editorGroupService: IEditorGroupsService,
5049
@IWorkbenchLayoutService private layoutService: IWorkbenchLayoutService,
@@ -88,7 +87,7 @@ export class WorkbenchContextKeysHandler extends Disposable {
8887
IsLinuxContext.bindTo(this.contextKeyService);
8988
IsWindowsContext.bindTo(this.contextKeyService);
9089

91-
IsRemoteContext.bindTo(this.contextKeyService).set(!!this.windowService.getConfiguration().remoteAuthority);
90+
IsRemoteContext.bindTo(this.contextKeyService).set(!!this.environmentService.configuration.remoteAuthority);
9291

9392
// macOS Native Tabs
9493
const windowConfig = this.configurationService.getValue<IWindowsConfiguration>();
@@ -99,7 +98,7 @@ export class WorkbenchContextKeysHandler extends Disposable {
9998

10099
// File Pickers
101100
SupportsWorkspacesContext.bindTo(this.contextKeyService);
102-
SupportsOpenFileFolderContext.bindTo(this.contextKeyService).set(!!this.windowService.getConfiguration().remoteAuthority);
101+
SupportsOpenFileFolderContext.bindTo(this.contextKeyService).set(!!this.environmentService.configuration.remoteAuthority);
103102

104103
// Editors
105104
this.activeEditorContext = ActiveEditorContext.bindTo(this.contextKeyService);

src/vs/workbench/browser/layout.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { ITitleService } from 'vs/workbench/services/title/common/titleService';
2525
import { IInstantiationService, ServicesAccessor, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
2626
import { LifecyclePhase, StartupKind, ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
2727
import { IWindowService, IPath, MenuBarVisibility, getTitleBarStyle } from 'vs/platform/windows/common/windows';
28-
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
28+
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
2929
import { IEditorService, IResourceEditor } from 'vs/workbench/services/editor/common/editorService';
3030
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
3131
import { Sizing, Direction, Grid, View } from 'vs/base/browser/ui/grid/grid';
@@ -89,7 +89,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
8989
private editorPartView: View;
9090
private statusBarPartView: View;
9191

92-
private environmentService: IEnvironmentService;
92+
private environmentService: IWorkbenchEnvironmentService;
9393
private configurationService: IConfigurationService;
9494
private lifecycleService: ILifecycleService;
9595
private storageService: IStorageService;
@@ -161,7 +161,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
161161
protected initLayout(accessor: ServicesAccessor): void {
162162

163163
// Services
164-
this.environmentService = accessor.get(IEnvironmentService);
164+
this.environmentService = accessor.get(IWorkbenchEnvironmentService);
165165
this.configurationService = accessor.get(IConfigurationService);
166166
this.lifecycleService = accessor.get(ILifecycleService);
167167
this.windowService = accessor.get(IWindowService);
@@ -389,7 +389,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
389389
}
390390

391391
private resolveEditorsToOpen(): Promise<IResourceEditor[]> | IResourceEditor[] {
392-
const configuration = this.windowService.getConfiguration();
392+
const configuration = this.environmentService.configuration;
393393
const hasInitialFilesToOpen = this.hasInitialFilesToOpen();
394394

395395
// Only restore editors if we are not instructed to open files initially
@@ -436,7 +436,7 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
436436
}
437437

438438
private hasInitialFilesToOpen(): boolean {
439-
const configuration = this.windowService.getConfiguration();
439+
const configuration = this.environmentService.configuration;
440440

441441
return !!(
442442
(configuration.filesToCreate && configuration.filesToCreate.length > 0) ||

src/vs/workbench/browser/nodeless.simpleservices.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
6161
import { Color, RGBA } from 'vs/base/common/color';
6262
import { IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEnvironment';
6363
import { IRemoteAgentService, IRemoteAgentConnection } from 'vs/workbench/services/remote/common/remoteAgentService';
64+
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
6465

6566
export const workspaceResource = URI.file(isWindows ? 'C:\\simpleWorkspace' : '/simpleWorkspace');
6667

@@ -225,7 +226,8 @@ registerSingleton(IDownloadService, SimpleDownloadService, true);
225226

226227
//#region Environment
227228

228-
export class SimpleEnvironmentService implements IEnvironmentService {
229+
export class SimpleEnvironmentService implements IWorkbenchEnvironmentService {
230+
configuration: IWindowConfiguration = new SimpleWindowConfiguration();
229231
untitledWorkspacesHome: URI;
230232
extensionTestsLocationURI?: URI;
231233
_serviceBrand: any;
@@ -1382,7 +1384,7 @@ export class SimpleWindowService implements IWindowService {
13821384

13831385
hasFocus = true;
13841386

1385-
private configuration: IWindowConfiguration = new SimpleWindowConfiguration();
1387+
readonly windowId = 0;
13861388

13871389
isFocused(): Promise<boolean> {
13881390
return Promise.resolve(false);
@@ -1392,14 +1394,6 @@ export class SimpleWindowService implements IWindowService {
13921394
return Promise.resolve(false);
13931395
}
13941396

1395-
getConfiguration(): IWindowConfiguration {
1396-
return this.configuration;
1397-
}
1398-
1399-
getCurrentWindowId(): number {
1400-
return 0;
1401-
}
1402-
14031397
pickFileFolderAndOpen(_options: INativeOpenDialogOptions): Promise<void> {
14041398
return Promise.resolve();
14051399
}

src/vs/workbench/browser/parts/titlebar/menubarControl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export class MenubarControl extends Disposable {
307307
// Send menus to main process to be rendered by Electron
308308
const menubarData = { menus: {}, keybindings: {} };
309309
if (this.getMenubarMenus(menubarData)) {
310-
this.menubarService.updateMenubar(this.windowService.getCurrentWindowId(), menubarData);
310+
this.menubarService.updateMenubar(this.windowService.windowId, menubarData);
311311
}
312312
}
313313
}
@@ -435,7 +435,7 @@ export class MenubarControl extends Disposable {
435435
return null;
436436

437437
case StateType.Idle:
438-
const windowId = this.windowService.getCurrentWindowId();
438+
const windowId = this.windowService.windowId;
439439
return new Action('update.check', nls.localize({ key: 'checkForUpdates', comment: ['&& denotes a mnemonic'] }, "Check for &&Updates..."), undefined, true, () =>
440440
this.updateService.checkForUpdates({ windowId }));
441441

src/vs/workbench/browser/parts/titlebar/titlebarPart.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
1818
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
1919
import * as nls from 'vs/nls';
2020
import { EditorInput, toResource, Verbosity, SideBySideEditor } from 'vs/workbench/common/editor';
21-
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
21+
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
2222
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
2323
import { IThemeService, registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
2424
import { TITLE_BAR_ACTIVE_BACKGROUND, TITLE_BAR_ACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_FOREGROUND, TITLE_BAR_INACTIVE_BACKGROUND, TITLE_BAR_BORDER } from 'vs/workbench/common/theme';
@@ -85,7 +85,7 @@ export class TitlebarPart extends Part implements ITitleService {
8585
@IConfigurationService private readonly configurationService: IConfigurationService,
8686
@IWindowsService private readonly windowsService: IWindowsService,
8787
@IEditorService private readonly editorService: IEditorService,
88-
@IEnvironmentService private readonly environmentService: IEnvironmentService,
88+
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
8989
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
9090
@IInstantiationService private readonly instantiationService: IInstantiationService,
9191
@IThemeService themeService: IThemeService,
@@ -412,7 +412,7 @@ export class TitlebarPart extends Part implements ITitleService {
412412
// Resizer
413413
this.resizer = append(this.element, $('div.resizer'));
414414

415-
const isMaximized = this.windowService.getConfiguration().maximized ? true : false;
415+
const isMaximized = this.environmentService.configuration.maximized ? true : false;
416416
this.onDidChangeMaximized(isMaximized);
417417
this.windowService.onDidChangeMaximize(this.onDidChangeMaximized, this);
418418
}

0 commit comments

Comments
 (0)