Merge from vscode 817eb6b0c720a4ecbc13c020afbbebfed667aa09 (#7356)

This commit is contained in:
Anthony Dresser
2019-09-24 21:36:17 -07:00
committed by GitHub
parent a29ae4d3b9
commit 6a6048d40f
541 changed files with 7045 additions and 7287 deletions

View File

@@ -5,16 +5,75 @@
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
export class BrowserHostService implements IHostService {
_serviceBrand: undefined;
constructor(@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService) { }
//#region Window
readonly windowCount = Promise.resolve(1);
async openEmptyWindow(options?: { reuse?: boolean, remoteAuthority?: string }): Promise<void> {
// TODO@Ben delegate to embedder
const targetHref = `${document.location.origin}${document.location.pathname}?ew=true`;
if (options && options.reuse) {
window.location.href = targetHref;
} else {
window.open(targetHref);
}
}
async toggleFullScreen(): Promise<void> {
const target = this.layoutService.getWorkbenchElement();
// Chromium
if (document.fullscreen !== undefined) {
if (!document.fullscreen) {
try {
return await target.requestFullscreen();
} catch (error) {
console.warn('Toggle Full Screen failed'); // https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullscreen
}
} else {
try {
return await document.exitFullscreen();
} catch (error) {
console.warn('Exit Full Screen failed');
}
}
}
// Safari and Edge 14 are all using webkit prefix
if ((<any>document).webkitIsFullScreen !== undefined) {
try {
if (!(<any>document).webkitIsFullScreen) {
(<any>target).webkitRequestFullscreen(); // it's async, but doesn't return a real promise.
} else {
(<any>document).webkitExitFullscreen(); // it's async, but doesn't return a real promise.
}
} catch {
console.warn('Enter/Exit Full Screen failed');
}
}
}
//#endregion
async restart(): Promise<void> {
this.reload();
}
async reload(): Promise<void> {
window.location.reload();
}
async closeWorkspace(): Promise<void> {
return this.openEmptyWindow({ reuse: true });
}
}
registerSingleton(IHostService, BrowserHostService, true);