Skip to content

Commit 373eb0c

Browse files
fix: make toggleFullScreen hookable instead of patching it
1 parent 21a6cbb commit 373eb0c

File tree

2 files changed

+68
-16
lines changed

2 files changed

+68
-16
lines changed

src/service-override/host.ts

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,75 @@
1+
import { mainWindow } from 'vs/base/browser/window'
12
import type { IEditorOverrideServices } from 'vs/editor/standalone/browser/standaloneServices'
3+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration.service'
4+
import { IDialogService } from 'vs/platform/dialogs/common/dialogs.service'
5+
import { IFileService } from 'vs/platform/files/common/files.service'
26
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'
3-
import { IHostService } from 'vs/workbench/services/host/browser/host.service'
4-
import { IHostColorSchemeService } from 'vs/workbench/services/themes/common/hostColorSchemeService.service'
7+
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'
8+
import { ILabelService } from 'vs/platform/label/common/label.service'
9+
import { ILayoutService } from 'vs/platform/layout/browser/layoutService.service'
10+
import { ILogService } from 'vs/platform/log/common/log.service'
11+
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile.service'
12+
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace.service'
13+
import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService.service'
514
import { BrowserHostService } from 'vs/workbench/services/host/browser/browserHostService'
15+
import { IHostService } from 'vs/workbench/services/host/browser/host.service'
16+
import type { BrowserLifecycleService } from 'vs/workbench/services/lifecycle/browser/lifecycleService'
17+
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle.service'
618
import { BrowserHostColorSchemeService } from 'vs/workbench/services/themes/browser/browserHostColorSchemeService'
19+
import { IHostColorSchemeService } from 'vs/workbench/services/themes/common/hostColorSchemeService.service'
20+
21+
class CustomBrowserHostService extends BrowserHostService {
22+
constructor(
23+
private _toggleFullScreen: () => Promise<void> | undefined,
24+
@ILayoutService layoutService: ILayoutService,
25+
@IConfigurationService configurationService: IConfigurationService,
26+
@IFileService fileService: IFileService,
27+
@ILabelService labelService: ILabelService,
28+
@IBrowserWorkbenchEnvironmentService environmentService: IBrowserWorkbenchEnvironmentService,
29+
@IInstantiationService instantiationService: IInstantiationService,
30+
@ILifecycleService lifecycleService: BrowserLifecycleService,
31+
@ILogService logService: ILogService,
32+
@IDialogService dialogService: IDialogService,
33+
@IWorkspaceContextService contextService: IWorkspaceContextService,
34+
@IUserDataProfilesService userDataProfilesService: IUserDataProfilesService
35+
) {
36+
super(
37+
layoutService,
38+
configurationService,
39+
fileService,
40+
labelService,
41+
environmentService,
42+
instantiationService,
43+
lifecycleService,
44+
logService,
45+
dialogService,
46+
contextService,
47+
userDataProfilesService
48+
)
49+
}
750

8-
export default function getServiceOverride(): IEditorOverrideServices {
51+
override async toggleFullScreen(targetWindow: Window): Promise<void> {
52+
if (this._toggleFullScreen != null && targetWindow === mainWindow) {
53+
await this._toggleFullScreen()
54+
} else {
55+
await super.toggleFullScreen(targetWindow)
56+
}
57+
}
58+
}
59+
60+
interface BrowserHostServiceOverrideParams {
61+
toggleFullScreen?: (targetWindow: Window) => Promise<void>
62+
}
63+
64+
export default function getServiceOverride({
65+
toggleFullScreen
66+
}: BrowserHostServiceOverrideParams = {}): IEditorOverrideServices {
967
return {
10-
[IHostService.toString()]: new SyncDescriptor(BrowserHostService, [], true),
68+
[IHostService.toString()]: new SyncDescriptor(
69+
CustomBrowserHostService,
70+
[toggleFullScreen],
71+
true
72+
),
1173
[IHostColorSchemeService.toString()]: new SyncDescriptor(
1274
BrowserHostColorSchemeService,
1375
[],

vscode-patches/0071-feat-prevent-IDE-from-entering-fullscreen-if-not-occ.patch

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Subject: [PATCH] feat: prevent IDE from entering fullscreen if not occupying
77
---
88
src/vs/base/browser/dom.ts | 12 ++++++++----
99
src/vs/workbench/browser/web.main.ts | 2 +-
10-
.../services/host/browser/browserHostService.ts | 4 ++--
11-
3 files changed, 11 insertions(+), 7 deletions(-)
10+
.../services/host/browser/browserHostService.ts | 4 +-
11+
3 files changed, 10 insertions(+), 6 deletions(-)
1212

1313
diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts
1414
index 49549236908..af89a7f1e46 100644
@@ -74,13 +74,3 @@ index 6f62f49b906..6e41a554052 100644
7474
+ const fullScreen = detectFullscreen(window, this.layoutService.getContainer(window));
7575
return fullScreen !== null && !fullScreen.guess;
7676
};
77-
78-
@@ -523,7 +523,7 @@ export class BrowserHostService extends Disposable implements IHostService {
79-
}
80-
81-
async toggleFullScreen(targetWindow: Window): Promise<void> {
82-
- const target = this.layoutService.getContainer(targetWindow);
83-
+ const target = targetWindow === mainWindow ? targetWindow.document.body : this.layoutService.getContainer(targetWindow);
84-
85-
// Chromium
86-
if (targetWindow.document.fullscreen !== undefined) {

0 commit comments

Comments
 (0)