fix i think

This commit is contained in:
ruban 2024-05-03 05:25:11 +00:00
parent 52312dbd23
commit 4cd94370e8

View File

@ -95,22 +95,29 @@ export const useSyncStore = createPersistStore(
const provider = get().provider; const provider = get().provider;
const config = get()[provider]; const config = get()[provider];
const client = this.getClient(); const client = this.getClient();
try { try {
const remoteState = JSON.parse( const remoteState = await client.get(config.username);
await client.get(config.username), if (!remoteState || remoteState === "") {
) as AppState; console.log("[Sync] Remote state is empty, using local state instead.");
mergeAppState(localState, remoteState); return
setLocalAppState(localState); } else {
const parsedRemoteState = JSON.parse(
await client.get(config.username),
) as AppState;
mergeAppState(localState, parsedRemoteState);
setLocalAppState(localState);
}
} catch (e) { } catch (e) {
console.log("[Sync] failed to get remote state", e); console.log("[Sync] failed to get remote state", e);
throw e; throw e;
} }
await client.set(config.username, JSON.stringify(localState)); await client.set(config.username, JSON.stringify(localState));
this.markSyncTime(); this.markSyncTime();
}, },
async check() { async check() {
const client = this.getClient(); const client = this.getClient();