window - create a proper window config

This commit is contained in:
Benjamin Pasero 2021-04-07 08:40:53 +02:00
parent 04b6291eed
commit 28a55539bb
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
2 changed files with 53 additions and 61 deletions

View file

@ -3,14 +3,12 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { release } from 'os';
import product from 'vs/platform/product/common/product';
import { join } from 'vs/base/common/path';
import { localize } from 'vs/nls';
import { getMarks, mark } from 'vs/base/common/performance';
import { Emitter } from 'vs/base/common/event';
import { URI } from 'vs/base/common/uri';
import { screen, BrowserWindow, systemPreferences, app, TouchBar, nativeImage, Rectangle, Display, TouchBarSegmentedControl, NativeImage, BrowserWindowConstructorOptions, SegmentedControlSegment, nativeTheme, Event, RenderProcessGoneDetails } from 'electron';
import { screen, BrowserWindow, systemPreferences, app, TouchBar, nativeImage, Rectangle, Display, TouchBarSegmentedControl, NativeImage, BrowserWindowConstructorOptions, SegmentedControlSegment, Event, RenderProcessGoneDetails } from 'electron';
import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService';
import { ILogService } from 'vs/platform/log/common/log';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@ -836,47 +834,17 @@ export class CodeWindow extends Disposable implements ICodeWindow {
configuration['disable-extensions'] = options.disableExtensions;
}
// Set window ID
// Update window identifier and session
configuration.windowId = this._win.id;
configuration.sessionId = `window:${this._win.id}`;
configuration.logLevel = this.logService.getLevel();
configuration.logsPath = this.environmentMainService.logsPath;
// Set zoomlevel
const windowConfig = this.configurationService.getValue<IWindowSettings | undefined>('window');
const zoomLevel = windowConfig?.zoomLevel;
if (typeof zoomLevel === 'number') {
configuration.zoomLevel = zoomLevel;
}
// Set fullscreen state
// Update window related properties
configuration.fullscreen = this.isFullScreen;
// Set Accessibility Config
configuration.autoDetectHighContrast = windowConfig?.autoDetectHighContrast ?? true;
configuration.accessibilitySupport = app.accessibilitySupportEnabled;
configuration.colorScheme = {
dark: nativeTheme.shouldUseDarkColors,
highContrast: nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors
};
// Title style related
configuration.maximized = this._win.isMaximized();
// Dump Perf Counters
// Update performance marks
configuration.perfMarks = getMarks();
// Parts splash
configuration.partsSplashPath = join(this.environmentMainService.userDataPath, 'rapid_render.json');
// OS Info
configuration.os = {
release: release()
};
// Product
configuration.product = product;
// Store into config object URL
this.configObjectUrl.update(configuration);
}

View file

@ -4,6 +4,9 @@
*--------------------------------------------------------------------------------------------*/
import { statSync } from 'fs';
import { release } from 'os';
import product from 'vs/platform/product/common/product';
import { getMarks } from 'vs/base/common/performance';
import { basename, normalize, join, posix } from 'vs/base/common/path';
import { localize } from 'vs/nls';
import { coalesce, distinct, firstOrDefault } from 'vs/base/common/arrays';
@ -13,7 +16,7 @@ import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/e
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { IStateService } from 'vs/platform/state/node/state';
import { CodeWindow } from 'vs/platform/windows/electron-main/window';
import { BrowserWindow, MessageBoxOptions, WebContents } from 'electron';
import { app, BrowserWindow, MessageBoxOptions, nativeTheme, WebContents } from 'electron';
import { ILifecycleMainService, UnloadReason } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ILogService } from 'vs/platform/log/common/log';
@ -1139,33 +1142,54 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
}
private openInBrowserWindow(options: IOpenBrowserWindowOptions): ICodeWindow {
const windowConfig = this.configurationService.getValue<IWindowSettings | undefined>('window');
// Build `INativeWindowConfiguration` from config and options
const configuration = { ...options.cli } as INativeWindowConfiguration;
configuration.appRoot = this.environmentMainService.appRoot;
configuration.machineId = this.machineId;
configuration.nodeCachedDataDir = this.environmentMainService.nodeCachedDataDir;
configuration.mainPid = process.pid;
configuration.execPath = process.execPath;
configuration.userEnv = { ...this.initialUserEnv, ...options.userEnv };
configuration.isInitialStartup = options.initialStartup;
configuration.workspace = options.workspace;
configuration.remoteAuthority = options.remoteAuthority;
// Build up the window configuration from provided options, config and environment
const configuration: INativeWindowConfiguration = {
...options.cli, // inherit all CLI arguments provided
_: options.cli?._ ?? [], // this is only needed to avoid `undefined`
const filesToOpen = options.filesToOpen;
if (filesToOpen) {
configuration.filesToOpenOrCreate = filesToOpen.filesToOpenOrCreate;
configuration.filesToDiff = filesToOpen.filesToDiff;
configuration.filesToWait = filesToOpen.filesToWait;
}
machineId: this.machineId,
// if we know the backup folder upfront (for empty windows to restore), we can set it
// directly here which helps for restoring UI state associated with that window.
// For all other cases we first call into registerEmptyWindowBackupSync() to set it before
// loading the window.
if (options.emptyWindowBackupInfo) {
configuration.backupPath = join(this.environmentMainService.backupHome, options.emptyWindowBackupInfo.backupFolder);
}
sessionId: '', // Will be filled in by the window once loaded later
windowId: -1, // Will be filled in by the window once loaded later
mainPid: process.pid,
appRoot: this.environmentMainService.appRoot,
execPath: process.execPath,
nodeCachedDataDir: this.environmentMainService.nodeCachedDataDir,
partsSplashPath: join(this.environmentMainService.userDataPath, 'rapid_render.json'),
// If we know the backup folder upfront (for empty windows to restore), we can set it
// directly here which helps for restoring UI state associated with that window.
// For all other cases we first call into registerEmptyWindowBackupSync() to set it before
// loading the window.
backupPath: options.emptyWindowBackupInfo ? join(this.environmentMainService.backupHome, options.emptyWindowBackupInfo.backupFolder) : undefined,
remoteAuthority: options.remoteAuthority,
workspace: options.workspace,
userEnv: { ...this.initialUserEnv, ...options.userEnv },
filesToOpenOrCreate: options.filesToOpen?.filesToOpenOrCreate,
filesToDiff: options.filesToOpen?.filesToDiff,
filesToWait: options.filesToOpen?.filesToWait,
logLevel: this.logService.getLevel(),
logsPath: this.environmentMainService.logsPath,
product,
isInitialStartup: options.initialStartup,
perfMarks: getMarks(),
os: { release: release() },
zoomLevel: typeof windowConfig?.zoomLevel === 'number' ? windowConfig.zoomLevel : undefined,
autoDetectHighContrast: windowConfig?.autoDetectHighContrast ?? true,
accessibilitySupport: app.accessibilitySupportEnabled,
colorScheme: {
dark: nativeTheme.shouldUseDarkColors,
highContrast: nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors
}
};
let window: ICodeWindow | undefined;
if (!options.forceNewWindow && !options.forceNewTabbedWindow) {