Skip to content

Commit a11694e

Browse files
committed
use isTauri in storage.ts
1 parent 40be49f commit a11694e

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/tauri/storage.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } fr
55
import { useTauriContext } from './TauriProvider';
66
// docs: https://github.com/tauri-apps/tauri-plugin-store/blob/dev/webview-src/index.ts
77

8-
const RUNNING_IN_TAURI = window.__TAURI_INTERNALS__ !== undefined;
8+
const RUNNING_IN_TAURI = window.isTauri === true;
99
export const USE_STORE = false && RUNNING_IN_TAURI;
1010
// save data after setState
1111
// https://blog.seethis.link/scan-rate-estimator/
12-
const SAVE_DELAY = 400;
12+
const SAVE_DELAY = 100;
1313

1414
// returns an API to get a item, set an item from a specific category of data
1515
// why? we don't to have loading variable for multiple values
@@ -73,11 +73,7 @@ export function createStorage(storePath: string) {
7373
}
7474
if (newData !== data) {
7575
if (RUNNING_IN_TAURI) {
76-
// avoid spiking disk IO by saving every SAVE_DELAY
77-
fileStoreRef.current!.set('data', newData)
78-
.then(() => {
79-
timeoutRef.current = window.setTimeout(() => fileStoreRef.current!.save(), SAVE_DELAY)
80-
});
76+
fileStoreRef.current!.set('data', newData);
8177
} else {
8278
timeoutRef.current = window.setTimeout(() => localforage.setItem(storePath, newData), SAVE_DELAY);
8379
}

0 commit comments

Comments
 (0)