-
Notifications
You must be signed in to change notification settings - Fork 27.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195326 from microsoft/ben/husky-bison
Some editors and aux window fixes
- Loading branch information
Showing
24 changed files
with
385 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/vs/platform/auxiliaryWindow/electron-main/auxiliaryWindow.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { BrowserWindow, WebContents } from 'electron'; | ||
import { Emitter, Event } from 'vs/base/common/event'; | ||
import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService'; | ||
import { BaseWindow } from 'vs/platform/windows/electron-main/windowImpl'; | ||
|
||
export interface IAuxiliaryWindow { | ||
|
||
readonly onDidClose: Event<void>; | ||
|
||
readonly id: number; | ||
readonly win: BrowserWindow | null; | ||
|
||
focus(options?: { force: boolean }): void; | ||
} | ||
|
||
export class AuxiliaryWindow extends BaseWindow implements IAuxiliaryWindow { | ||
|
||
readonly id = this.contents.id; | ||
|
||
private readonly _onDidClose = this._register(new Emitter<void>()); | ||
readonly onDidClose = this._onDidClose.event; | ||
|
||
private _win: BrowserWindow | null = null; | ||
get win() { | ||
if (!this._win) { | ||
const window = BrowserWindow.fromWebContents(this.contents); | ||
if (window) { | ||
this._win = window; | ||
this.registerWindowListeners(window); | ||
} | ||
} | ||
|
||
return this._win; | ||
} | ||
|
||
protected getWin(): BrowserWindow | null { | ||
return this.win; | ||
} | ||
|
||
constructor( | ||
private readonly contents: WebContents, | ||
@IEnvironmentMainService private readonly environmentMainService: IEnvironmentMainService | ||
) { | ||
super(); | ||
|
||
this.create(); | ||
} | ||
|
||
private create(): void { | ||
|
||
// Handle devtools argument | ||
if (this.environmentMainService.args['open-devtools'] === true) { | ||
this.contents.openDevTools({ mode: 'bottom' }); | ||
} | ||
} | ||
|
||
private registerWindowListeners(window: BrowserWindow): void { | ||
|
||
// Window close | ||
window.on('closed', () => { | ||
this._onDidClose.fire(); | ||
|
||
this.dispose(); | ||
}); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/vs/platform/auxiliaryWindow/electron-main/auxiliaryWindows.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { BrowserWindowConstructorOptions, WebContents } from 'electron'; | ||
import { IAuxiliaryWindow } from 'vs/platform/auxiliaryWindow/electron-main/auxiliaryWindow'; | ||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; | ||
|
||
export const IAuxiliaryWindowsMainService = createDecorator<IAuxiliaryWindowsMainService>('auxiliaryWindowsMainService'); | ||
|
||
export interface IAuxiliaryWindowsMainService { | ||
|
||
readonly _serviceBrand: undefined; | ||
|
||
createWindow(): BrowserWindowConstructorOptions; | ||
registerWindow(webContents: WebContents): void; | ||
|
||
getWindowById(windowId: number): IAuxiliaryWindow | undefined; | ||
getFocusedWindow(): IAuxiliaryWindow | undefined; | ||
} |
51 changes: 51 additions & 0 deletions
51
src/vs/platform/auxiliaryWindow/electron-main/auxiliaryWindowsMainService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { BrowserWindow, BrowserWindowConstructorOptions, WebContents } from 'electron'; | ||
import { Event } from 'vs/base/common/event'; | ||
import { FileAccess } from 'vs/base/common/network'; | ||
import { AuxiliaryWindow, IAuxiliaryWindow } from 'vs/platform/auxiliaryWindow/electron-main/auxiliaryWindow'; | ||
import { IAuxiliaryWindowsMainService } from 'vs/platform/auxiliaryWindow/electron-main/auxiliaryWindows'; | ||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; | ||
import { defaultBrowserWindowOptions } from 'vs/platform/windows/electron-main/windows'; | ||
|
||
export class AuxiliaryWindowsMainService implements IAuxiliaryWindowsMainService { | ||
|
||
declare readonly _serviceBrand: undefined; | ||
|
||
private readonly windows = new Map<number, IAuxiliaryWindow>(); | ||
|
||
constructor( | ||
@IInstantiationService private readonly instantiationService: IInstantiationService | ||
) { } | ||
|
||
createWindow(): BrowserWindowConstructorOptions { | ||
return this.instantiationService.invokeFunction(defaultBrowserWindowOptions, undefined, { | ||
webPreferences: { | ||
preload: FileAccess.asFileUri('vs/base/parts/sandbox/electron-sandbox/preload-slim.js').fsPath | ||
} | ||
}); | ||
} | ||
|
||
registerWindow(webContents: WebContents): void { | ||
const auxiliaryWindow = this.instantiationService.createInstance(AuxiliaryWindow, webContents); | ||
this.windows.set(auxiliaryWindow.id, auxiliaryWindow); | ||
|
||
Event.once(auxiliaryWindow.onDidClose)(() => this.windows.delete(auxiliaryWindow.id)); | ||
} | ||
|
||
getWindowById(windowId: number): IAuxiliaryWindow | undefined { | ||
return this.windows.get(windowId); | ||
} | ||
|
||
getFocusedWindow(): IAuxiliaryWindow | undefined { | ||
const window = BrowserWindow.getFocusedWindow(); | ||
if (window) { | ||
return this.getWindowById(window.id); | ||
} | ||
|
||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.