Skip to content

Commit 45856f0

Browse files
author
Benjamin Pasero
committed
debt - windows => windowsMainService
1 parent 1602957 commit 45856f0

4 files changed

Lines changed: 33 additions & 33 deletions

File tree

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

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

66
import { app, ipcMain as ipc, systemPreferences, shell, Event, contentTracing, protocol, powerMonitor, Event as IpcMainEvent, BrowserWindow } from 'electron';
77
import { IProcessEnvironment, isWindows, isMacintosh } from 'vs/base/common/platform';
8-
import { WindowsManager } from 'vs/code/electron-main/windows';
8+
import { WindowsMainService } from 'vs/platform/windows/electron-main/windowsMainService';
99
import { OpenContext, IWindowOpenable } from 'vs/platform/windows/common/windows';
1010
import { ActiveWindowManager } from 'vs/code/node/activeWindowTracker';
1111
import { ILifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
@@ -449,7 +449,7 @@ export class CodeApplication extends Disposable {
449449
break;
450450
}
451451

452-
services.set(IWindowsMainService, new SyncDescriptor(WindowsManager, [machineId, this.userEnv]));
452+
services.set(IWindowsMainService, new SyncDescriptor(WindowsMainService, [machineId, this.userEnv]));
453453
services.set(IDialogMainService, new SyncDescriptor(DialogMainService));
454454
services.set(ISharedProcessMainService, new SyncDescriptor(SharedProcessMainService, [sharedProcess]));
455455
services.set(ILaunchMainService, new SyncDescriptor(LaunchMainService));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import * as assert from 'assert';
66
import * as os from 'os';
77
import * as path from 'vs/base/common/path';
88

9-
import { restoreWindowsState, getWindowsStateStoreData } from 'vs/code/electron-main/windowsStateStorage';
9+
import { restoreWindowsState, getWindowsStateStoreData } from 'vs/platform/windows/electron-main/windowsStateStorage';
1010
import { IWindowState as IWindowUIState, WindowMode } from 'vs/platform/windows/electron-main/windows';
1111
import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
1212
import { URI } from 'vs/base/common/uri';
13-
import { IWindowsState, IWindowState } from 'vs/code/electron-main/windows';
13+
import { IWindowsState, IWindowState } from 'vs/platform/windows/electron-main/windowsMainService';
1414

1515
function getUIState(): IWindowUIState {
1616
return {
@@ -288,4 +288,4 @@ suite('Windows State Storing', () => {
288288

289289
});
290290

291-
});
291+
});

src/vs/code/electron-main/windows.ts renamed to src/vs/platform/windows/electron-main/windowsMainService.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { Schemas } from 'vs/base/common/network';
3131
import { URI } from 'vs/base/common/uri';
3232
import { getComparisonKey, isEqual, normalizePath, originalFSPath, hasTrailingPathSeparator, removeTrailingPathSeparator } from 'vs/base/common/resources';
3333
import { getRemoteAuthority } from 'vs/platform/remote/common/remoteHosts';
34-
import { restoreWindowsState, WindowsStateStorageData, getWindowsStateStoreData } from 'vs/code/electron-main/windowsStateStorage';
34+
import { restoreWindowsState, WindowsStateStorageData, getWindowsStateStoreData } from 'vs/platform/windows/electron-main/windowsStateStorage';
3535
import { getWorkspaceIdentifier, IWorkspacesMainService } from 'vs/platform/workspaces/electron-main/workspacesMainService';
3636
import { once } from 'vs/base/common/functional';
3737
import { Disposable } from 'vs/base/common/lifecycle';
@@ -149,7 +149,7 @@ interface IWorkspacePathToOpen {
149149
label?: string;
150150
}
151151

152-
export class WindowsManager extends Disposable implements IWindowsMainService {
152+
export class WindowsMainService extends Disposable implements IWindowsMainService {
153153

154154
_serviceBrand: undefined;
155155

@@ -185,7 +185,7 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
185185
) {
186186
super();
187187

188-
this.windowsState = restoreWindowsState(this.stateService.getItem<WindowsStateStorageData>(WindowsManager.windowsStateStorageKey));
188+
this.windowsState = restoreWindowsState(this.stateService.getItem<WindowsStateStorageData>(WindowsMainService.windowsStateStorageKey));
189189
if (!Array.isArray(this.windowsState.openedWindows)) {
190190
this.windowsState.openedWindows = [];
191191
}
@@ -299,7 +299,7 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
299299
if (!currentWindowsState.lastActiveWindow) {
300300
let activeWindow = this.getLastActiveWindow();
301301
if (!activeWindow || activeWindow.isExtensionDevelopmentHost) {
302-
activeWindow = WindowsManager.WINDOWS.filter(window => !window.isExtensionDevelopmentHost)[0];
302+
activeWindow = WindowsMainService.WINDOWS.filter(window => !window.isExtensionDevelopmentHost)[0];
303303
}
304304

305305
if (activeWindow) {
@@ -308,7 +308,7 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
308308
}
309309

310310
// 2.) Find extension host window
311-
const extensionHostWindow = WindowsManager.WINDOWS.filter(window => window.isExtensionDevelopmentHost && !window.isExtensionTestHost)[0];
311+
const extensionHostWindow = WindowsMainService.WINDOWS.filter(window => window.isExtensionDevelopmentHost && !window.isExtensionTestHost)[0];
312312
if (extensionHostWindow) {
313313
currentWindowsState.lastPluginDevelopmentHostWindow = this.toWindowState(extensionHostWindow);
314314
}
@@ -319,11 +319,11 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
319319
// so if we ever want to persist the UI state of the last closed window (window count === 1), it has
320320
// to come from the stored lastClosedWindowState on Win/Linux at least
321321
if (this.getWindowCount() > 1) {
322-
currentWindowsState.openedWindows = WindowsManager.WINDOWS.filter(window => !window.isExtensionDevelopmentHost).map(window => this.toWindowState(window));
322+
currentWindowsState.openedWindows = WindowsMainService.WINDOWS.filter(window => !window.isExtensionDevelopmentHost).map(window => this.toWindowState(window));
323323
}
324324

325325
// Persist
326-
this.stateService.setItem(WindowsManager.windowsStateStorageKey, getWindowsStateStoreData(currentWindowsState));
326+
this.stateService.setItem(WindowsMainService.windowsStateStorageKey, getWindowsStateStoreData(currentWindowsState));
327327
}
328328

329329
// See note on #onBeforeShutdown() for details how these events are flowing
@@ -546,7 +546,7 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
546546
const fileToCheck = fileInputs.filesToOpenOrCreate[0] || fileInputs.filesToDiff[0];
547547

548548
// only look at the windows with correct authority
549-
const windows = WindowsManager.WINDOWS.filter(window => window.remoteAuthority === fileInputs!.remoteAuthority);
549+
const windows = WindowsMainService.WINDOWS.filter(window => window.remoteAuthority === fileInputs!.remoteAuthority);
550550

551551
const bestWindowOrFolder = findBestWindowOrFolderForFile({
552552
windows,
@@ -602,7 +602,7 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
602602
if (allWorkspacesToOpen.length > 0) {
603603

604604
// Check for existing instances
605-
const windowsOnWorkspace = arrays.coalesce(allWorkspacesToOpen.map(workspaceToOpen => findWindowOnWorkspace(WindowsManager.WINDOWS, workspaceToOpen.workspace)));
605+
const windowsOnWorkspace = arrays.coalesce(allWorkspacesToOpen.map(workspaceToOpen => findWindowOnWorkspace(WindowsMainService.WINDOWS, workspaceToOpen.workspace)));
606606
if (windowsOnWorkspace.length > 0) {
607607
const windowOnWorkspace = windowsOnWorkspace[0];
608608
const fileInputsForWindow = (fileInputs && fileInputs.remoteAuthority === windowOnWorkspace.remoteAuthority) ? fileInputs : undefined;
@@ -644,7 +644,7 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
644644
if (allFoldersToOpen.length > 0) {
645645

646646
// Check for existing instances
647-
const windowsOnFolderPath = arrays.coalesce(allFoldersToOpen.map(folderToOpen => findWindowOnWorkspace(WindowsManager.WINDOWS, folderToOpen.folderUri)));
647+
const windowsOnFolderPath = arrays.coalesce(allFoldersToOpen.map(folderToOpen => findWindowOnWorkspace(WindowsMainService.WINDOWS, folderToOpen.folderUri)));
648648
if (windowsOnFolderPath.length > 0) {
649649
const windowOnFolderPath = windowsOnFolderPath[0];
650650
const fileInputsForWindow = fileInputs && fileInputs.remoteAuthority === windowOnFolderPath.remoteAuthority ? fileInputs : undefined;
@@ -1216,7 +1216,7 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
12161216
// Reload an existing extension development host window on the same path
12171217
// We currently do not allow more than one extension development window
12181218
// on the same extension path.
1219-
const existingWindow = findWindowOnExtensionDevelopmentPath(WindowsManager.WINDOWS, extensionDevelopmentPath);
1219+
const existingWindow = findWindowOnExtensionDevelopmentPath(WindowsMainService.WINDOWS, extensionDevelopmentPath);
12201220
if (existingWindow) {
12211221
this.reload(existingWindow, openConfig.cli);
12221222
existingWindow.focus(); // make sure it gets focus and is restored
@@ -1270,23 +1270,23 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
12701270

12711271
cliArgs = cliArgs.filter(path => {
12721272
const uri = URI.file(path);
1273-
if (!!findWindowOnWorkspaceOrFolderUri(WindowsManager.WINDOWS, uri)) {
1273+
if (!!findWindowOnWorkspaceOrFolderUri(WindowsMainService.WINDOWS, uri)) {
12741274
return false;
12751275
}
12761276
return uri.authority === authority;
12771277
});
12781278

12791279
folderUris = folderUris.filter(uri => {
12801280
const u = this.argToUri(uri);
1281-
if (!!findWindowOnWorkspaceOrFolderUri(WindowsManager.WINDOWS, u)) {
1281+
if (!!findWindowOnWorkspaceOrFolderUri(WindowsMainService.WINDOWS, u)) {
12821282
return false;
12831283
}
12841284
return u ? u.authority === authority : false;
12851285
});
12861286

12871287
fileUris = fileUris.filter(uri => {
12881288
const u = this.argToUri(uri);
1289-
if (!!findWindowOnWorkspaceOrFolderUri(WindowsManager.WINDOWS, u)) {
1289+
if (!!findWindowOnWorkspaceOrFolderUri(WindowsMainService.WINDOWS, u)) {
12901290
return false;
12911291
}
12921292
return u ? u.authority === authority : false;
@@ -1390,10 +1390,10 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
13901390
}
13911391

13921392
// Add to our list of windows
1393-
WindowsManager.WINDOWS.push(window);
1393+
WindowsMainService.WINDOWS.push(window);
13941394

13951395
// Indicate number change via event
1396-
this._onWindowsCountChanged.fire({ oldCount: WindowsManager.WINDOWS.length - 1, newCount: WindowsManager.WINDOWS.length });
1396+
this._onWindowsCountChanged.fire({ oldCount: WindowsMainService.WINDOWS.length - 1, newCount: WindowsMainService.WINDOWS.length });
13971397

13981398
// Window Events
13991399
once(window.onClose)(() => this.onWindowClosed(window!));
@@ -1570,14 +1570,14 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
15701570
}
15711571

15721572
private ensureNoOverlap(state: ISingleWindowState): ISingleWindowState {
1573-
if (WindowsManager.WINDOWS.length === 0) {
1573+
if (WindowsMainService.WINDOWS.length === 0) {
15741574
return state;
15751575
}
15761576

15771577
state.x = typeof state.x === 'number' ? state.x : 0;
15781578
state.y = typeof state.y === 'number' ? state.y : 0;
15791579

1580-
const existingWindowBounds = WindowsManager.WINDOWS.map(win => win.getBounds());
1580+
const existingWindowBounds = WindowsMainService.WINDOWS.map(win => win.getBounds());
15811581
while (existingWindowBounds.some(b => b.x === state.x || b.y === state.y)) {
15821582
state.x += 30;
15831583
state.y += 30;
@@ -1616,11 +1616,11 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
16161616
}
16171617

16181618
getLastActiveWindow(): ICodeWindow | undefined {
1619-
return getLastActiveWindow(WindowsManager.WINDOWS);
1619+
return getLastActiveWindow(WindowsMainService.WINDOWS);
16201620
}
16211621

16221622
private getLastActiveWindowForAuthority(remoteAuthority: string | undefined): ICodeWindow | undefined {
1623-
return getLastActiveWindow(WindowsManager.WINDOWS.filter(window => window.remoteAuthority === remoteAuthority));
1623+
return getLastActiveWindow(WindowsMainService.WINDOWS.filter(window => window.remoteAuthority === remoteAuthority));
16241624
}
16251625

16261626
openEmptyWindow(context: OpenContext, options?: IOpenEmptyWindowOptions): ICodeWindow[] {
@@ -1645,7 +1645,7 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
16451645
}
16461646

16471647
sendToAll(channel: string, payload?: any, windowIdsToIgnore?: number[]): void {
1648-
for (const window of WindowsManager.WINDOWS) {
1648+
for (const window of WindowsMainService.WINDOWS) {
16491649
if (windowIdsToIgnore && windowIdsToIgnore.indexOf(window.id) >= 0) {
16501650
continue; // do not send if we are instructed to ignore it
16511651
}
@@ -1664,26 +1664,26 @@ export class WindowsManager extends Disposable implements IWindowsMainService {
16641664
}
16651665

16661666
getWindowById(windowId: number): ICodeWindow | undefined {
1667-
const res = WindowsManager.WINDOWS.filter(window => window.id === windowId);
1667+
const res = WindowsMainService.WINDOWS.filter(window => window.id === windowId);
16681668
return arrays.firstOrDefault(res);
16691669
}
16701670

16711671
getWindows(): ICodeWindow[] {
1672-
return WindowsManager.WINDOWS;
1672+
return WindowsMainService.WINDOWS;
16731673
}
16741674

16751675
getWindowCount(): number {
1676-
return WindowsManager.WINDOWS.length;
1676+
return WindowsMainService.WINDOWS.length;
16771677
}
16781678

16791679
private onWindowClosed(win: ICodeWindow): void {
16801680

16811681
// Remove from our list so that Electron can clean it up
1682-
const index = WindowsManager.WINDOWS.indexOf(win);
1683-
WindowsManager.WINDOWS.splice(index, 1);
1682+
const index = WindowsMainService.WINDOWS.indexOf(win);
1683+
WindowsMainService.WINDOWS.splice(index, 1);
16841684

16851685
// Emit
1686-
this._onWindowsCountChanged.fire({ oldCount: WindowsManager.WINDOWS.length + 1, newCount: WindowsManager.WINDOWS.length });
1686+
this._onWindowsCountChanged.fire({ oldCount: WindowsMainService.WINDOWS.length + 1, newCount: WindowsMainService.WINDOWS.length });
16871687
this._onWindowClose.fire(win.id);
16881688
}
16891689

src/vs/code/electron-main/windowsStateStorage.ts renamed to src/vs/platform/windows/electron-main/windowsStateStorage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { URI, UriComponents } from 'vs/base/common/uri';
77
import { IWindowState as IWindowUIState } from 'vs/platform/windows/electron-main/windows';
8-
import { IWindowState, IWindowsState } from 'vs/code/electron-main/windows';
8+
import { IWindowState, IWindowsState } from 'vs/platform/windows/electron-main/windowsMainService';
99

1010
export type WindowsStateStorageData = object;
1111

0 commit comments

Comments
 (0)