-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.ts
85 lines (75 loc) · 3.5 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { MonacoEditorUtil } from '@axonivy/inscription-editor';
import { IvyBaseJsonrpcGLSPClient, SwitchThemeActionHandler } from '@axonivy/process-editor';
import { ThemeMode } from '@axonivy/process-editor-protocol';
import { DiagramLoader, EditMode, GLSPActionDispatcher, GLSPWebSocketProvider, MessageAction, StatusAction } from '@eclipse-glsp/client';
import { ApplicationIdProvider, GLSPClient } from '@eclipse-glsp/protocol';
import { Container } from 'inversify';
import { MessageConnection } from 'vscode-jsonrpc';
import createContainer from './di.config';
import './index.css';
import { getParameters, getServerDomain, isReadonly, isSecureConnection } from './url-helper';
const parameters = getParameters();
const app = parameters.get('app') ?? 'designer';
let server = parameters.get('server');
if (!server) {
server = getServerDomain().replace(app, '');
}
const pmv = parameters.get('pmv') ?? '';
const pid = parameters.get('pid') ?? '';
const sourceUri = parameters.get('file') ?? '';
const select = parameters.get('select');
const theme = (parameters.get('theme') as ThemeMode) ?? SwitchThemeActionHandler.prefsColorScheme();
const debug = parameters.has('debug', 'true');
const id = 'ivy-glsp-process';
const diagramType = 'ivy-glsp-process';
const clientId = ApplicationIdProvider.get() + '_' + sourceUri + pid;
const webSocketBase = `${isSecureConnection() ? 'wss' : 'ws'}://${server}/`;
const webSocketUrl = `${webSocketBase}${app}/${id}`;
let glspClient: GLSPClient;
let container: Container;
const wsProvider = new GLSPWebSocketProvider(webSocketUrl);
wsProvider.listen({ onConnection: initialize, onReconnect: reconnect, logger: console });
initMonaco();
async function initialize(connectionProvider: MessageConnection, isReconnecting = false): Promise<void> {
glspClient = new IvyBaseJsonrpcGLSPClient({ id, connectionProvider });
container = createContainer({
clientId,
diagramType,
glspClientProvider: async () => glspClient,
sourceUri,
editMode: isReadonly() ? EditMode.READONLY : EditMode.EDITABLE,
select,
theme,
inscriptionContext: {
app,
pmv,
server: webSocketBase
}
});
const diagramLoader = container.get(DiagramLoader);
await diagramLoader.load({
// Our custom server needs the 'readonly' argument here as well and not only set through the edit mode in the diagram options
requestModelOptions: { isReconnecting, app, pmv, pid, readonly: isReadonly() },
initializeParameters: {
applicationId: ApplicationIdProvider.get(),
protocolVersion: GLSPClient.protocolVersion
}
});
const actionDispatcher = container.get(GLSPActionDispatcher);
if (isReconnecting) {
const message = `Connection to the ${id} glsp server got closed. Connection was successfully re-established.`;
const timeout = 5000;
const severity = 'WARNING';
actionDispatcher.dispatchAll([StatusAction.create(message, { severity, timeout }), MessageAction.create(message, { severity })]);
}
}
async function reconnect(connectionProvider: MessageConnection): Promise<void> {
glspClient.stop();
initialize(connectionProvider, true /* isReconnecting */);
}
async function initMonaco(): Promise<void> {
// packaging with vite has it's own handling of workers so it can be properly accessed
// we therefore import the worker here and use that instead of the default mechanism
const worker = await import('monaco-editor/esm/vs/editor/editor.worker?worker');
MonacoEditorUtil.configureInstance({ theme, debug, worker: { workerConstructor: worker.default } });
}