-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathServerConnectionService.ts
More file actions
143 lines (119 loc) · 3.96 KB
/
ServerConnectionService.ts
File metadata and controls
143 lines (119 loc) · 3.96 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* -*- js-indent-level: 8; fill-column: 100 -*- */
/*
* Copyright the Collabora Online contributors.
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* This file contains service which will coordinate operations which
* should happen on server connection changes.
*/
interface ViewSetting {
zoteroAPIKey?: string;
accessibilityState: boolean;
signatureCertificate?: string;
aiConfigured?: boolean;
aiRequestTimeout?: string;
aiModelName?: string;
aiEthicalRating?: string;
}
class ServerConnectionService {
public constructor() {
TileManager.appendAfterFirstTileTask(this.onFirstTileReceived.bind(this));
}
// below methods should be sorted in expected order of execution to help understand the init
public onBasicUI() {
app.console.debug('ServerConnectionService: onBasicUI');
app.tableStyles = new TableStylesService();
}
public onWopiProps(props: {
AIConfigured: boolean;
AIModelName: string;
AIEthicalRating: string;
}) {
app.console.debug('ServerConnectionService: onWopiProps');
if (!app.map) {
app.console.error('ServerConnectionService: missing map reference');
return;
}
app.map.isAIConfigured = !!props.AIConfigured;
app.map.aiModelName = props.AIModelName || '';
app.map.aiEthicalRating = props.AIEthicalRating || 'U';
}
public onViewSetting(viewSetting: ViewSetting) {
app.console.debug('ServerConnectionService: onViewSetting');
if (!app.map) {
app.console.error('ServerConnectionService: missing map reference');
return;
}
app.map.isAIConfigured = !!viewSetting.aiConfigured;
app.map.aiRequestTimeout = viewSetting.aiRequestTimeout
? Math.max(10, Number(viewSetting.aiRequestTimeout))
: 120;
app.map.aiModelName = viewSetting.aiModelName || '';
app.map.aiEthicalRating = viewSetting.aiEthicalRating || 'U';
let zoteroPlugin = app.map.zotero;
const zoteroAPIKey = viewSetting.zoteroAPIKey;
if (
window.zoteroEnabled &&
zoteroAPIKey &&
!zoteroPlugin &&
!window.mode.isSmallScreenDevice()
) {
app.console.debug('ServerConnectionService: initialize Zotero plugin');
zoteroPlugin = window.L.control.zotero(app.map);
zoteroPlugin.apiKey = zoteroAPIKey;
app.map.zotero = zoteroPlugin;
app.map.addControl(zoteroPlugin);
zoteroPlugin.updateUserID();
}
}
public onSpecializedUI(docType: string) {
app.console.debug('ServerConnectionService: onSpecializedUI - ' + docType);
app.map.fire('initializedui');
}
/// see _appLoadedConditions in Map.Wopi.js
public onDocumentLoaded() {
app.console.debug('ServerConnectionService: onDocumentLoaded');
}
public onFirstTileReceived() {
app.console.debug('ServerConnectionService: onFirstTileReceived');
if (!window.mode.isSmallScreenDevice()) {
// show zotero items if needed
const zoteroItems = [
'zoteroaddeditbibliography',
'zoterocontaineradd',
'zoterocontainerrefresh',
'zoteroSetDocPrefs',
'references-zoterosetdocprefs-break',
];
const isWriter = app.map?._docLayer?.isWriter();
if (isWriter && window.zoteroEnabled && app.map.zotero) {
app.console.debug('ServerConnectionService: show UI for zotero');
zoteroItems.forEach((id: string) =>
app.map.uiManager.notebookbar.showItem(id),
);
} else {
app.console.debug('ServerConnectionService: hide UI for zotero');
zoteroItems.forEach((id: string) =>
app.map.uiManager.notebookbar.hideItem(id),
);
}
}
// initialize notebookbar in core
app.map.uiManager.initializeLateComponents();
JSDialog.RefreshScrollables();
}
/// only called the first time the sidebar is shown
public onShowSidebar() {
app.console.debug('ServerConnectionService: onShowSidebar');
app.map._docLayer.recalculateZoomOnResize();
}
public onNotebookbarInCoreInit() {
app.console.debug('ServerConnectionService: onNotebookbarInCoreInit');
}
}