This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 441
/
GlobalConfig.ts
185 lines (176 loc) · 6.08 KB
/
GlobalConfig.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v2.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 incorporates work covered by the following copyright and
// permission notice:
//
// Copyright 2018-2021 Cruise LLC
//
// This source code is licensed under the Apache License, Version 2.0,
// found at http://www.apache.org/licenses/LICENSE-2.0
// You may not use this file except in compliance with the License.
import { PersistedState, Store } from "@foxglove-studio/app/reducers";
// We put all the internal requires inside functions, so that when they load the hooks have been properly set.
/* eslint-disable @typescript-eslint/no-var-requires */
let importedPanelsByCategory: unknown;
let importedPerPanelHooks: any;
const defaultHooks = {
areHooksImported: () => importedPanelsByCategory && importedPerPanelHooks,
getLayoutFromUrl: async (search: string) => {
const { LAYOUT_URL_QUERY_KEY } = require("@foxglove-studio/app/util/globalConstants");
const params = new URLSearchParams(search);
const layoutUrl = params.get(LAYOUT_URL_QUERY_KEY);
if (!layoutUrl) {
throw new Error(`Missing query argument: ${LAYOUT_URL_QUERY_KEY}`);
}
return fetch(layoutUrl)
.then((result) => {
try {
return result.json();
} catch (e) {
throw new Error(`Failed to parse JSON layout: ${e.message}`);
}
})
.catch((e) => {
throw new Error(`Failed to fetch layout from URL: ${e.message}`);
});
},
async importHooksAsync() {
return new Promise<void>((resolve, reject) => {
if (importedPanelsByCategory && importedPerPanelHooks) {
resolve();
}
import("./hooksImporter")
.then((hooksImporter) => {
importedPerPanelHooks = hooksImporter.perPanelHooks();
importedPanelsByCategory = hooksImporter.panelsByCategory();
resolve();
})
.catch((reason) => {
reject(`Failed to import hooks bundle: ${reason}`);
});
});
},
nodes: () => [],
getDefaultPersistedState() {
const { defaultPlaybackConfig } = require("@foxglove-studio/app/reducers/panels");
// All panel fields have to be present.
const state: PersistedState = {
fetchedLayout: { isLoading: false, data: undefined },
search: "",
panels: {
layout: {
direction: "row",
first: "DiagnosticSummary!3edblo1",
second: {
direction: "row",
first: "RosOut!1f38b3d",
second: "3D Panel!1my2ydk",
splitPercentage: 50,
},
splitPercentage: 33.3333333333,
},
savedProps: {},
globalVariables: {},
userNodes: {},
linkedGlobalVariables: [],
playbackConfig: defaultPlaybackConfig,
},
};
return state;
},
panelCategories() {
return [
{ label: "ROS", key: "ros" },
{ label: "Utilities", key: "utilities" },
{ label: "Debugging", key: "debugging" },
];
},
panelsByCategory: () => {
if (!importedPanelsByCategory) {
throw new Error("panelsByCategory requested before hooks have been imported");
}
return importedPanelsByCategory;
},
helpPageFootnote: () => null,
perPanelHooks: () => {
if (!importedPerPanelHooks) {
throw new Error("perPanelHooks requested before hooks have been imported");
}
return importedPerPanelHooks;
},
startupPerPanelHooks: () => {
return {
ThreeDimensionalViz: {
getDefaultTopicSettingsByColumn() {
return undefined;
},
getDefaultSettings: () => ({}),
getDefaultTopicTree: () => ({
name: "root",
children: [
{
name: "TF",
topicName: "/tf",
children: [],
description: "Visualize relationships between /tf frames.",
},
],
}),
getStaticallyAvailableNamespacesByTopic: () => ({}),
},
};
},
load: async () => {
const { initializeLogEvent } = require("@foxglove-studio/app/util/logEvent");
initializeLogEvent(() => undefined, {}, {});
},
getAdditionalDataProviders: () => {
// do nothing
},
experimentalFeaturesList() {
return {
diskBagCaching: {
name: "Disk Bag Caching (requires reload)",
description:
"When streaming bag data, persist it on disk, so that when reloading the page we don't have to download the data again. However, this might result in an overall slower experience, and is generally experimental, so we only recommend it if you're on a slow network connection. Alternatively, you can download the bag to disk manually, and drag it into Webviz.",
developmentDefault: false,
productionDefault: false,
},
unlimitedMemoryCache: {
name: "Unlimited in-memory cache (requires reload)",
description:
"If you have a lot of memory in your computer, and you frequently have to play all the way through large bags, you can turn this on to fully buffer the bag into memory. However, use at your own risk, as this might crash the browser.",
developmentDefault: false,
productionDefault: false,
},
};
},
linkMessagePathSyntaxToHelpPage: () => true,
getSecondSourceUrlParams() {
const { REMOTE_BAG_URL_2_QUERY_KEY } = require("@foxglove-studio/app/util/globalConstants");
return [REMOTE_BAG_URL_2_QUERY_KEY];
},
updateUrlToTrackLayoutChanges: async (_opt: { store: Store; skipPatch: boolean }) => {
// Persist the layout state in URL or remote storage if needed.
await Promise.resolve();
},
getPoseErrorScaling() {
const scaling = {
x: 1,
y: 1,
};
return { originalScaling: scaling, updatedScaling: scaling };
},
};
let hooks = defaultHooks;
export function getGlobalConfig() {
return hooks;
}
export function setGlobalConfig(hooksToSet: Record<string, unknown>) {
hooks = { ...hooks, ...hooksToSet };
}
export function resetGlobalConfigToDefault() {
hooks = defaultHooks;
}