Skip to content

Commit

Permalink
initialize empty box if no boxes present
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbenington committed Dec 16, 2024
1 parent bfc223f commit 25a903c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/backend/tauri/tauriBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,21 @@ export const TauriBackend: BackendInterface = {
},

/* openhome boxes */
loadHomeBoxes: function (): Promise<Errorable<StoredBoxData[]>> {
return TauriInvoker.getStorageFileJSON('box-data.json') as Promise<Errorable<StoredBoxData[]>>
loadHomeBoxes: async function (): Promise<Errorable<StoredBoxData[]>> {
const result = await (TauriInvoker.getStorageFileJSON('box-data.json') as Promise<
Errorable<StoredBoxData[]>
>)

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<Errorable<null>> => {
return TauriInvoker.writeStorageFileJSON('box-data.json', boxData)
Expand Down

0 comments on commit 25a903c

Please sign in to comment.