|
1 | 1 | import { type IEditorOverrideServices } from 'vs/editor/standalone/browser/standaloneServices' |
2 | 2 | import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors' |
| 3 | +import { ILogService } from 'vs/platform/log/common/log.service' |
| 4 | +import { IStorageService } from 'vs/platform/storage/common/storage.service' |
3 | 5 | import { BrowserLifecycleService } from 'vs/workbench/services/lifecycle/browser/lifecycleService' |
| 6 | +import { StartupKind } from 'vs/workbench/services/lifecycle/common/lifecycle' |
4 | 7 | import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle.service' |
5 | 8 | import { TimerService } from 'vs/workbench/services/timer/browser/timerService' |
6 | 9 | import { ITimerService } from 'vs/workbench/services/timer/browser/timerService.service' |
7 | 10 |
|
8 | | -export default function getServiceOverride(): IEditorOverrideServices { |
| 11 | +interface StartupKindResolver { |
| 12 | + (resolveDefault: () => StartupKind | undefined): StartupKind | undefined |
| 13 | +} |
| 14 | +export interface LifecycleServiceParams { |
| 15 | + /** |
| 16 | + * Allows to force the startup kind |
| 17 | + */ |
| 18 | + resolveStartupKind?: StartupKindResolver |
| 19 | +} |
| 20 | + |
| 21 | +const DEFAULT_RESOLVE_STARTUP_KIND: StartupKindResolver = (resolveDefault) => resolveDefault() |
| 22 | + |
| 23 | +class BrowserLifecycleServiceOverride extends BrowserLifecycleService { |
| 24 | + constructor( |
| 25 | + private params: LifecycleServiceParams, |
| 26 | + @ILogService logService: ILogService, |
| 27 | + @IStorageService storageService: IStorageService |
| 28 | + ) { |
| 29 | + super(logService, storageService) |
| 30 | + } |
| 31 | + |
| 32 | + protected override doResolveStartupKind(): StartupKind | undefined { |
| 33 | + return (this.params.resolveStartupKind ?? DEFAULT_RESOLVE_STARTUP_KIND)(() => |
| 34 | + super.doResolveStartupKind() |
| 35 | + ) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +export default function getServiceOverride( |
| 40 | + options: LifecycleServiceParams = {} |
| 41 | +): IEditorOverrideServices { |
9 | 42 | return { |
10 | | - [ILifecycleService.toString()]: new SyncDescriptor(BrowserLifecycleService), |
| 43 | + [ILifecycleService.toString()]: new SyncDescriptor(BrowserLifecycleServiceOverride, [options]), |
11 | 44 | [ITimerService.toString()]: new SyncDescriptor(TimerService) |
12 | 45 | } |
13 | 46 | } |
| 47 | + |
| 48 | +export { StartupKind } |
0 commit comments