feat: add game mock

This commit is contained in:
Rodrigo Addor
2025-02-08 21:55:48 -03:00
parent 315d1db163
commit e4a8195674
7 changed files with 47 additions and 12 deletions

2
.gitignore vendored
View File

@@ -22,3 +22,5 @@ dist-ssr
*.njsproj *.njsproj
*.sln *.sln
*.sw? *.sw?
.env

1
mock/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
games.json

View File

@@ -4,7 +4,7 @@
"version": "0.1.0", "version": "0.1.0",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "tauri dev", "dev": "tauri dev --config ./src-tauri/tauri.dev.conf.json",
"build": "tauri build", "build": "tauri build",
"vite:dev": "vite", "vite:dev": "vite",
"vite:build": "tsc && vite build", "vite:build": "tsc && vite build",

View File

@@ -34,14 +34,22 @@
] ]
}, },
{ {
"identifier": "shell:allow-execute", "identifier": "shell:allow-execute",
"allow": [ "allow": [
{ {
"name": "shadps4-emu", "name": "shadps4-emu",
"cmd": "$APPDATA/shadps4-emu.exe", "cmd": "$APPDATA/shadps4-emu.exe",
"args": true "args": true
} }
] ]
},
{
"identifier": "fs:read-files",
"allow": [
{
"path": "$RESOURCE/mock/**/*"
}
]
} }
] ]
} }

View File

@@ -0,0 +1,8 @@
{
"$schema": "https://schema.tauri.app/config/2",
"bundle": {
"resources": {
"../mock/**/*": "resources/mock/"
}
}
}

View File

@@ -1,6 +1,6 @@
import { convertFileSrc } from "@tauri-apps/api/core"; import { convertFileSrc } from "@tauri-apps/api/core";
import { basename, join } from "@tauri-apps/api/path"; import { basename, join, resourceDir } from "@tauri-apps/api/path";
import { exists, readDir } from "@tauri-apps/plugin-fs"; import { exists, readDir, readTextFile } from "@tauri-apps/plugin-fs";
import { atom } from "jotai"; import { atom } from "jotai";
import { pathPreferences } from "./paths"; import { pathPreferences } from "./paths";
@@ -12,6 +12,14 @@ export interface GameEntry {
} }
export const gameLibrary = atom(async (get) => { export const gameLibrary = atom(async (get) => {
if (import.meta.env.VITE_USE_MOCK) {
const data = await readTextFile(
await join(await resourceDir(), "mock/games.json"),
);
return JSON.parse(data) as GameEntry[];
}
const knownPaths: string[] = []; const knownPaths: string[] = [];
async function isGame(path: string) { async function isGame(path: string) {

8
src/vite-env.d.ts vendored
View File

@@ -1 +1,9 @@
/// <reference types="vite/client" /> /// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_USE_MOCK: boolean;
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}