Skip to content

Commit 2f2eb54

Browse files
author
Benjamin Pasero
committed
💄 service context
1 parent 4da232a commit 2f2eb54

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/vs/platform/electron/electron-main/electronMainService.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ import { OpenContext, INativeOpenDialogOptions } from 'vs/platform/windows/commo
1010
import { isMacintosh } from 'vs/base/common/platform';
1111
import { IElectronService } from 'vs/platform/electron/node/electron';
1212
import { ISerializableCommandAction } from 'vs/platform/actions/common/actions';
13+
import { AddContextToFunctions } from 'vs/platform/ipc/node/simpleIpcProxy';
1314

14-
type ElectronServiceInterface = {
15-
// Every property of service: IF property is a FUNCTION ADD windowId as first parameter and original parameters afterwards with same return type ELSE preserve as is
16-
[K in keyof IElectronService]: IElectronService[K] extends (...args: any) => any ? (windowId: number, ...args: Parameters<IElectronService[K]>) => ReturnType<IElectronService[K]> : IElectronService[K]
17-
};
18-
19-
export class ElectronMainService implements ElectronServiceInterface {
15+
export class ElectronMainService implements AddContextToFunctions<IElectronService, number> {
2016

2117
_serviceBrand: undefined;
2218

src/vs/platform/ipc/node/simpleIpcProxy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
1111
// for a very basic process <=> process communication over methods.
1212
//
1313

14+
export type AddContextToFunctions<Target, Context> = {
15+
// For every property: IF property is a FUNCTION ADD context as first parameter and original parameters afterwards with same return type, otherwise preserve as is
16+
[K in keyof Target]: Target[K] extends (...args: any) => any ? (context: Context, ...args: Parameters<Target[K]>) => ReturnType<Target[K]> : Target[K]
17+
};
18+
1419
interface ISimpleChannelProxyContext {
1520
__$simpleIPCContextMarker: boolean;
1621
proxyContext: unknown;

0 commit comments

Comments
 (0)