Skip to content

Commit

Permalink
Merge pull request #19 from cohstats/master
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
JohannesMerkt authored Mar 11, 2023
2 parents ef467ec + 160d55b commit 05f1ff3
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "coh3-stats-desktop-app",
"private": true,
"version": "1.0.0",
"version": "1.0.1",
"type": "module",
"scripts": {
"dev": "vite",
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 = "1.0.0"
version = "1.0.1"
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": "1.0.0"
"version": "1.0.1"
},
"tauri": {
"allowlist": {
Expand Down
45 changes: 37 additions & 8 deletions src/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@ import {
Button,
Tooltip,
Checkbox,
Slider,
} from "@mantine/core"
import { appDataDir } from "@tauri-apps/api/path"
import { writeText } from "@tauri-apps/api/clipboard"
import { useEffect, useState } from "react"
import { IconCheck, IconCopy, IconX } from "@tabler/icons-react"
import { IconCheck, IconCopy, IconPlayerPlay, IconX } from "@tabler/icons-react"
import { open } from "@tauri-apps/api/dialog"
import { trySetLogFilePath, useLogFilePath, usePlaySound } from "./configStore"
import {
trySetLogFilePath,
useLogFilePath,
usePlaySound,
usePlaySoundVolume,
} from "./configStore"
import { playSound as playSoundFunc } from "./game-found-sound/playSound"

export const Settings: React.FC = () => {
const logFilePath = useLogFilePath()
const { playSound, setPlaySound } = usePlaySound()
const { playSoundVolume, setPlaySoundVolume } = usePlaySoundVolume()
const [appDataPath, setAppDataPath] = useState<string>("")
useEffect(() => {
const getAppDataPath = async () => {
Expand Down Expand Up @@ -107,12 +115,33 @@ export const Settings: React.FC = () => {
<Group>
<div>Play sound on match found:</div>
<div>
<Checkbox
checked={playSound}
onChange={(event) => {
setPlaySound(event.currentTarget.checked)
}}
/>
<Group>
<Checkbox
checked={playSound}
onChange={(event) => {
setPlaySound(
event.currentTarget.checked
)
}}
/>
<Text>Volume:</Text>
<Slider
min={0}
max={1}
step={0.1}
style={{ width: "100px" }}
value={playSoundVolume}
onChange={setPlaySoundVolume}
/>
<ActionIcon
radius="xl"
variant="filled"
color="blue"
onClick={playSoundFunc}
>
<IconPlayerPlay size="1.125rem" />
</ActionIcon>
</Group>
</div>
</Group>
<Divider />
Expand Down
52 changes: 52 additions & 0 deletions src/configStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { EventEmitter } from "@tauri-apps/api/shell"

const LOG_FILE_PATH_KEY = "logFilePath"
const PLAY_SOUND_KEY = "playSound"
const PLAY_SOUND_VOLUME_KEY = "playSoundVolume"

let CONFIG_STORE: Store | undefined
const CONFIG_CHANGE_EVENT = new EventEmitter()
Expand Down Expand Up @@ -40,6 +41,11 @@ export const getStore: () => Promise<Store> = async () => {
await CONFIG_STORE.set(PLAY_SOUND_KEY, false)
await CONFIG_STORE.save()
}
const hasPlaySoundVolume = await CONFIG_STORE.has(PLAY_SOUND_VOLUME_KEY)
if (!hasPlaySoundVolume) {
await CONFIG_STORE.set(PLAY_SOUND_VOLUME_KEY, 0.8)
await CONFIG_STORE.save()
}
}
return CONFIG_STORE
}
Expand Down Expand Up @@ -158,3 +164,49 @@ export const getPlaySound = async () => {
}
return value
}

export const usePlaySoundVolume = () => {
const [playSoundVolume, setPlaySoundVolume] = useState(0.8)
const valueInitializedRef = useRef(false)

useEffect(() => {
const onChange = (value: number) => {
setPlaySoundVolume(value)
}
const initializeValue = async () => {
const store = await getStore()
const initialValue = await store.get<number>(PLAY_SOUND_VOLUME_KEY)
if (initialValue === null) {
setPlaySoundVolume(0.8)
} else {
setPlaySoundVolume(initialValue)
}
valueInitializedRef.current = true
}
if (valueInitializedRef.current === false) {
initializeValue()
}
CONFIG_CHANGE_EVENT.on(PLAY_SOUND_VOLUME_KEY, onChange)
return () => {
CONFIG_CHANGE_EVENT.off(PLAY_SOUND_VOLUME_KEY, onChange)
}
}, [])

const setPlaySoundInStore = async (value: number) => {
const store = await getStore()
await store.set(PLAY_SOUND_VOLUME_KEY, value)
await store.save()
CONFIG_CHANGE_EVENT.emit(PLAY_SOUND_VOLUME_KEY, value)
}

return { playSoundVolume, setPlaySoundVolume: setPlaySoundInStore }
}

export const getPlaySoundVolume = async () => {
const store = await getStore()
const value = await store.get<number>(PLAY_SOUND_VOLUME_KEY)
if (value === null) {
return 0.8
}
return value
}
4 changes: 2 additions & 2 deletions src/game-data-provider/useFullGameData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { MantineColor } from "@mantine/core"
import { renderStreamerHTML } from "../streamer-overlay/renderStreamerOverlay"
import { getPlaySound, useLogFilePath } from "../configStore"
import { playSound as playSoundFunc } from "../game-found-sound/playSound"

const PLAYER_COLOR_OBJECT: { left: MantineColor[]; right: MantineColor[] } = {
left: ["blue", "blue", "blue", "blue"],
Expand Down Expand Up @@ -141,8 +142,7 @@ export const useFullGameData = () => {
const refineLogFileData = async (rawGameData: RawGameData) => {
const playSound = await getPlaySound()
if (playSound && rawGameData.game_state === "Loading") {
const audio = new Audio("/hoorah.wav")
audio.play()
playSoundFunc()
}
try {
const [leftRefined, rightRefined] = await Promise.all([
Expand Down
7 changes: 7 additions & 0 deletions src/game-found-sound/playSound.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { getPlaySoundVolume } from "../configStore"

export const playSound = async () => {
const audio = new Audio("/hoorah.wav")
audio.volume = await getPlaySoundVolume()
audio.play()
}
8 changes: 5 additions & 3 deletions src/streamer-overlay/OverlayApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ export interface OverlayAppProps {
gameData: FullGameData
}

// gameData.state === "Loading" || gameData.state === "InGame"

export const OverlayApp: React.FC<OverlayAppProps> = ({ gameData }) => {
return (
<>
{gameData.state === "Loading" || gameData.state === "InGame" ? (
{true ? (
<div
style={{
display: "flex",
flexWrap: "wrap",
justifyContent: "flex-start",
alignItems: "stretch",
position: "absolute",
left: "calc(calc(100vw / 2) - 450px)",
right: "calc(calc(100vw / 2) - 450px)",
left: "calc(calc(100vw / 2) - 485px)",
right: "calc(calc(100vw / 2) - 485px)",
top: 65,
}}
>
Expand Down
10 changes: 10 additions & 0 deletions src/streamer-overlay/PlayerEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export const PlayerEntry: React.FC<PlayerEntryProps> = ({ playerData }) => {
height={25}
style={{ paddingRight: 10 }}
/>
<img
src={
"https://raw.githubusercontent.com/cohstats/coh3-stats-desktop-app/master/public/flags/4x3/" +
playerData.country +
".svg"
}
width={25}
height={25}
style={{ paddingRight: 10 }}
/>
<span
style={{
paddingRight: 10,
Expand Down

0 comments on commit 05f1ff3

Please sign in to comment.