Skip to content

Commit

Permalink
Merge pull request #14 from cohstats/master
Browse files Browse the repository at this point in the history
Fix log file watching + Add auto update functionality
  • Loading branch information
JohannesMerkt authored Mar 4, 2023
2 parents 590f946 + 6b34ca4 commit 5e4076e
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 86 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "coh3-stats-desktop-app",
"private": true,
"version": "0.0.7",
"version": "0.0.8",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -12,8 +12,8 @@
},
"dependencies": {
"@emotion/react": "^11.10.6",
"@mantine/core": "^5.10.4",
"@mantine/hooks": "^5.10.4",
"@mantine/core": "^6.0.0",
"@mantine/hooks": "^6.0.0",
"@tauri-apps/api": "^1.2.0",
"axios": "^1.3.4",
"coh-stats-components": "github:cohstats/coh-stats-components#0.0.7",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "coh3-stats-desktop-app"
version = "0.0.7"
version = "0.0.8"
description = "A Tauri App"
authors = ["you"]
license = ""
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "Coh3 Stats Desktop App",
"version": "0.0.7"
"version": "0.0.8"
},
"tauri": {
"allowlist": {
Expand Down
1 change: 0 additions & 1 deletion src/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const Game: React.FC = () => {
<>
{gameData.logFileFound ? (
<>
<Button onClick={gameData.reloadLogFile}>Reload</Button>
{gameData.gameData.map.length > 0 ? (
<>
<Grid gutter={0}>
Expand Down
5 changes: 1 addition & 4 deletions src/game-data-provider/useFullGameData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export const useFullGameData = () => {
const {
logFilePath,
rawGameData,
setInterval,
setLogFilePath,
interval,
logFileFound,
reloadLogFile,
} = useRawGameData()
Expand Down Expand Up @@ -68,6 +66,7 @@ export const useFullGameData = () => {
)
)
)
console.log("FETCH DATA")
let mergedResponses = responses.map((response, index) => ({
response,
relicID: onlyRealPlayers[index].relic_id,
Expand Down Expand Up @@ -187,9 +186,7 @@ export const useFullGameData = () => {
}, [logFilePath, rawGameData])

return {
setInterval,
setLogFilePath,
interval,
logFilePath,
rawGameData,
gameData,
Expand Down
62 changes: 17 additions & 45 deletions src/game-data-provider/useRawGameData.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import React, {
useContext,
useEffect,
useCallback,
useState,
useRef,
} from "react"
import React, { useEffect, useState } from "react"
import { invoke } from "@tauri-apps/api/tauri"
import { watch } from "tauri-plugin-fs-watch-api"
import { RawGameData } from "./GameData"
import { UnlistenFn } from "@tauri-apps/api/event"
import { useInterval } from "@mantine/hooks"

/** This hook handles the collection of raw game data from the log file */
export const useRawGameData = () => {
const [logFilePath, setExistingLogFilePath] = useState<string>()
const stopWatcherRef = useRef<UnlistenFn>()
const [interval, setInterval] = useState(200) // default log file checking interval is 2 seconds
const [rawGameData, setRawGameData] = useState<RawGameData>()
const getLogFileData = async (path: string) => {
const data = (await invoke("parse_log_file_reverse", {
path,
})) as RawGameData
setRawGameData(data)
}
const interval = useInterval(() => {
console.log("Check log file")
if (logFilePath !== undefined) {
getLogFileData(logFilePath)
}
}, 2000)

const setLogFilePath = async (logFilePath: string) => {
const result = (await invoke("check_log_file_exists", {
Expand All @@ -37,52 +40,21 @@ export const useRawGameData = () => {
getDefaultLogFilePath()
}
}, [logFilePath])
const getLogFileData = async (path: string) => {
const data = (await invoke("parse_log_file_reverse", {
path,
})) as RawGameData
setRawGameData(data)
}

const reloadLogFile = () => {
if (logFilePath) {
if (logFilePath !== undefined) {
getLogFileData(logFilePath)
}
}
// when log file exists start watching the log file
useEffect(() => {
const recreateWatcher = async (path: string) => {
if (stopWatcherRef.current) {
await stopWatcherRef.current()
stopWatcherRef.current = undefined
}
getLogFileData(path)
const newStopWatcher = await watch(
path,
{
//delayMs: interval
},
() => {
console.log("log file updated")
getLogFileData(path)
}
)
stopWatcherRef.current = newStopWatcher
}
if (logFilePath !== undefined) {
recreateWatcher(logFilePath)
interval.start()
}
}, [logFilePath, interval])
// used to change the interval the log file is checked
const setValidatedInterval = useCallback((interval: number) => {
if (interval > 0) {
setInterval(interval)
}
}, [])
return {
setInterval: setValidatedInterval,
setLogFilePath: setLogFilePath,
logFilePath,
interval,
rawGameData,
logFileFound: logFilePath !== undefined,
reloadLogFile,
Expand Down
11 changes: 0 additions & 11 deletions updater.json

This file was deleted.

104 changes: 85 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -481,34 +481,35 @@
"@jridgewell/resolve-uri" "3.1.0"
"@jridgewell/sourcemap-codec" "1.4.14"

"@mantine/core@^5.10.4":
version "5.10.5"
resolved "https://registry.yarnpkg.com/@mantine/core/-/core-5.10.5.tgz#071e14dcf8b94a36d0243f1f4b30305ac0074afd"
integrity sha512-F4tqHSEVM9D6/iSqHfPda+Xl5XgSEPHAAkT01Zwzj4Jnbd10qGrlqr/SFUop2CIcuKYnmra9XltUahUPXBC2BQ==
"@mantine/core@^6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@mantine/core/-/core-6.0.0.tgz#721bca646713b50dc2d7fa1e538fbd409526c33e"
integrity sha512-ik2NUAAn9fYcqmOAluGtI9R73ijrr450dZDA+MezKq/dvpUU/Fhl9yXnGoCxxZ5XF6y4i6q07318rdrVturc9w==
dependencies:
"@floating-ui/react" "^0.19.1"
"@mantine/styles" "5.10.5"
"@mantine/utils" "5.10.5"
"@mantine/styles" "6.0.0"
"@mantine/utils" "6.0.0"
"@radix-ui/react-scroll-area" "1.0.2"
react-remove-scroll "^2.5.5"
react-textarea-autosize "8.3.4"

"@mantine/hooks@^5.10.4":
version "5.10.5"
resolved "https://registry.yarnpkg.com/@mantine/hooks/-/hooks-5.10.5.tgz#568586a0fa649be46f057ddc920bf98761017ffb"
integrity sha512-hFQp71QZDfivPzfIUOQZfMKLiOL/Cn2EnzacRlbUr55myteTfzYN8YMt+nzniE/6c4IRopFHEAdbKEtfyQc6kg==
"@mantine/hooks@^6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@mantine/hooks/-/hooks-6.0.0.tgz#08b67946e0b45f67181efa9e37df68f92a8ee6d1"
integrity sha512-boszkajLaA4qvd/ebDhqZBbMuUXlvJv8EM0jTaXz09IaGPachBKG5WKpXEcwWh2qmrUQL6pyhIbLMgPnvwS0QQ==

"@mantine/styles@5.10.5":
version "5.10.5"
resolved "https://registry.yarnpkg.com/@mantine/styles/-/styles-5.10.5.tgz#ace82a71b4fe3d14ee14638f1735d5680d93d36d"
integrity sha512-0NXk8c/XGzuTUkZc6KceF2NaTCMEu5mHR4ru0x+ttb9DGnLpHuGWduTHjSfr4hl6eAJgedD0zauO+VAhDzO9zA==
"@mantine/styles@6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@mantine/styles/-/styles-6.0.0.tgz#71b0b7d9c1885070543206b754cac82cbe763fda"
integrity sha512-TyqFvdKIhbhnGYBDEJ9QIPit4NzyzQ3ivDfdzeqzd/cJBxFPhxB0sEFU8RppXpXBUlbhLFhulYFEVl2pP6zaeg==
dependencies:
clsx "1.1.1"
csstype "3.0.9"

"@mantine/utils@5.10.5":
version "5.10.5"
resolved "https://registry.yarnpkg.com/@mantine/utils/-/utils-5.10.5.tgz#ad620d714e545c6efb7f69d94ce46e3fd2fe01fb"
integrity sha512-FGMq4dGs5HhDAtI0z46uzxzKKPmZ3h5uKUyKg1ZHoFR1mBtcUMbB6FylFmHqKFRWlJ5IXqX9dwmiVrLYUOfTmA==
"@mantine/utils@6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@mantine/utils/-/utils-6.0.0.tgz#26b6b89e27a77340d571a1c41a879a8344417742"
integrity sha512-1AalSgzINKP4uv1DBTkJe/jh6yGwC2xaCQE4Atlr2bSHiLezYFMy/deGQ8XLFFv2AL0sjvewLW4ernlFujGMZg==

"@radix-ui/[email protected]":
version "1.0.0"
Expand Down Expand Up @@ -855,6 +856,11 @@ delayed-stream@~1.0.0:
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==

detect-node-es@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/detect-node-es/-/detect-node-es-1.1.0.tgz#163acdf643330caa0b4cd7c21e7ee7755d6fa493"
integrity sha512-ypdmJU/TbBby2Dxibuv7ZLW3Bs1QEmM7nHjEANfohJLvE0XVujisn1qPJcZxg+qDucsr+bP6fLD1rPS3AhJ7EQ==

electron-to-chromium@^1.4.251:
version "1.4.284"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.284.tgz#61046d1e4cab3a25238f6bf7413795270f125592"
Expand Down Expand Up @@ -944,6 +950,11 @@ gensync@^1.0.0-beta.2:
resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0"
integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==

get-nonce@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/get-nonce/-/get-nonce-1.0.1.tgz#fdf3f0278073820d2ce9426c18f07481b1e0cdf3"
integrity sha512-FJhYRoDaiatfEkUK8HKlicmu/3SGFD51q3itKDGoSTysQJBnfOcxU5GxnhE1E6soB76MbT0MBtnKJuXyAx+96Q==

globals@^11.1.0:
version "11.12.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
Expand Down Expand Up @@ -976,6 +987,13 @@ import-fresh@^3.2.1:
parent-module "^1.0.0"
resolve-from "^4.0.0"

invariant@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
dependencies:
loose-envify "^1.0.0"

is-arrayish@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
Expand Down Expand Up @@ -1013,7 +1031,7 @@ lines-and-columns@^1.1.6:
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz#eca284f75d2965079309dc0ad9255abb2ebc1632"
integrity sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==

loose-envify@^1.1.0:
loose-envify@^1.0.0, loose-envify@^1.1.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
Expand Down Expand Up @@ -1123,6 +1141,25 @@ react-refresh@^0.14.0:
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.14.0.tgz#4e02825378a5f227079554d4284889354e5f553e"
integrity sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ==

react-remove-scroll-bar@^2.3.3:
version "2.3.4"
resolved "https://registry.yarnpkg.com/react-remove-scroll-bar/-/react-remove-scroll-bar-2.3.4.tgz#53e272d7a5cb8242990c7f144c44d8bd8ab5afd9"
integrity sha512-63C4YQBUt0m6ALadE9XV56hV8BgJWDmmTPY758iIJjfQKt2nYwoUrPk0LXRXcB/yIj82T1/Ixfdpdk68LwIB0A==
dependencies:
react-style-singleton "^2.2.1"
tslib "^2.0.0"

react-remove-scroll@^2.5.5:
version "2.5.5"
resolved "https://registry.yarnpkg.com/react-remove-scroll/-/react-remove-scroll-2.5.5.tgz#1e31a1260df08887a8a0e46d09271b52b3a37e77"
integrity sha512-ImKhrzJJsyXJfBZ4bzu8Bwpka14c/fQt0k+cyFp/PBhTfyDnU5hjOtM4AG/0AMyy8oKzOTR0lDgJIM7pYXI0kw==
dependencies:
react-remove-scroll-bar "^2.3.3"
react-style-singleton "^2.2.1"
tslib "^2.1.0"
use-callback-ref "^1.3.0"
use-sidecar "^1.1.2"

react-router-dom@^6.4.5:
version "6.4.5"
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.4.5.tgz#4fdb12efef4f3848c693a76afbeaed1f6ca02047"
Expand All @@ -1138,6 +1175,15 @@ [email protected]:
dependencies:
"@remix-run/router" "1.0.5"

react-style-singleton@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/react-style-singleton/-/react-style-singleton-2.2.1.tgz#f99e420492b2d8f34d38308ff660b60d0b1205b4"
integrity sha512-ZWj0fHEMyWkHzKYUr2Bs/4zU6XLmq9HsgBURm7g5pAVfyn49DgUiNgY2d4lXRlYSiCif9YBGpQleewkcqddc7g==
dependencies:
get-nonce "^1.0.0"
invariant "^2.2.4"
tslib "^2.0.0"

[email protected]:
version "8.3.4"
resolved "https://registry.yarnpkg.com/react-textarea-autosize/-/react-textarea-autosize-8.3.4.tgz#270a343de7ad350534141b02c9cb78903e553524"
Expand Down Expand Up @@ -1240,6 +1286,11 @@ tslib@^2.0.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.1.tgz#0d0bfbaac2880b91e22df0768e55be9753a5b17e"
integrity sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==

tslib@^2.1.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf"
integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==

typescript@^4.9.3:
version "4.9.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.4.tgz#a2a3d2756c079abda241d75f149df9d561091e78"
Expand All @@ -1253,6 +1304,13 @@ update-browserslist-db@^1.0.9:
escalade "^3.1.1"
picocolors "^1.0.0"

use-callback-ref@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/use-callback-ref/-/use-callback-ref-1.3.0.tgz#772199899b9c9a50526fedc4993fc7fa1f7e32d5"
integrity sha512-3FT9PRuRdbB9HfXhEq35u4oZkvpJ5kuYbpqhCfmiZyReuRgpnhDlbr2ZEnnuS0RrJAPn6l23xjFg9kpDM+Ms7w==
dependencies:
tslib "^2.0.0"

use-composed-ref@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/use-composed-ref/-/use-composed-ref-1.3.0.tgz#3d8104db34b7b264030a9d916c5e94fbe280dbda"
Expand All @@ -1270,6 +1328,14 @@ use-latest@^1.2.1:
dependencies:
use-isomorphic-layout-effect "^1.1.1"

use-sidecar@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/use-sidecar/-/use-sidecar-1.1.2.tgz#2f43126ba2d7d7e117aa5855e5d8f0276dfe73c2"
integrity sha512-epTbsLuzZ7lPClpz2TyryBfztm7m+28DlEv2ZCQ3MDr5ssiwyOwGH/e5F9CkfWjJ1t4clvI58yF822/GUkjjhw==
dependencies:
detect-node-es "^1.1.0"
tslib "^2.0.0"

vite@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/vite/-/vite-4.0.1.tgz#e0a54d818c28ae47fd27bcac6a4a952c6a658502"
Expand Down

0 comments on commit 5e4076e

Please sign in to comment.