mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode 817eb6b0c720a4ecbc13c020afbbebfed667aa09 (#7356)
This commit is contained in:
@@ -6,9 +6,10 @@
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { Client } from 'vs/base/parts/ipc/common/ipc.net';
|
||||
import { connect } from 'vs/base/parts/ipc/node/ipc.net';
|
||||
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
|
||||
import { IWindowService } from 'vs/platform/windows/common/windows';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { IChannel, IServerChannel, getDelayedChannel } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { IMainProcessService } from 'vs/platform/ipc/electron-browser/mainProcessService';
|
||||
|
||||
export const ISharedProcessService = createDecorator<ISharedProcessService>('sharedProcessService');
|
||||
|
||||
@@ -17,8 +18,10 @@ export interface ISharedProcessService {
|
||||
_serviceBrand: undefined;
|
||||
|
||||
getChannel(channelName: string): IChannel;
|
||||
|
||||
registerChannel(channelName: string, channel: IServerChannel<string>): void;
|
||||
|
||||
whenSharedProcessReady(): Promise<void>;
|
||||
toggleSharedProcessWindow(): Promise<void>;
|
||||
}
|
||||
|
||||
export class SharedProcessService implements ISharedProcessService {
|
||||
@@ -26,16 +29,23 @@ export class SharedProcessService implements ISharedProcessService {
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private withSharedProcessConnection: Promise<Client<string>>;
|
||||
private sharedProcessMainChannel: IChannel;
|
||||
|
||||
constructor(
|
||||
@IWindowsService windowsService: IWindowsService,
|
||||
@IMainProcessService mainProcessService: IMainProcessService,
|
||||
@IWindowService windowService: IWindowService,
|
||||
@IEnvironmentService environmentService: IEnvironmentService
|
||||
) {
|
||||
this.withSharedProcessConnection = windowsService.whenSharedProcessReady()
|
||||
this.sharedProcessMainChannel = mainProcessService.getChannel('sharedProcess');
|
||||
|
||||
this.withSharedProcessConnection = this.whenSharedProcessReady()
|
||||
.then(() => connect(environmentService.sharedIPCHandle, `window:${windowService.windowId}`));
|
||||
}
|
||||
|
||||
whenSharedProcessReady(): Promise<void> {
|
||||
return this.sharedProcessMainChannel.call('whenSharedProcessReady');
|
||||
}
|
||||
|
||||
getChannel(channelName: string): IChannel {
|
||||
return getDelayedChannel(this.withSharedProcessConnection.then(connection => connection.getChannel(channelName)));
|
||||
}
|
||||
@@ -43,4 +53,8 @@ export class SharedProcessService implements ISharedProcessService {
|
||||
registerChannel(channelName: string, channel: IServerChannel<string>): void {
|
||||
this.withSharedProcessConnection.then(connection => connection.registerChannel(channelName, channel));
|
||||
}
|
||||
|
||||
toggleSharedProcessWindow(): Promise<void> {
|
||||
return this.sharedProcessMainChannel.call('toggleSharedProcessWindow');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ISharedProcess } from 'vs/platform/windows/electron-main/windows';
|
||||
|
||||
export const ISharedProcessMainService = createDecorator<ISharedProcessMainService>('sharedProcessMainService');
|
||||
|
||||
export interface ISharedProcessMainService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
whenSharedProcessReady(): Promise<void>;
|
||||
toggleSharedProcessWindow(): Promise<void>;
|
||||
}
|
||||
export class SharedProcessMainService implements ISharedProcessMainService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
constructor(private sharedProcess: ISharedProcess) { }
|
||||
|
||||
whenSharedProcessReady(): Promise<void> {
|
||||
return this.sharedProcess.whenReady();
|
||||
}
|
||||
|
||||
async toggleSharedProcessWindow(): Promise<void> {
|
||||
return this.sharedProcess.toggle();
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,32 @@ import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
|
||||
// for a very basic process <=> process communication over methods.
|
||||
//
|
||||
|
||||
export type AddContextToFunctions<Target, Context> = {
|
||||
// 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
|
||||
[K in keyof Target]: Target[K] extends (...args: any) => any ? (context: Context, ...args: Parameters<Target[K]>) => ReturnType<Target[K]> : Target[K]
|
||||
};
|
||||
|
||||
interface ISimpleChannelProxyContext {
|
||||
__$simpleIPCContextMarker: boolean;
|
||||
proxyContext: unknown;
|
||||
}
|
||||
|
||||
function serializeContext(proxyContext?: unknown): ISimpleChannelProxyContext | undefined {
|
||||
if (proxyContext) {
|
||||
return { __$simpleIPCContextMarker: true, proxyContext };
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function deserializeContext(candidate?: ISimpleChannelProxyContext | undefined): unknown | undefined {
|
||||
if (candidate && candidate.__$simpleIPCContextMarker === true) {
|
||||
return candidate.proxyContext;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export class SimpleServiceProxyChannel implements IServerChannel {
|
||||
|
||||
private service: { [key: string]: unknown };
|
||||
@@ -23,9 +49,16 @@ export class SimpleServiceProxyChannel implements IServerChannel {
|
||||
throw new Error(`Events are currently unsupported by SimpleServiceProxyChannel: ${event}`);
|
||||
}
|
||||
|
||||
call(_: unknown, command: string, args: any[]): Promise<any> {
|
||||
call(_: unknown, command: string, args?: any[]): Promise<any> {
|
||||
const target = this.service[command];
|
||||
if (typeof target === 'function') {
|
||||
if (Array.isArray(args)) {
|
||||
const context = deserializeContext(args[0]);
|
||||
if (context) {
|
||||
args[0] = context;
|
||||
}
|
||||
}
|
||||
|
||||
return target.apply(this.service, args);
|
||||
}
|
||||
|
||||
@@ -33,12 +66,21 @@ export class SimpleServiceProxyChannel implements IServerChannel {
|
||||
}
|
||||
}
|
||||
|
||||
export function createSimpleChannelProxy<T>(channel: IChannel): T {
|
||||
export function createSimpleChannelProxy<T>(channel: IChannel, context?: unknown): T {
|
||||
const serializedContext = serializeContext(context);
|
||||
|
||||
return new Proxy({}, {
|
||||
get(_target, propKey, _receiver) {
|
||||
if (typeof propKey === 'string') {
|
||||
return function (...args: any[]) {
|
||||
return channel.call(propKey, args);
|
||||
let methodArgs: any[];
|
||||
if (serializedContext) {
|
||||
methodArgs = [context, ...args];
|
||||
} else {
|
||||
methodArgs = args;
|
||||
}
|
||||
|
||||
return channel.call(propKey, methodArgs);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user