This repository has been archived by the owner on Mar 24, 2024. It is now read-only.
/
App.tsx
75 lines (65 loc) · 2.72 KB
/
App.tsx
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
// 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/
import { useEffect, useState } from "react";
import { OsContextSingleton } from "@foxglove-studio/app/OsContext";
import { FileContext } from "@foxglove-studio/app/components/FileContext";
import Root from "@foxglove-studio/app/components/Root";
import { usePrompt } from "@foxglove-studio/app/hooks/usePrompt";
import { ROSBRIDGE_WEBSOCKET_URL_QUERY_KEY } from "@foxglove-studio/app/util/globalConstants";
function App() {
const [bagFile, setBagFile] = useState<File | undefined>();
const [isFullScreen, setFullScreen] = useState(false);
const prompt = usePrompt();
useEffect(() => {
OsContextSingleton?.addWindowEventListener("enter-full-screen", () => setFullScreen(true));
OsContextSingleton?.addWindowEventListener("leave-full-screen", () => setFullScreen(false));
}, []);
useEffect(() => {
OsContextSingleton?.installMenuHandlers({
"file.open-bag": () => {
// The main thread simulated a mouse click for us which allows us to invoke input.click();
// The idea is to move handling of opening the file to the renderer thread
const input = document.createElement("input");
input.setAttribute("type", "file");
input.setAttribute("accept", ".bag");
input.addEventListener(
"input",
() => {
if (input.files?.length && input.files.length > 0) {
setBagFile(input.files[0]);
}
},
{ once: true },
);
input.click();
},
"file.open-websocket-url": async () => {
const result = await prompt("ws://localhost:9090");
// Note(roman): Architecturally we should move the param handling out of nested components
// like PlayerManager and feed in the data providers via context or up-tree components
// This would simplify PlayerManager and add flexibility to the app at a more appropriate level
// of abstraction.
if (result) {
const params = new URLSearchParams(window.location.search);
params.set(ROSBRIDGE_WEBSOCKET_URL_QUERY_KEY, result);
window.location.search = params.toString();
}
},
});
}, [prompt]);
return (
<>
<FileContext.Provider value={bagFile}>
<Root
onToolbarDoubleClick={OsContextSingleton?.handleToolbarDoubleClick}
windowStyle={
OsContextSingleton?.platform === "darwin" ? "standaloneWithTopLeftButtons" : "normal"
}
isFullScreen={isFullScreen}
/>
</FileContext.Provider>
</>
);
}
export { App };