|
1 | 1 | import { Component } from 'preact'; |
2 | 2 | import { Message, MessageType, SetupMessage } from '../types'; |
3 | 3 | import Worker from '../worker?worker' |
4 | | -import { Row, Spinner } from 'react-bootstrap'; |
| 4 | +import { Button, Container, Row, Spinner } from 'react-bootstrap'; |
5 | 5 | import { setAppNavigation } from './Navbar'; |
6 | 6 | import {isDebugMode, secret } from '../utils'; |
7 | 7 | import Median from "median-js-bridge"; |
@@ -117,6 +117,10 @@ class VirtualNetworkInterface { |
117 | 117 | } |
118 | 118 | } |
119 | 119 |
|
| 120 | + downloadPcapLog() { |
| 121 | + this.worker.postMessage("download"); |
| 122 | + } |
| 123 | + |
120 | 124 | // This handles the Message coming from the Charger once the setup is done |
121 | 125 | handleWorkerMessage(e: MessageEvent) { |
122 | 126 | if (typeof e.data === "string") { |
@@ -147,13 +151,17 @@ class VirtualNetworkInterface { |
147 | 151 | break; |
148 | 152 |
|
149 | 153 | case MessageType.FileDownload: |
150 | | - const a = document.createElement("a"); |
151 | 154 | const blob = new Blob([msg.data as Uint8Array]); |
152 | 155 | 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 | + } |
157 | 165 | break; |
158 | 166 |
|
159 | 167 | case MessageType.FetchResponse: |
@@ -250,16 +258,21 @@ export class Frame extends Component<FrameProps, FrameState> { |
250 | 258 | } |
251 | 259 |
|
252 | 260 | 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; |
253 | 266 | return ( |
254 | | - <> |
| 267 | + <Container fluid className="d-flex flex-column h-100 p-0"> |
255 | 268 | <Row hidden={!this.state.show_spinner} className="align-content-center justify-content-center m-0 h-100"> |
256 | 269 | <Spinner className="p-3"animation='border' variant='primary'/> |
257 | 270 | </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> |
263 | 276 | ) |
264 | 277 | } |
265 | 278 | } |
0 commit comments