Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 3b395af

Browse files
akurinnoymonaka
authored andcommitted
expose some methods from CheApiService to Che Plugin API
1 parent 6dfcdb2 commit 3b395af

File tree

6 files changed

+127
-1
lines changed

6 files changed

+127
-1
lines changed

extensions/eclipse-che-theia-plugin-ext/src/browser/che-api-provider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { CheVariablesMainImpl } from './che-variables-main';
1818
import { CheTaskMainImpl } from './che-task-main';
1919
import { CheSshMainImpl } from './che-ssh-main';
2020
import { CheDevfileMainImpl } from './che-devfile-main';
21+
import { CheUserMainImpl } from './che-user-main';
2122

2223
@injectable()
2324
export class CheApiProvider implements MainPluginApiProvider {
@@ -29,6 +30,7 @@ export class CheApiProvider implements MainPluginApiProvider {
2930
rpc.set(PLUGIN_RPC_CONTEXT.CHE_VARIABLES_MAIN, new CheVariablesMainImpl(container, rpc));
3031
rpc.set(PLUGIN_RPC_CONTEXT.CHE_TASK_MAIN, new CheTaskMainImpl(container, rpc));
3132
rpc.set(PLUGIN_RPC_CONTEXT.CHE_SSH_MAIN, new CheSshMainImpl(container));
33+
rpc.set(PLUGIN_RPC_CONTEXT.CHE_USER_MAIN, new CheUserMainImpl(container));
3234
}
3335

3436
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*********************************************************************
2+
* Copyright (c) 2019 Red Hat, Inc.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
**********************************************************************/
10+
11+
import { interfaces } from 'inversify';
12+
import { CheApiService, CheUserMain } from '../common/che-protocol';
13+
import { Preferences } from '@eclipse-che/plugin';
14+
15+
export class CheUserMainImpl implements CheUserMain {
16+
17+
private readonly cheApiService: CheApiService;
18+
19+
constructor(container: interfaces.Container) {
20+
this.cheApiService = container.get(CheApiService);
21+
}
22+
23+
$getUserPreferences(filter?: string): Promise<Preferences> {
24+
return this.cheApiService.getUserPreferences(filter);
25+
}
26+
27+
$updateUserPreferences(preferences: Preferences): Promise<Preferences> {
28+
return this.cheApiService.updateUserPreferences(preferences);
29+
}
30+
31+
$replaceUserPreferences(preferences: Preferences): Promise<Preferences> {
32+
return this.cheApiService.replaceUserPreferences(preferences);
33+
}
34+
35+
$deleteUserPreferences(list?: string[]): Promise<void> {
36+
return this.cheApiService.deleteUserPreferences(list);
37+
}
38+
}

extensions/eclipse-che-theia-plugin-ext/src/common/che-protocol.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ export const PLUGIN_RPC_CONTEXT = {
366366

367367
CHE_SSH: <ProxyIdentifier<CheSsh>>createProxyIdentifier<CheSsh>('CheSsh'),
368368
CHE_SSH_MAIN: <ProxyIdentifier<CheSshMain>>createProxyIdentifier<CheSshMain>('CheSshMain'),
369+
370+
CHE_USER: <ProxyIdentifier<CheUser>>createProxyIdentifier<CheUser>('CheUser'),
371+
CHE_USER_MAIN: <ProxyIdentifier<CheUserMain>>createProxyIdentifier<CheUserMain>('CheUserMain'),
369372
};
370373

371374
// Theia RPC protocol
@@ -487,3 +490,12 @@ export interface ChePluginService {
487490
removePlugin(pluginKey: string): Promise<void>;
488491

489492
}
493+
494+
export interface CheUser { }
495+
496+
export interface CheUserMain {
497+
$getUserPreferences(filter?: string): Promise<Preferences>;
498+
$updateUserPreferences(preferences: Preferences): Promise<Preferences>;
499+
$replaceUserPreferences(preferences: Preferences): Promise<Preferences>;
500+
$deleteUserPreferences(list?: string[]): Promise<void>;
501+
}

extensions/eclipse-che-theia-plugin-ext/src/plugin/che-api.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { CheFactoryImpl } from './che-factory';
1919
import { CheDevfileImpl } from './che-devfile';
2020
import { CheTaskImpl } from './che-task-impl';
2121
import { CheSshImpl } from './che-ssh';
22+
import { CheUserImpl } from './che-user';
2223

2324
export interface CheApiFactory {
2425
(plugin: Plugin): typeof che;
@@ -31,6 +32,7 @@ export function createAPIFactory(rpc: RPCProtocol): CheApiFactory {
3132
const cheVariablesImpl = rpc.set(PLUGIN_RPC_CONTEXT.CHE_VARIABLES, new CheVariablesImpl(rpc));
3233
const cheTaskImpl = rpc.set(PLUGIN_RPC_CONTEXT.CHE_TASK, new CheTaskImpl(rpc));
3334
const cheSshImpl = rpc.set(PLUGIN_RPC_CONTEXT.CHE_SSH, new CheSshImpl(rpc));
35+
const cheUserImpl = rpc.set(PLUGIN_RPC_CONTEXT.CHE_USER, new CheUserImpl(rpc));
3436

3537
return function (plugin: Plugin): typeof che {
3638
const workspace: typeof che.workspace = {
@@ -124,13 +126,29 @@ export function createAPIFactory(rpc: RPCProtocol): CheApiFactory {
124126
}
125127
};
126128

129+
const user: typeof che.user = {
130+
getUserPreferences(filter?: string): Promise<che.Preferences> {
131+
return cheUserImpl.getUserPreferences(filter);
132+
},
133+
updateUserPreferences(update: che.Preferences): Promise<che.Preferences> {
134+
return cheUserImpl.updateUserPreferences(update);
135+
},
136+
replaceUserPreferences(preferences: che.Preferences): Promise<che.Preferences> {
137+
return cheUserImpl.replaceUserPreferences(preferences);
138+
},
139+
deleteUserPreferences(list?: string[]): Promise<void> {
140+
return cheUserImpl.deleteUserPreferences(list);
141+
}
142+
};
143+
127144
return <typeof che>{
128145
workspace,
129146
factory,
130147
devfile,
131148
variables,
132149
task,
133-
ssh
150+
ssh,
151+
user
134152
};
135153
};
136154

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*********************************************************************
2+
* Copyright (c) 2019 Red Hat, Inc.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
**********************************************************************/
10+
11+
import { RPCProtocol } from '@theia/plugin-ext/lib/api/rpc-protocol';
12+
import { Preferences } from '@eclipse-che/plugin';
13+
import {
14+
CheUser,
15+
CheUserMain,
16+
PLUGIN_RPC_CONTEXT,
17+
} from '../common/che-protocol';
18+
19+
export class CheUserImpl implements CheUser {
20+
21+
private readonly userMain: CheUserMain;
22+
23+
constructor(rpc: RPCProtocol) {
24+
this.userMain = rpc.getProxy(PLUGIN_RPC_CONTEXT.CHE_USER_MAIN);
25+
}
26+
27+
getUserPreferences(filter?: string): Promise<Preferences> {
28+
return this.userMain.$getUserPreferences(filter);
29+
}
30+
31+
updateUserPreferences(update: Preferences): Promise<Preferences> {
32+
return this.userMain.$updateUserPreferences(update);
33+
}
34+
35+
replaceUserPreferences(preferences: Preferences): Promise<Preferences> {
36+
return this.userMain.$replaceUserPreferences(preferences);
37+
}
38+
39+
deleteUserPreferences(list?: string[]): Promise<void> {
40+
return this.userMain.$deleteUserPreferences(list);
41+
}
42+
43+
}

extensions/eclipse-che-theia-plugin/src/che-proposed.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,17 @@ declare module '@eclipse-che/plugin' {
156156
/** Additional task type specific properties. */
157157
readonly [key: string]: any;
158158
}
159+
160+
export namespace user {
161+
export function getUserPreferences(): Promise<Preferences>;
162+
export function getUserPreferences(filter: string | undefined): Promise<Preferences>;
163+
export function updateUserPreferences(update: Preferences): Promise<Preferences>;
164+
export function replaceUserPreferences(preferences: Preferences): Promise<Preferences>;
165+
export function deleteUserPreferences(): Promise<void>;
166+
export function deleteUserPreferences(list: string[] | undefined): Promise<void>;
167+
}
168+
169+
export interface Preferences {
170+
[key: string]: string;
171+
}
159172
}

0 commit comments

Comments
 (0)