From 495a0900cbd3f24cd5bc1625596cc44c92cf486e Mon Sep 17 00:00:00 2001 From: dumdum7 <95527094+dumdum7@users.noreply.github.com> Date: Sun, 29 Dec 2024 10:33:11 +0100 Subject: [PATCH 1/2] Resync Handy every hour --- ui/v2.5/src/hooks/Interactive/context.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ui/v2.5/src/hooks/Interactive/context.tsx b/ui/v2.5/src/hooks/Interactive/context.tsx index 04c2548ab92..436ed4b6be5 100644 --- a/ui/v2.5/src/hooks/Interactive/context.tsx +++ b/ui/v2.5/src/hooks/Interactive/context.tsx @@ -62,15 +62,17 @@ export const InteractiveContext = React.createContext({ }); const LOCAL_FORAGE_KEY = "interactive"; +const TIME_BETWEEN_SYNCS = 60 * 60 * 1000; // 1 hour interface IInteractiveState { serverOffset: number; + lastSyncTime: number; } export const InteractiveProvider: React.FC = ({ children }) => { const [{ data: config }, setConfig] = useLocalForage( LOCAL_FORAGE_KEY, - { serverOffset: 0 } + { serverOffset: 0, lastSyncTime: 0 } ); const { configuration: stashConfig } = React.useContext(ConfigurationContext); @@ -91,10 +93,14 @@ export const InteractiveProvider: React.FC = ({ children }) => { const initialise = useCallback(async () => { setError(undefined); - if (!config?.serverOffset) { + const shouldResync = + !config?.lastSyncTime || + Date.now() - config?.lastSyncTime > TIME_BETWEEN_SYNCS; + + if (!config?.serverOffset || shouldResync) { setState(ConnectionState.Syncing); const offset = await interactive.sync(); - setConfig({ serverOffset: offset }); + setConfig({ serverOffset: offset, lastSyncTime: Date.now() }); setState(ConnectionState.Ready); setInitialised(true); } else { @@ -159,7 +165,7 @@ export const InteractiveProvider: React.FC = ({ children }) => { setState(ConnectionState.Syncing); const offset = await interactive.sync(); - setConfig({ serverOffset: offset }); + setConfig({ serverOffset: offset, lastSyncTime: Date.now() }); setState(ConnectionState.Ready); }, [interactive, state, setConfig, initialised]); From e17878c4601adc4f56070bd16c9ebeb5ddf00c43 Mon Sep 17 00:00:00 2001 From: dumdum7 <95527094+dumdum7@users.noreply.github.com> Date: Tue, 31 Dec 2024 13:06:49 +0100 Subject: [PATCH 2/2] Don't try to upload script after resync if Handy is disconnected --- ui/v2.5/src/hooks/Interactive/context.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/v2.5/src/hooks/Interactive/context.tsx b/ui/v2.5/src/hooks/Interactive/context.tsx index 436ed4b6be5..a42f0aa7b07 100644 --- a/ui/v2.5/src/hooks/Interactive/context.tsx +++ b/ui/v2.5/src/hooks/Interactive/context.tsx @@ -101,9 +101,9 @@ export const InteractiveProvider: React.FC = ({ children }) => { setState(ConnectionState.Syncing); const offset = await interactive.sync(); setConfig({ serverOffset: offset, lastSyncTime: Date.now() }); - setState(ConnectionState.Ready); - setInitialised(true); - } else { + } + + if (config?.serverOffset) { interactive.setServerTimeOffset(config.serverOffset); setState(ConnectionState.Connecting); try {