import React, {useState, useEffect} from "react"; import { dialog } from "@electron/remote"; import { settingList, updateSettings } from "../settings"; import logger from "../logger"; import {blender, blenderCmd} from "../blenderController"; import openFolder from "../openFolder"; import {platformCharacter} from "../paths"; import {getLogTime} from "../logReader"; import {formatDate} from "../dateFormat"; function MainPage() { const [logs, setLogs] = useState(settingList.log); const [output, setOutput] = useState(settingList.output); const [logTable, setLogTable] = useState([]); useEffect(() => { async function getData() { const logList = settingList.log.substring(1).slice(0, -1).split('""'); const logListName:string[] = []; const logListTime:string[] = []; const logListLength:string[] = []; for(const log of logList) { logListName.push(log.split(platformCharacter())[log.split(platformCharacter()).length - 1].replace(".csv", "")); const logTime = await getLogTime(log); const logTimeDisplay = formatDate(logTime.start.year, logTime.start.month, logTime.start.day) + " " + logTime.start.hour + ":" + logTime.start.minute + ":" + logTime.start.second; logListTime.push(logTimeDisplay); let logLengthDisplay = "00:00:00"; if(logTime.length.years > 0) { logLengthDisplay = logTime.length.years + "y " + logTime.length.months + "m " + logTime.length.days + "d " + logTime.length.hours + "h " + logTime.length.minutes + "m " + logTime.length.seconds + "s"; } else if(logTime.length.months > 0) { logLengthDisplay = logTime.length.months + "m " + logTime.length.days + "d " + logTime.length.hours + "h " + logTime.length.minutes + "m " + logTime.length.seconds + "s"; } else if(logTime.length.days > 0) { logLengthDisplay = logTime.length.days + "d " + logTime.length.hours + "h " + logTime.length.minutes + "m " + logTime.length.seconds + "s"; } else { logLengthDisplay = logTime.length.hours + "h " + logTime.length.minutes + "m " + logTime.length.seconds + "s"; } logListLength.push(logLengthDisplay); } setLogTable(logListName.map((log, index) => { return {index+1}. openFolder(logList[index].substring(0, logList[index].lastIndexOf(platformCharacter())))}>{log} ({logListLength[index]}) })); } if(settingList.log == "") { setLogTable([]); } else { getData(); } }, [logs]); return (

Logs:

{logTable}

Output Folder:

openFolder(settingList.output)}>{output}

) } function addLog(updateHook:React.Dispatch>) { dialog.showOpenDialog({ properties: [ "multiSelections" ], filters: [ { name: "TX-Logs", extensions: [ "csv" ] } ] }).then(result => { let logStr = ""; result.filePaths.forEach(value => { const logToAdd = "\"" + value + "\""; if(settingList.log.includes(logToAdd)) { logger.warningMSG("Log " + logToAdd + " already added."); } else { logStr += "\"" + String(value) + "\""; } }); const newLogs = settingList.log + logStr; updateSettings({log:newLogs}); updateHook(newLogs); }).catch(err => { logger.errorMSG(err); }); } function openVid(updateHook:React.Dispatch>) { dialog.showOpenDialog({ properties: [ "openDirectory" ] }).then(result => { if(result.filePaths.length > 0) { updateSettings({output:String(result.filePaths)}); updateHook(String(result.filePaths)); } }).catch(err => { logger.errorMSG(err); }); } export default MainPage;