Skip to content

Commit da3a6e5

Browse files
committed
fixed app state update logic
1 parent 22c4891 commit da3a6e5

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/lib/store.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ type DownloadOptionsT = {
77
downloadBatchSize: number;
88
downloadBatchDelay: number;
99
}
10-
export const sourceDownloadOptions = Object.fromEntries(Object.keys(SOURCES).map(s => [
10+
export const getSourceDownloadOptions = (batchSize = 5, batchDelay = 0) => Object.fromEntries(Object.keys(SOURCES).map(s => [
1111
s,
1212
{
13-
downloadBatchSize: s === "novelbin" ? 2 : 5,
14-
downloadBatchDelay: s === "novelbin" ? 1 : 0
13+
downloadBatchSize: s === "novelbin" ? 2 : batchSize,
14+
downloadBatchDelay: s === "novelbin" ? 1 : batchDelay
1515
} satisfies DownloadOptionsT
1616
])) as { [key in SourceIDsT]: DownloadOptionsT };
1717
export type AppStateT = {
@@ -30,7 +30,7 @@ export const appStateAtom = atomWithImmer<AppStateT>({
3030
viewedNotesForVersion: undefined,
3131
isSidePanelOpen: true,
3232
libraryRootPath: "",
33-
sourceDownloadOptions: sourceDownloadOptions
33+
sourceDownloadOptions: getSourceDownloadOptions()
3434
})
3535

3636
export type LibraryStateT = {

src/routes/__root.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AppSidebar } from '@/components/app-sidebar';
44
import { Fragment, useEffect, useState } from 'react';
55
import { load, Store } from '@tauri-apps/plugin-store';
66
import { useAtom, useSetAtom } from 'jotai/react';
7-
import { appStateAtom, AppStateT, downloadStatusAtom, libraryStateAtom, LibraryStateT, sourceDownloadOptions } from '@/lib/store';
7+
import { appStateAtom, AppStateT, downloadStatusAtom, getSourceDownloadOptions, libraryStateAtom, LibraryStateT } from '@/lib/store';
88
import Loader from '@/components/loader';
99
import * as path from '@tauri-apps/api/path';
1010
import { createLibraryDir, saveNovelChapters } from '@/lib/library/library';
@@ -89,10 +89,11 @@ function RootComponent() {
8989
if (!app) app = appState;
9090

9191
if (app.version === 1) {
92-
delete (app as AppStateV1T).downloadBatchSize;
93-
delete (app as AppStateV1T).downloadBatchDelay;
94-
app.viewedNotesForVersion
95-
app.sourceDownloadOptions = sourceDownloadOptions;
92+
const oldApp = app as AppStateV1T;
93+
app.viewedNotesForVersion = undefined;
94+
app.sourceDownloadOptions = getSourceDownloadOptions(oldApp.downloadBatchSize, oldApp.downloadBatchDelay);
95+
delete oldApp.downloadBatchSize;
96+
delete oldApp.downloadBatchDelay;
9697
app.version = 2;
9798
}
9899

0 commit comments

Comments
 (0)