Skip to content

Commit 3becf54

Browse files
fix: file watchers not checking if folder exists
1 parent b035488 commit 3becf54

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
33
"productName": "shadps4-launcher",
4-
"version": "0.2.0",
4+
"version": "0.2.1",
55
"identifier": "net.shadps4.app",
66
"build": {
77
"beforeDevCommand": "bun vite:dev",

src/store/game-library.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import { convertFileSrc } from "@tauri-apps/api/core";
22
import { BaseDirectory, basename, join } from "@tauri-apps/api/path";
3-
import { exists, readDir, readTextFile, watch } from "@tauri-apps/plugin-fs";
3+
import {
4+
exists,
5+
mkdir,
6+
readDir,
7+
readTextFile,
8+
watch,
9+
} from "@tauri-apps/plugin-fs";
410
import { atom } from "jotai";
511
import { type PSF, readPsf } from "@/lib/native/psf";
612
import { defaultStore, type JotaiStore } from ".";
713
import { atomGamesPath } from "./paths";
14+
import { toast } from "sonner";
15+
import { stringifyError } from "@/utils/error";
816

917
export interface GameEntry {
1018
path: string;
@@ -114,16 +122,22 @@ export function refreshGameLibrary(s: JotaiStore) {
114122
}
115123

116124
(() => {
117-
let unsub: Promise<() => void> | undefined;
118-
defaultStore.sub(atomGamesPath, () => {
119-
unsub?.then((e) => e());
125+
let unsub: (() => void) | undefined;
126+
defaultStore.sub(atomGamesPath, async () => {
127+
unsub?.();
120128
unsub = undefined;
121129

122-
const path = defaultStore.get(atomGamesPath);
123-
if (path) {
124-
unsub = watch(path, () => {
125-
refreshGameLibrary(defaultStore);
126-
});
130+
try {
131+
const path = defaultStore.get(atomGamesPath);
132+
if (path) {
133+
await mkdir(path, { recursive: true});
134+
unsub = await watch(path, () => {
135+
refreshGameLibrary(defaultStore);
136+
});
137+
}
138+
} catch (e: unknown) {
139+
console.error(e)
140+
toast.error("Error watching games path: " + stringifyError(e));
127141
}
128142
});
129143
})();

src/store/version-manager.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { join } from "@tauri-apps/api/path";
2-
import { exists, readDir, watch } from "@tauri-apps/plugin-fs";
2+
import { exists, mkdir, readDir, watch } from "@tauri-apps/plugin-fs";
33
import { platform } from "@tauri-apps/plugin-os";
44
import { atom } from "jotai";
55
import { unwrap } from "jotai/utils";
66
import { atomWithQuery } from "jotai-tanstack-query";
77
import { Octokit } from "octokit";
8+
import { toast } from "sonner";
89
import { readConfig } from "@/handlers/version-manager";
10+
import { stringifyError } from "@/utils/error";
911
import { atomWithTauriStore } from "@/utils/jotai/tauri-store";
1012
import { defaultStore, type JotaiStore } from ".";
1113
import { oficialRepo } from "./common";
@@ -188,16 +190,22 @@ export const atomInstalledVersions = atom(async (get) => {
188190
});
189191

190192
(() => {
191-
let unsub: Promise<() => void> | undefined;
192-
defaultStore.sub(atomEmuInstallsPath, () => {
193-
unsub?.then((e) => e());
193+
let unsub: (() => void) | undefined;
194+
defaultStore.sub(atomEmuInstallsPath, async () => {
195+
unsub?.();
194196
unsub = undefined;
195197

196-
const path = defaultStore.get(atomEmuInstallsPath);
197-
if (path) {
198-
unsub = watch(path, () => {
199-
refreshInstalledVersion(defaultStore);
200-
});
198+
try {
199+
const path = defaultStore.get(atomEmuInstallsPath);
200+
if (path) {
201+
await mkdir(path, { recursive: true });
202+
unsub = await watch(path, () => {
203+
refreshInstalledVersion(defaultStore);
204+
});
205+
}
206+
} catch (e: unknown) {
207+
console.error(e);
208+
toast.error("Error watching install path: " + stringifyError(e));
201209
}
202210
});
203211
})();

0 commit comments

Comments
 (0)