Skip to content

Commit ecb288a

Browse files
committed
frontend/frame: add download button when in debugMode.
1 parent 4416ff4 commit ecb288a

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

frontend/src/components/Frame.tsx

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component } from 'preact';
22
import { Message, MessageType, SetupMessage } from '../types';
33
import Worker from '../worker?worker'
4-
import { Row, Spinner } from 'react-bootstrap';
4+
import { Button, Container, Row, Spinner } from 'react-bootstrap';
55
import { setAppNavigation } from './Navbar';
66
import {isDebugMode, secret } from '../utils';
77
import Median from "median-js-bridge";
@@ -117,6 +117,10 @@ class VirtualNetworkInterface {
117117
}
118118
}
119119

120+
downloadPcapLog() {
121+
this.worker.postMessage("download");
122+
}
123+
120124
// This handles the Message coming from the Charger once the setup is done
121125
handleWorkerMessage(e: MessageEvent) {
122126
if (typeof e.data === "string") {
@@ -147,13 +151,17 @@ class VirtualNetworkInterface {
147151
break;
148152

149153
case MessageType.FileDownload:
150-
const a = document.createElement("a");
151154
const blob = new Blob([msg.data as Uint8Array]);
152155
const url = URL.createObjectURL(blob)
153-
a.href = url;
154-
a.download = "out.pcap";
155-
a.target = "_blank";
156-
a.click();
156+
if (Median.isNativeApp()) {
157+
Median.share.downloadFile({url: url, filename: "out.pcap"});
158+
} else {
159+
const a = document.createElement("a");
160+
a.href = url;
161+
a.download = "out.pcap";
162+
a.target = "_blank";
163+
a.click();
164+
}
157165
break;
158166

159167
case MessageType.FetchResponse:
@@ -250,16 +258,21 @@ export class Frame extends Component<FrameProps, FrameState> {
250258
}
251259

252260
render() {
261+
const downLoadButton = isDebugMode.value ? <Row className="d-flex">
262+
<Button variant='secondary' class="btn" onClick={() => {
263+
this.interface.downloadPcapLog();
264+
}}>Download Pcap log</Button>
265+
</Row> : null;
253266
return (
254-
<>
267+
<Container fluid className="d-flex flex-column h-100 p-0">
255268
<Row hidden={!this.state.show_spinner} className="align-content-center justify-content-center m-0 h-100">
256269
<Spinner className="p-3"animation='border' variant='primary'/>
257270
</Row>
258-
<iframe hidden={this.state.show_spinner} width="100%" height="100%" id="interface"></iframe>
259-
{/* <button onClick={() => {
260-
this.worker.postMessage("download");
261-
}}>Download Pcap log</button> */}
262-
</>
271+
<Row className="flex-grow-1">
272+
<iframe hidden={this.state.show_spinner} width="100%" height="100%" id="interface"></iframe>
273+
</Row>
274+
{downLoadButton}
275+
</Container>
263276
)
264277
}
265278
}

0 commit comments

Comments
 (0)