From c95f06e6814e79931420aa4017715bd12be0154a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Wed, 17 Jun 2020 16:51:56 +0200 Subject: [PATCH] Add env.uiKind API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Mäder --- .../plugin-ext/src/common/plugin-api-rpc.ts | 14 +++++++++++ .../src/hosted/browser/hosted-plugin.ts | 4 +++- packages/plugin-ext/src/plugin/env.ts | 8 +++++++ .../plugin-ext/src/plugin/plugin-context.ts | 3 +++ .../plugin-ext/src/plugin/plugin-manager.ts | 1 + packages/plugin-ext/src/plugin/types-impl.ts | 17 ++++++++++++++ packages/plugin/src/theia.d.ts | 23 +++++++++++++++++++ 7 files changed, 69 insertions(+), 1 deletion(-) diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index d43ac418e7512..a39bbf288802d 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -98,10 +98,24 @@ export interface ConfigStorage { hostGlobalStoragePath: string; } +export enum UIKind { + + /** + * Extensions are accessed from a desktop application. + */ + Desktop = 1, + + /** + * Extensions are accessed from a web browser. + */ + Web = 2 +} + export interface EnvInit { queryParams: QueryParameters; language: string; shell: string; + uiKind: UIKind, appName: string; } diff --git a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts index e6fd9415157f6..bf66b3679bfff 100644 --- a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts +++ b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts @@ -27,7 +27,7 @@ import { injectable, inject, interfaces, named, postConstruct } from 'inversify' import { PluginWorker } from '../../main/browser/plugin-worker'; import { PluginMetadata, getPluginId, HostedPluginServer, DeployedPlugin } from '../../common/plugin-protocol'; import { HostedPluginWatcher } from './hosted-plugin-watcher'; -import { MAIN_RPC_CONTEXT, PluginManagerExt, ConfigStorage } from '../../common/plugin-api-rpc'; +import { MAIN_RPC_CONTEXT, PluginManagerExt, ConfigStorage, UIKind } from '../../common/plugin-api-rpc'; import { setUpPluginApi } from '../../main/browser/main-context'; import { RPCProtocol, RPCProtocolImpl } from '../../common/rpc-protocol'; import { @@ -60,6 +60,7 @@ import { TerminalService } from '@theia/terminal/lib/browser/base/terminal-servi import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; import URI from '@theia/core/lib/common/uri'; import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider'; +import { environment } from '@theia/application-package/lib/environment'; export type PluginHost = 'frontend' | string; export type DebugActivationEvent = 'onDebugResolve' | 'onDebugInitialConfigurations' | 'onDebugAdapterProtocolTracker'; @@ -454,6 +455,7 @@ export class HostedPluginSupport { queryParams: getQueryParameters(), language: navigator.language, shell: defaultShell, + uiKind: environment.electron.is() ? UIKind.Desktop : UIKind.Web, appName: FrontendApplicationConfigProvider.get().applicationName }, extApi, diff --git a/packages/plugin-ext/src/plugin/env.ts b/packages/plugin-ext/src/plugin/env.ts index 51d8fd010c48b..9f0e464fb04dc 100644 --- a/packages/plugin-ext/src/plugin/env.ts +++ b/packages/plugin-ext/src/plugin/env.ts @@ -26,6 +26,7 @@ export abstract class EnvExtImpl { private lang: string; private applicationName: string; private defaultShell: string; + private ui: theia.UIKind; private envMachineId: string; private envSessionId: string; @@ -68,6 +69,10 @@ export abstract class EnvExtImpl { this.defaultShell = shell; } + setUIKind(uiKind: theia.UIKind): void { + this.ui = uiKind; + } + getClientOperatingSystem(): Promise { return this.proxy.$getClientOperatingSystem(); } @@ -93,4 +98,7 @@ export abstract class EnvExtImpl { get shell(): string { return this.defaultShell; } + get uiKind(): theia.UIKind { + return this.ui; + } } diff --git a/packages/plugin-ext/src/plugin/plugin-context.ts b/packages/plugin-ext/src/plugin/plugin-context.ts index 0aede30c8172d..77f2bd68690c1 100644 --- a/packages/plugin-ext/src/plugin/plugin-context.ts +++ b/packages/plugin-ext/src/plugin/plugin-context.ts @@ -112,6 +112,7 @@ import { ColorPresentation, OperatingSystem, WebviewPanelTargetArea, + UIKind, FileSystemError, CommentThreadCollapsibleState, QuickInputButtons, @@ -511,6 +512,7 @@ export function createAPIFactory( get sessionId(): string { return envExt.sessionId; }, get uriScheme(): string { return envExt.uriScheme; }, get shell(): string { return envExt.shell; }, + get uiKind(): theia.UIKind { return envExt.uiKind; }, clipboard, getEnvVariable(envVarName: string): PromiseLike { return envExt.getEnvVariable(envVarName); @@ -878,6 +880,7 @@ export function createAPIFactory( FoldingRangeKind, OperatingSystem, WebviewPanelTargetArea, + UIKind, FileSystemError, CommentThreadCollapsibleState, QuickInputButtons, diff --git a/packages/plugin-ext/src/plugin/plugin-manager.ts b/packages/plugin-ext/src/plugin/plugin-manager.ts index 1918e5d7cbbb5..87b946bd9ffa5 100644 --- a/packages/plugin-ext/src/plugin/plugin-manager.ts +++ b/packages/plugin-ext/src/plugin/plugin-manager.ts @@ -186,6 +186,7 @@ export class PluginManagerExtImpl implements PluginManagerExt, PluginManager { this.envExt.setQueryParameters(params.env.queryParams); this.envExt.setLanguage(params.env.language); this.envExt.setShell(params.env.shell); + this.envExt.setUIKind(params.env.uiKind); this.envExt.setApplicationName(params.env.appName); this.preferencesManager.init(params.preferences); diff --git a/packages/plugin-ext/src/plugin/types-impl.ts b/packages/plugin-ext/src/plugin/types-impl.ts index eedf4b144ba1a..df6b4deb00467 100644 --- a/packages/plugin-ext/src/plugin/types-impl.ts +++ b/packages/plugin-ext/src/plugin/types-impl.ts @@ -2054,6 +2054,23 @@ export enum WebviewPanelTargetArea { Right = 'right', Bottom = 'bottom' } + +/** + * Possible kinds of UI that can use extensions. + */ +export enum UIKind { + + /** + * Extensions are accessed from a desktop application. + */ + Desktop = 1, + + /** + * Extensions are accessed from a web browser. + */ + Web = 2 +} + export class CallHierarchyItem { _sessionId?: string; _itemId?: string; diff --git a/packages/plugin/src/theia.d.ts b/packages/plugin/src/theia.d.ts index f0a5a00d9cab9..3d8dea080e39a 100644 --- a/packages/plugin/src/theia.d.ts +++ b/packages/plugin/src/theia.d.ts @@ -3150,6 +3150,22 @@ declare module '@theia/plugin' { writeText(value: string): PromiseLike; } + /** + * Possible kinds of UI that can use extensions. + */ + export enum UIKind { + + /** + * Extensions are accessed from a desktop application. + */ + Desktop = 1, + + /** + * Extensions are accessed from a web browser. + */ + Web = 2 + } + /** * A uri handler is responsible for handling system-wide [uris](#Uri). * @@ -5295,6 +5311,13 @@ declare module '@theia/plugin' { */ export const shell: string; + /** + * The UI kind property indicates from which UI extensions + * are accessed from. For example, extensions could be accessed + * from a desktop application or a web browser. + */ + export const uiKind: UIKind; + /** * The system clipboard. */