diff --git a/webapp/.gitignore b/.gitignore similarity index 94% rename from webapp/.gitignore rename to .gitignore index 3ad579c..e6f9227 100644 --- a/webapp/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ node_modules/ # production /build +/dist/win-unpacked # misc .DS_Store diff --git a/client/.prettierrc b/.prettierrc similarity index 100% rename from client/.prettierrc rename to .prettierrc diff --git a/.rescriptsrc.js b/.rescriptsrc.js new file mode 100644 index 0000000..62f02c6 --- /dev/null +++ b/.rescriptsrc.js @@ -0,0 +1 @@ +module.exports = [require.resolve("./.webpack.config.js")]; diff --git a/.webpack.config.js b/.webpack.config.js new file mode 100644 index 0000000..d9bd475 --- /dev/null +++ b/.webpack.config.js @@ -0,0 +1,4 @@ +module.exports = config => { + config.target = "electron-renderer"; + return config; +}; diff --git a/client/.gitignore b/client/.gitignore deleted file mode 100644 index 975ba35..0000000 --- a/client/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules/ -yarn.lock \ No newline at end of file diff --git a/client/index.js b/client/index.js deleted file mode 100644 index cbae8c5..0000000 --- a/client/index.js +++ /dev/null @@ -1,73 +0,0 @@ -const app = require("express")(); -const http = require("http").createServer(app); -const server = require("socket.io")(http); - -const { F1TelemetryClient, constants } = require("f1-telemetry-client"); -const F1Telemetry = new F1TelemetryClient({ bigintEnabled: false }); - -const { PACKETS } = constants; - -let playerCarId = null; - -server.on("connection", socket => { - console.log("New client connected"); - - socket.on("lapData", data => { - server.sockets.emit("lapData", data); - }); - socket.on("playerCarId", data => { - server.sockets.emit("playerCarId", data); - }); - socket.on("carStatus", data => { - server.sockets.emit("carStatus", data); - }); - socket.on("carTelemetry", data => { - server.sockets.emit("carTelemetry", data); - }); - socket.on("session", data => { - server.sockets.emit("session", data); - }); -}); - -const io = require("socket.io-client"); -const client = io.connect("http://localhost:4000"); - -F1Telemetry.on(PACKETS.participants, data => { - if (data && data.m_header.m_playerCarIndex !== playerCarId) { - playerCarId = data.m_header.m_playerCarIndex; - client.emit("playerCarId", data.m_header.m_playerCarIndex); - console.log("Player car id: " + playerCarId); - } -}); - -let currentLap, currentSector; -F1Telemetry.on(PACKETS.lapData, data => { - if (playerCarId !== null) { - if ( - data.m_lapData[playerCarId].m_currentLapNum !== currentLap || - data.m_lapData[playerCarId].m_sector !== currentSector - ) { - client.emit("lapData", data.m_lapData[playerCarId]); - currentLap = data.m_lapData[playerCarId].m_currentLapNum; - currentSector = data.m_lapData[playerCarId].m_sector; - } - } -}); - -F1Telemetry.on(PACKETS.carStatus, data => { - if (playerCarId !== null) { - client.emit("carStatus", data.m_carStatusData[playerCarId]); - } -}); - -F1Telemetry.on(PACKETS.carTelemetry, data => { - if (playerCarId !== null) { - client.emit("carTelemetry", data.m_carTelemetryData[playerCarId]); - } -}); - -F1Telemetry.on(PACKETS.session, data => client.emit("session", data)); - -F1Telemetry.start(); - -http.listen(4000); diff --git a/client/package.json b/client/package.json deleted file mode 100644 index 6e21121..0000000 --- a/client/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "telemetry-client", - "version": "1.0.0", - "description": "", - "main": "index.js", - "author": "LucasSonego", - "license": "MIT", - "scripts": { - "start": "node index.js" - }, - "dependencies": { - "express": "^4.17.1", - "f1-telemetry-client": "^0.1.18", - "socket.io": "^2.3.0" - } -} diff --git a/dist/.icon-ico/icon.ico b/dist/.icon-ico/icon.ico new file mode 100644 index 0000000..3db58ea Binary files /dev/null and b/dist/.icon-ico/icon.ico differ diff --git a/dist/F1 Better Telemetry Setup 1.0.0.exe b/dist/F1 Better Telemetry Setup 1.0.0.exe new file mode 100644 index 0000000..f9089ad Binary files /dev/null and b/dist/F1 Better Telemetry Setup 1.0.0.exe differ diff --git a/dist/F1 Better Telemetry Setup 1.0.0.exe.blockmap b/dist/F1 Better Telemetry Setup 1.0.0.exe.blockmap new file mode 100644 index 0000000..84b6411 Binary files /dev/null and b/dist/F1 Better Telemetry Setup 1.0.0.exe.blockmap differ diff --git a/dist/builder-effective-config.yaml b/dist/builder-effective-config.yaml new file mode 100644 index 0000000..9186cd2 --- /dev/null +++ b/dist/builder-effective-config.yaml @@ -0,0 +1,16 @@ +directories: + output: dist + buildResources: build +appId: f1-better-telemetry-by-lucassonego +productName: F1 Better Telemetry +copyright: 'Copyright © 2021 ${author}' +mac: + category: public.app-category.utilities +extends: null +extraMetadata: + main: main.js +files: + - filter: + - '**/*' + - build +electronVersion: 11.2.0 diff --git a/dist/latest.yml b/dist/latest.yml new file mode 100644 index 0000000..cb9e47a --- /dev/null +++ b/dist/latest.yml @@ -0,0 +1,8 @@ +version: 1.0.0 +files: + - url: F1-Better-Telemetry-Setup-1.0.0.exe + sha512: 81+bPquRFfHXWDytOzbDBS48YY8IozcP8HXyZzaErZ9v0V2rH62WPqYqMSat3Yb5aO3kbYmDMf+hBQBc8nMAxg== + size: 81809167 +path: F1-Better-Telemetry-Setup-1.0.0.exe +sha512: 81+bPquRFfHXWDytOzbDBS48YY8IozcP8HXyZzaErZ9v0V2rH62WPqYqMSat3Yb5aO3kbYmDMf+hBQBc8nMAxg== +releaseDate: '2021-01-21T18:58:39.090Z' diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..96fedb4 Binary files /dev/null and b/icon.png differ diff --git a/main.js b/main.js new file mode 100644 index 0000000..59c2ac0 --- /dev/null +++ b/main.js @@ -0,0 +1,45 @@ +require("./telemetryClient")(); + +const electron = require("electron"); +const app = electron.app; +const BrowserWindow = electron.BrowserWindow; +const path = require("path"); +const isDev = require("electron-is-dev"); + +let mainWindow; + +function createWindow() { + mainWindow = new BrowserWindow({ + width: 1200, + height: 650, + minHeight: 650, + minWidth: 1200, + frame: false, + webPreferences: { + nodeIntegration: true, + enableRemoteModule: true, + }, + icon: __dirname + "/icon.png", + }); + mainWindow.loadURL( + isDev + ? "http://localhost:3000" + : `file://${path.join(__dirname, "./build/index.html")}` + ); + // mainWindow.webContents.openDevTools(); + mainWindow.on("closed", () => (mainWindow = null)); +} + +app.on("ready", createWindow); + +app.on("window-all-closed", () => { + if (process.platform !== "darwin") { + app.quit(); + } +}); + +app.on("activate", () => { + if (mainWindow === null) { + createWindow(); + } +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..f854c07 --- /dev/null +++ b/package.json @@ -0,0 +1,83 @@ +{ + "name": "f1-better-telemetry", + "version": "1.0.0", + "description": "Live telemetry from Codemasters F1 game", + "author": { + "name": "Lucas Sônego", + "email": "sonego_lucas@outlook.com", + "url": "https://github.com/LucasSonego" + }, + "private": false, + "license": "MIT", + "homepage": "./", + "dependencies": { + "@testing-library/jest-dom": "^5.11.4", + "@testing-library/react": "^11.1.0", + "@testing-library/user-event": "^12.1.10", + "cross-env": "^7.0.3", + "express": "^4.17.1", + "f1-telemetry-client": "^0.1.18", + "react": "^17.0.1", + "react-dom": "^17.0.1", + "react-icons": "^3.11.0", + "react-scripts": "4.0.0", + "socket.io": "^2.3.0", + "socket.io-client": "^2.3.1", + "styled-components": "^5.2.1", + "web-vitals": "^0.2.4", + "electron-is-dev": "^1.2.0" + }, + "devDependencies": { + "electron": "^11.2.0", + "@rescripts/cli": "^0.0.15", + "@rescripts/rescript-env": "^0.0.12", + "concurrently": "^5.3.0", + "electron-builder": "^22.9.1", + "wait-on": "^5.2.1" + }, + "main": "main.js", + "build": { + "appId": "f1-better-telemetry-by-lucassonego", + "productName": "F1 Better Telemetry", + "copyright": "Copyright © 2021 ${author}", + "mac": { + "category": "public.app-category.utilities" + }, + "extends": null, + "extraMetadata": { + "main": "main.js" + }, + "files": [ + "**/*", + "build" + ] + }, + "scripts": { + "react-start": "rescripts start", + "react-build": "rescripts build", + "react-test": "rescripts test --env=jsdom", + "react-eject": "react-scripts eject", + "electron-build": "electron-builder", + "release": "yarn react-build && electron-builder --publish=always", + "build": "yarn react-build && yarn electron-build", + "start": "concurrently \"cross-env BROWSER=none yarn react-start\" \"wait-on http://localhost:3000 && electron .\"" + }, + "eslintConfig": { + "extends": [ + "react-app", + "react-app/jest" + ] + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/webapp/public/favicon.ico b/public/favicon.ico similarity index 100% rename from webapp/public/favicon.ico rename to public/favicon.ico diff --git a/webapp/public/index.html b/public/index.html similarity index 100% rename from webapp/public/index.html rename to public/index.html diff --git a/webapp/public/logo192.png b/public/logo192.png similarity index 100% rename from webapp/public/logo192.png rename to public/logo192.png diff --git a/webapp/public/logo512.png b/public/logo512.png similarity index 100% rename from webapp/public/logo512.png rename to public/logo512.png diff --git a/webapp/src/App.js b/src/App.js similarity index 68% rename from webapp/src/App.js rename to src/App.js index bb9d453..92c47c5 100644 --- a/webapp/src/App.js +++ b/src/App.js @@ -2,10 +2,11 @@ import React, { useEffect, useState } from "react"; import io from "socket.io-client"; import Fonts from "./fonts"; -import { Container } from "./styles"; +import { Container, Content } from "./styles"; import LapData from "./Components/LapData"; import CarData from "./Components/CarData"; import SessionData from "./Components/SessionData"; +import TitleBar from "./Components/TitleBar"; const telemetry = io.connect("http://localhost:4000"); @@ -29,12 +30,15 @@ function App() { return ( - - - + + + + + + ); } diff --git a/webapp/src/Components/Car/index.jsx b/src/Components/Car/index.jsx similarity index 100% rename from webapp/src/Components/Car/index.jsx rename to src/Components/Car/index.jsx diff --git a/webapp/src/Components/Car/styles.js b/src/Components/Car/styles.js similarity index 100% rename from webapp/src/Components/Car/styles.js rename to src/Components/Car/styles.js diff --git a/webapp/src/Components/CarData/index.jsx b/src/Components/CarData/index.jsx similarity index 100% rename from webapp/src/Components/CarData/index.jsx rename to src/Components/CarData/index.jsx diff --git a/webapp/src/Components/CarData/styles.js b/src/Components/CarData/styles.js similarity index 92% rename from webapp/src/Components/CarData/styles.js rename to src/Components/CarData/styles.js index 88feda3..7562cef 100644 --- a/webapp/src/Components/CarData/styles.js +++ b/src/Components/CarData/styles.js @@ -3,7 +3,7 @@ import styled from "styled-components"; export const Container = styled.div` .car { padding: 0 20px; - height: 100vh; + height: 100%; display: flex; justify-content: center; align-items: center; diff --git a/webapp/src/Components/LapData/index.jsx b/src/Components/LapData/index.jsx similarity index 100% rename from webapp/src/Components/LapData/index.jsx rename to src/Components/LapData/index.jsx diff --git a/webapp/src/Components/LapData/styles.js b/src/Components/LapData/styles.js similarity index 98% rename from webapp/src/Components/LapData/styles.js rename to src/Components/LapData/styles.js index 45bfed7..4f3bff2 100644 --- a/webapp/src/Components/LapData/styles.js +++ b/src/Components/LapData/styles.js @@ -9,8 +9,8 @@ export const Container = styled.div` grid-gap: 10px; grid-auto-rows: min-content; color: #fff; - height: 100vh; - max-height: 100vh; + height: 100%; + max-height: 100%; overflow-y: scroll; /* width */ diff --git a/webapp/src/Components/SessionData/SessionType/index.jsx b/src/Components/SessionData/SessionType/index.jsx similarity index 100% rename from webapp/src/Components/SessionData/SessionType/index.jsx rename to src/Components/SessionData/SessionType/index.jsx diff --git a/webapp/src/Components/SessionData/SessionType/styles.js b/src/Components/SessionData/SessionType/styles.js similarity index 100% rename from webapp/src/Components/SessionData/SessionType/styles.js rename to src/Components/SessionData/SessionType/styles.js diff --git a/webapp/src/Components/SessionData/Weather/index.jsx b/src/Components/SessionData/Weather/index.jsx similarity index 100% rename from webapp/src/Components/SessionData/Weather/index.jsx rename to src/Components/SessionData/Weather/index.jsx diff --git a/webapp/src/Components/SessionData/Weather/styles.js b/src/Components/SessionData/Weather/styles.js similarity index 100% rename from webapp/src/Components/SessionData/Weather/styles.js rename to src/Components/SessionData/Weather/styles.js diff --git a/webapp/src/Components/SessionData/index.jsx b/src/Components/SessionData/index.jsx similarity index 100% rename from webapp/src/Components/SessionData/index.jsx rename to src/Components/SessionData/index.jsx diff --git a/webapp/src/Components/SessionData/styles.js b/src/Components/SessionData/styles.js similarity index 100% rename from webapp/src/Components/SessionData/styles.js rename to src/Components/SessionData/styles.js diff --git a/src/Components/TitleBar/index.jsx b/src/Components/TitleBar/index.jsx new file mode 100644 index 0000000..3fd046d --- /dev/null +++ b/src/Components/TitleBar/index.jsx @@ -0,0 +1,42 @@ +import React from "react"; +import { remote } from "electron"; + +import { + VscClose, + VscChromeMaximize, + VscChromeMinimize, +} from "react-icons/vsc"; +import { Container } from "./styles"; + +function TitleBar() { + return ( + + F1 Better Telemetry +
+ + + +
+
+ ); +} + +export default TitleBar; diff --git a/src/Components/TitleBar/styles.js b/src/Components/TitleBar/styles.js new file mode 100644 index 0000000..562e36d --- /dev/null +++ b/src/Components/TitleBar/styles.js @@ -0,0 +1,60 @@ +import styled from "styled-components"; + +export const Container = styled.div` + display: flex; + align-items: center; + justify-content: space-between; + height: 30px; + width: 100%; + background-color: #ffffff07; + -webkit-app-region: drag; + + span { + color: #ffffff77; + font-size: 14px; + margin-left: 15px; + } + + button { + -webkit-app-region: none; + } + + .controls { + button { + background: #ffffff04; + border: none; + outline: none; + height: 30px; + width: 40px; + padding: 0; + + .button-content { + display: flex; + align-items: center; + justify-content: center; + } + + .minimize, + .maximize { + color: #fffa; + height: 15px; + width: 15px; + } + + .close { + color: #fffa; + height: 17px; + width: 17px; + } + + transition: 0.3s; + &:hover { + background: #fff1; + + .close { + color: #e74c3c; + } + } + } + } +`; diff --git a/webapp/src/assets/Car/chassis.svg b/src/assets/Car/chassis.svg similarity index 100% rename from webapp/src/assets/Car/chassis.svg rename to src/assets/Car/chassis.svg diff --git a/webapp/src/assets/Car/engine.svg b/src/assets/Car/engine.svg similarity index 100% rename from webapp/src/assets/Car/engine.svg rename to src/assets/Car/engine.svg diff --git a/webapp/src/assets/Car/frontWing.svg b/src/assets/Car/frontWing.svg similarity index 100% rename from webapp/src/assets/Car/frontWing.svg rename to src/assets/Car/frontWing.svg diff --git a/webapp/src/assets/Car/gearbox.svg b/src/assets/Car/gearbox.svg similarity index 100% rename from webapp/src/assets/Car/gearbox.svg rename to src/assets/Car/gearbox.svg diff --git a/webapp/src/assets/brakeIcon.svg b/src/assets/brakeIcon.svg similarity index 100% rename from webapp/src/assets/brakeIcon.svg rename to src/assets/brakeIcon.svg diff --git a/webapp/src/assets/engineIcon.svg b/src/assets/engineIcon.svg similarity index 100% rename from webapp/src/assets/engineIcon.svg rename to src/assets/engineIcon.svg diff --git a/webapp/src/assets/gearboxIcon.svg b/src/assets/gearboxIcon.svg similarity index 100% rename from webapp/src/assets/gearboxIcon.svg rename to src/assets/gearboxIcon.svg diff --git a/webapp/src/exampleData/LapData.js b/src/exampleData/LapData.js similarity index 100% rename from webapp/src/exampleData/LapData.js rename to src/exampleData/LapData.js diff --git a/webapp/src/exampleData/carStatus.js b/src/exampleData/carStatus.js similarity index 100% rename from webapp/src/exampleData/carStatus.js rename to src/exampleData/carStatus.js diff --git a/webapp/src/exampleData/carTelemetry.js b/src/exampleData/carTelemetry.js similarity index 100% rename from webapp/src/exampleData/carTelemetry.js rename to src/exampleData/carTelemetry.js diff --git a/webapp/src/fonts/Formula1-Bold.woff b/src/fonts/Formula1-Bold.woff similarity index 100% rename from webapp/src/fonts/Formula1-Bold.woff rename to src/fonts/Formula1-Bold.woff diff --git a/webapp/src/fonts/Formula1-Regular.woff b/src/fonts/Formula1-Regular.woff similarity index 100% rename from webapp/src/fonts/Formula1-Regular.woff rename to src/fonts/Formula1-Regular.woff diff --git a/webapp/src/fonts/index.js b/src/fonts/index.js similarity index 100% rename from webapp/src/fonts/index.js rename to src/fonts/index.js diff --git a/webapp/src/index.css b/src/index.css similarity index 100% rename from webapp/src/index.css rename to src/index.css diff --git a/webapp/src/index.js b/src/index.js similarity index 100% rename from webapp/src/index.js rename to src/index.js diff --git a/webapp/src/styles.js b/src/styles.js similarity index 50% rename from webapp/src/styles.js rename to src/styles.js index 022d2d7..fae8e52 100644 --- a/webapp/src/styles.js +++ b/src/styles.js @@ -1,5 +1,10 @@ import styled from "styled-components"; export const Container = styled.div` + height: 100vh; +`; + +export const Content = styled.div` display: flex; + height: calc(100vh - 30px); `; diff --git a/telemetryClient.js b/telemetryClient.js new file mode 100644 index 0000000..1716941 --- /dev/null +++ b/telemetryClient.js @@ -0,0 +1,75 @@ +module.exports = () => { + const express = require("express")(); + const http = require("http").createServer(express); + const server = require("socket.io")(http); + + const { F1TelemetryClient, constants } = require("f1-telemetry-client"); + const F1Telemetry = new F1TelemetryClient({ bigintEnabled: false }); + + const { PACKETS } = constants; + + let playerCarId = null; + + server.on("connection", socket => { + console.log("New client connected"); + + socket.on("lapData", data => { + server.sockets.emit("lapData", data); + }); + socket.on("playerCarId", data => { + server.sockets.emit("playerCarId", data); + }); + socket.on("carStatus", data => { + server.sockets.emit("carStatus", data); + }); + socket.on("carTelemetry", data => { + server.sockets.emit("carTelemetry", data); + }); + socket.on("session", data => { + server.sockets.emit("session", data); + }); + }); + + const io = require("socket.io-client"); + const client = io.connect("http://localhost:4000"); + + F1Telemetry.on(PACKETS.participants, data => { + if (data && data.m_header.m_playerCarIndex !== playerCarId) { + playerCarId = data.m_header.m_playerCarIndex; + client.emit("playerCarId", data.m_header.m_playerCarIndex); + console.log("Player car id: " + playerCarId); + } + }); + + let currentLap, currentSector; + F1Telemetry.on(PACKETS.lapData, data => { + if (playerCarId !== null) { + if ( + data.m_lapData[playerCarId].m_currentLapNum !== currentLap || + data.m_lapData[playerCarId].m_sector !== currentSector + ) { + client.emit("lapData", data.m_lapData[playerCarId]); + currentLap = data.m_lapData[playerCarId].m_currentLapNum; + currentSector = data.m_lapData[playerCarId].m_sector; + } + } + }); + + F1Telemetry.on(PACKETS.carStatus, data => { + if (playerCarId !== null) { + client.emit("carStatus", data.m_carStatusData[playerCarId]); + } + }); + + F1Telemetry.on(PACKETS.carTelemetry, data => { + if (playerCarId !== null) { + client.emit("carTelemetry", data.m_carTelemetryData[playerCarId]); + } + }); + + F1Telemetry.on(PACKETS.session, data => client.emit("session", data)); + + F1Telemetry.start(); + + http.listen(4000); +}; diff --git a/webapp/.prettierrc b/webapp/.prettierrc deleted file mode 100644 index 6e9f691..0000000 --- a/webapp/.prettierrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "arrowParens": "avoid", - "bracketSpacing": true, - "endOfLine": "lf", - "jsxSingleQuote": false, - "quoteProps": "as-needed", - "printWidth": 80, - "singleQuote": false, - "semi": true, - "trailingComma": "es5", - "tabWidth": 2, - "useTabs": false -} diff --git a/webapp/package.json b/webapp/package.json deleted file mode 100644 index 6b67941..0000000 --- a/webapp/package.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "f1-telemetry", - "version": "0.1.0", - "private": true, - "dependencies": { - "@testing-library/jest-dom": "^5.11.4", - "@testing-library/react": "^11.1.0", - "@testing-library/user-event": "^12.1.10", - "f1-telemetry-client": "^0.1.18", - "react": "^17.0.1", - "react-dom": "^17.0.1", - "react-icons": "^3.11.0", - "react-scripts": "4.0.0", - "socket.io-client": "^2.3.1", - "styled-components": "^5.2.1", - "web-vitals": "^0.2.4" - }, - "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" - }, - "eslintConfig": { - "extends": [ - "react-app", - "react-app/jest" - ] - }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - } -}