Skip to content

Commit

Permalink
feat: Auto-generate launcher configuration when changing game paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ximu3 committed Nov 27, 2024
1 parent 6850de1 commit e123954
Showing 1 changed file with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cn } from '~/utils'
import { useDBSyncedState } from '~/hooks'
import { useDBSyncedState, useGameMedia } from '~/hooks'
import { Card, CardContent, CardHeader, CardTitle } from '@ui/card'
import {
Select,
Expand All @@ -12,10 +12,33 @@ import {
} from '@ui/select'
import { Input } from '@ui/input'
import { Button } from '@ui/button'
import { ipcInvoke } from '~/utils'
import { ipcInvoke, ipcSend } from '~/utils'
import { ArrayTextarea } from '@ui/array-textarea'

export function Path({ gameId }: { gameId: string }): JSX.Element {
const [_path] = useDBSyncedState('', `games/${gameId}/launcher.json`, ['fileConfig', 'path'])
const [_workingDirectory] = useDBSyncedState('', `games/${gameId}/launcher.json`, [
'fileConfig',
'workingDirectory'
])
const [_timerMode] = useDBSyncedState('folder', `games/${gameId}/launcher.json`, [
'fileConfig',
'timerMode'
])
const [_timerPath] = useDBSyncedState('', `games/${gameId}/launcher.json`, [
'fileConfig',
'timerPath'
])
const { mediaUrl: icon, refreshMedia } = useGameMedia({
gameId,
type: 'icon',
noToastError: true
})
const [launcherMode] = useDBSyncedState('file', `games/${gameId}/launcher.json`, ['mode'])
const [timerPath] = useDBSyncedState('', `games/${gameId}/launcher.json`, [
`${launcherMode}Config`,
'timerPath'
])
const [gamePath, setGamePath] = useDBSyncedState('', `games/${gameId}/path.json`, ['gamePath'])
const [saveMode, setSaveMode] = useDBSyncedState('folder', `games/${gameId}/path.json`, [
'savePath',
Expand All @@ -34,8 +57,14 @@ export function Path({ gameId }: { gameId: string }): JSX.Element {
if (!filePath) {
return
}
setGamePath(filePath)
await ipcInvoke('save-game-icon', gameId, filePath)
await setGamePath(filePath)
if (!icon) {
await ipcInvoke('save-game-icon', gameId, filePath)
await refreshMedia()
}
if (!timerPath) {
ipcSend('launcher-preset', 'default', gameId)
}
}
async function selectSaveFolderPath(): Promise<void> {
const folderPath: string[] = await ipcInvoke('select-multiple-path-dialog', ['openDirectory'])
Expand Down

0 comments on commit e123954

Please sign in to comment.