|
1 | 1 | import { ipcMain, dialog } from "electron"; |
2 | 2 | import fs from "fs"; |
| 3 | +import path from "path"; |
3 | 4 | import { parseFlightLog } from "./logparser.js" |
4 | 5 | import { exportFlightLogToCSVs } from "./flightlog.js" |
5 | 6 | import { connect, disconnect, command, cliCommand, getList } from "./serial.js"; |
@@ -74,17 +75,16 @@ export function subscribeListeners() { |
74 | 75 | event.sender.send("EXPORT_FLIGHTLOG_CSVS"); |
75 | 76 | }); |
76 | 77 |
|
77 | | - ipcMain.on("EXPORT_FLIGHTLOG_HTML", (event, flightLogHtmlStr) => { |
| 78 | + ipcMain.on("EXPORT_FLIGHTLOG_HTML", (event, flightLog, useImperialUnits) => { |
| 79 | + const flightlogJson = JSON.stringify(flightLog); |
| 80 | + const useImperialUnitsString = String(true); |
78 | 81 |
|
79 | | - flightLogHtmlStr = ` |
80 | | - <!DOCTYPE html> |
81 | | - <html> |
82 | | - <head> |
83 | | - <script src="https://cdn.plot.ly/plotly-2.18.2.min.js"></script> |
84 | | - </head> |
85 | | - <body> |
86 | | - ` + flightLogHtmlStr + "</body></html>" |
87 | | - fs.writeFile("plots.html", flightLogHtmlStr, 'utf8', function (err) { |
| 82 | + let plotsHTML = fs.readFileSync(path.join(__dirname, '../templates/plots.html'), 'utf8'); |
| 83 | + |
| 84 | + plotsHTML = plotsHTML.replace("/* FLIGHTLOG_PLACEHOLDER */", flightlogJson); |
| 85 | + plotsHTML = plotsHTML.replace("/* USE_IMPERIAL_UNITS_PLACEHOLDER */", useImperialUnitsString); |
| 86 | + |
| 87 | + fs.writeFile("plots.html", plotsHTML, 'utf8', function (err) { |
88 | 88 | if (err) { |
89 | 89 | console.log("An error occurred while writing CSV Object to File."); |
90 | 90 | return console.log(err); |
|
0 commit comments