From 25a903c89b625b3e59b89ff16acf5425fee925ff Mon Sep 17 00:00:00 2001 From: Andrew Benington Date: Sun, 15 Dec 2024 21:37:06 -0600 Subject: [PATCH] initialize empty box if no boxes present --- src/backend/tauri/tauriBackend.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/backend/tauri/tauriBackend.ts b/src/backend/tauri/tauriBackend.ts index 54d7e1e0..6bbf40c7 100644 --- a/src/backend/tauri/tauriBackend.ts +++ b/src/backend/tauri/tauriBackend.ts @@ -85,8 +85,21 @@ export const TauriBackend: BackendInterface = { }, /* openhome boxes */ - loadHomeBoxes: function (): Promise> { - return TauriInvoker.getStorageFileJSON('box-data.json') as Promise> + loadHomeBoxes: async function (): Promise> { + const result = await (TauriInvoker.getStorageFileJSON('box-data.json') as Promise< + Errorable + >) + + if (E.isLeft(result)) return result + + let boxData = result.right + + if (boxData.length === 0) { + boxData = [{ index: 0, monIdentifiersByIndex: {}, name: undefined }] + TauriInvoker.writeStorageFileJSON('box-data.json', boxData) + } + + return E.right(boxData) }, writeHomeBoxes: (boxData: StoredBoxData[]): Promise> => { return TauriInvoker.writeStorageFileJSON('box-data.json', boxData)