mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-26 09:35:38 -05:00
This reverts commit 5d44b6a6a7.
This commit is contained in:
@@ -8,7 +8,7 @@ import * as objects from 'vs/base/common/objects';
|
||||
import * as nls from 'vs/nls';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IStateService } from 'vs/platform/state/common/state';
|
||||
import { screen, BrowserWindow, systemPreferences, app, TouchBar, nativeImage, Rectangle, Display } from 'electron';
|
||||
import { screen, BrowserWindow, systemPreferences, app, TouchBar, nativeImage } from 'electron';
|
||||
import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
@@ -25,6 +25,7 @@ import * as perf from 'vs/base/common/performance';
|
||||
import { resolveMarketplaceHeaders } from 'vs/platform/extensionManagement/node/extensionGalleryService';
|
||||
import { getBackgroundColor } from 'vs/code/electron-main/theme';
|
||||
import { RunOnceScheduler } from 'vs/base/common/async';
|
||||
import { withNullAsUndefined } from 'vs/base/common/types';
|
||||
import { endsWith } from 'vs/base/common/strings';
|
||||
|
||||
export interface IWindowCreationOptions {
|
||||
@@ -79,6 +80,8 @@ export class CodeWindow extends Disposable implements ICodeWindow {
|
||||
|
||||
private readonly touchBarGroups: Electron.TouchBarSegmentedControl[];
|
||||
|
||||
private nodeless: boolean;
|
||||
|
||||
constructor(
|
||||
config: IWindowCreationOptions,
|
||||
@ILogService private readonly logService: ILogService,
|
||||
@@ -95,6 +98,8 @@ export class CodeWindow extends Disposable implements ICodeWindow {
|
||||
this._readyState = ReadyState.NONE;
|
||||
this.whenReadyCallbacks = [];
|
||||
|
||||
this.nodeless = !!(environmentService.args.nodeless && !environmentService.isBuilt);
|
||||
|
||||
// create browser window
|
||||
this.createBrowserWindow(config);
|
||||
|
||||
@@ -124,7 +129,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
|
||||
height: this.windowState.height,
|
||||
x: this.windowState.x,
|
||||
y: this.windowState.y,
|
||||
backgroundColor: getBackgroundColor(this.stateService),
|
||||
backgroundColor: this.nodeless ? undefined : getBackgroundColor(this.stateService),
|
||||
minWidth: CodeWindow.MIN_WIDTH,
|
||||
minHeight: CodeWindow.MIN_HEIGHT,
|
||||
show: !isFullscreenOrMaximized,
|
||||
@@ -138,6 +143,10 @@ export class CodeWindow extends Disposable implements ICodeWindow {
|
||||
}
|
||||
};
|
||||
|
||||
if (this.nodeless) {
|
||||
options.webPreferences!.nodeIntegration = false; // simulate Electron 5 behaviour
|
||||
}
|
||||
|
||||
if (isLinux) {
|
||||
options.icon = path.join(this.environmentService.appRoot, 'resources/linux/code.png'); // Windows and Mac are better off using the embedded icon(s)
|
||||
}
|
||||
@@ -192,6 +201,10 @@ export class CodeWindow extends Disposable implements ICodeWindow {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.nodeless) {
|
||||
this._win.webContents.toggleDevTools();
|
||||
}
|
||||
|
||||
this._lastFocusTime = Date.now(); // since we show directly, we need to set the last focus time too
|
||||
}
|
||||
|
||||
@@ -627,6 +640,10 @@ export class CodeWindow extends Disposable implements ICodeWindow {
|
||||
}
|
||||
|
||||
private doGetUrl(config: object): string {
|
||||
if (this.nodeless) {
|
||||
return `${require.toUrl('vs/code/electron-browser/workbench/workbench.nodeless.html')}?config=${encodeURIComponent(JSON.stringify(config))}`;
|
||||
}
|
||||
|
||||
return `${require.toUrl('vs/code/electron-browser/workbench/workbench.html')}?config=${encodeURIComponent(JSON.stringify(config))}`;
|
||||
}
|
||||
|
||||
@@ -692,55 +709,66 @@ export class CodeWindow extends Disposable implements ICodeWindow {
|
||||
private restoreWindowState(state?: IWindowState): IWindowState {
|
||||
if (state) {
|
||||
try {
|
||||
state = this.validateWindowState(state);
|
||||
state = withNullAsUndefined(this.validateWindowState(state));
|
||||
} catch (err) {
|
||||
this.logService.warn(`Unexpected error validating window state: ${err}\n${err.stack}`); // somehow display API can be picky about the state to validate
|
||||
}
|
||||
}
|
||||
return state || defaultWindowState();
|
||||
|
||||
if (!state) {
|
||||
state = defaultWindowState();
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
private validateWindowState(state: IWindowState): IWindowState | undefined {
|
||||
private validateWindowState(state: IWindowState): IWindowState | null {
|
||||
if (!state) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (typeof state.x !== 'number'
|
||||
|| typeof state.y !== 'number'
|
||||
|| typeof state.width !== 'number'
|
||||
|| typeof state.height !== 'number'
|
||||
) {
|
||||
return undefined;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (state.width <= 0 || state.height <= 0) {
|
||||
return undefined;
|
||||
return null;
|
||||
}
|
||||
|
||||
const displays = screen.getAllDisplays();
|
||||
|
||||
// Single Monitor: be strict about x/y positioning
|
||||
if (displays.length === 1) {
|
||||
const displayWorkingArea = this.getWorkingArea(displays[0]);
|
||||
if (state.mode !== WindowMode.Maximized && displayWorkingArea) {
|
||||
if (state.x < displayWorkingArea.x) {
|
||||
state.x = displayWorkingArea.x; // prevent window from falling out of the screen to the left
|
||||
const displayBounds = displays[0].bounds;
|
||||
|
||||
// Careful with maximized: in that mode x/y can well be negative!
|
||||
if (state.mode !== WindowMode.Maximized && displayBounds.width > 0 && displayBounds.height > 0 /* Linux X11 sessions sometimes report wrong display bounds */) {
|
||||
if (state.x < displayBounds.x) {
|
||||
state.x = displayBounds.x; // prevent window from falling out of the screen to the left
|
||||
}
|
||||
|
||||
if (state.y < displayWorkingArea.y) {
|
||||
state.y = displayWorkingArea.y; // prevent window from falling out of the screen to the top
|
||||
if (state.y < displayBounds.y) {
|
||||
state.y = displayBounds.y; // prevent window from falling out of the screen to the top
|
||||
}
|
||||
|
||||
if (state.x > (displayWorkingArea.x + displayWorkingArea.width)) {
|
||||
state.x = displayWorkingArea.x; // prevent window from falling out of the screen to the right
|
||||
if (state.x > (displayBounds.x + displayBounds.width)) {
|
||||
state.x = displayBounds.x; // prevent window from falling out of the screen to the right
|
||||
}
|
||||
|
||||
if (state.y > (displayWorkingArea.y + displayWorkingArea.height)) {
|
||||
state.y = displayWorkingArea.y; // prevent window from falling out of the screen to the bottom
|
||||
if (state.y > (displayBounds.y + displayBounds.height)) {
|
||||
state.y = displayBounds.y; // prevent window from falling out of the screen to the bottom
|
||||
}
|
||||
|
||||
if (state.width > displayWorkingArea.width) {
|
||||
state.width = displayWorkingArea.width; // prevent window from exceeding display bounds width
|
||||
if (state.width > displayBounds.width) {
|
||||
state.width = displayBounds.width; // prevent window from exceeding display bounds width
|
||||
}
|
||||
|
||||
if (state.height > displayWorkingArea.height) {
|
||||
state.height = displayWorkingArea.height; // prevent window from exceeding display bounds height
|
||||
if (state.height > displayBounds.height) {
|
||||
state.height = displayBounds.height; // prevent window from exceeding display bounds height
|
||||
}
|
||||
}
|
||||
|
||||
@@ -766,14 +794,12 @@ export class CodeWindow extends Disposable implements ICodeWindow {
|
||||
// Multi Monitor (non-fullscreen): be less strict because metrics can be crazy
|
||||
const bounds = { x: state.x, y: state.y, width: state.width, height: state.height };
|
||||
const display = screen.getDisplayMatching(bounds);
|
||||
const displayWorkingArea = this.getWorkingArea(display);
|
||||
if (
|
||||
display && // we have a display matching the desired bounds
|
||||
displayWorkingArea && // we have valid working area bounds
|
||||
bounds.x < displayWorkingArea.x + displayWorkingArea.width && // prevent window from falling out of the screen to the right
|
||||
bounds.y < displayWorkingArea.y + displayWorkingArea.height && // prevent window from falling out of the screen to the bottom
|
||||
bounds.x + bounds.width > displayWorkingArea.x && // prevent window from falling out of the screen to the left
|
||||
bounds.y + bounds.height > displayWorkingArea.y // prevent window from falling out of the scree nto the top
|
||||
display && // we have a display matching the desired bounds
|
||||
bounds.x < display.bounds.x + display.bounds.width && // prevent window from falling out of the screen to the right
|
||||
bounds.y < display.bounds.y + display.bounds.height && // prevent window from falling out of the screen to the bottom
|
||||
bounds.x + bounds.width > display.bounds.x && // prevent window from falling out of the screen to the left
|
||||
bounds.y + bounds.height > display.bounds.y // prevent window from falling out of the scree nto the top
|
||||
) {
|
||||
if (state.mode === WindowMode.Maximized) {
|
||||
const defaults = defaultWindowState(WindowMode.Maximized); // when maximized, make sure we have good values when the user restores the window
|
||||
@@ -786,25 +812,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
|
||||
return state;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private getWorkingArea(display: Display): Rectangle | undefined {
|
||||
|
||||
// Prefer the working area of the display to account for taskbars on the
|
||||
// desktop being positioned somewhere (https://github.com/Microsoft/vscode/issues/50830).
|
||||
//
|
||||
// Linux X11 sessions sometimes report wrong display bounds, so we validate
|
||||
// the reported sizes are positive.
|
||||
if (display.workArea.width > 0 && display.workArea.height > 0) {
|
||||
return display.workArea;
|
||||
}
|
||||
|
||||
if (display.bounds.width > 0 && display.bounds.height > 0) {
|
||||
return display.bounds;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return null;
|
||||
}
|
||||
|
||||
getBounds(): Electron.Rectangle {
|
||||
|
||||
Reference in New Issue
Block a user