diff --git a/package.json b/package.json index eff05a5..76bf0b7 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "import-pwa": "yarn del-pwa && yarn del-nm-cache && yarn cp-pwa && yarn patch-package @dhis2/pwa", "import-headerbar": "yarn del-headerbar && yarn del-nm-cache && yarn cp-headerbar && yarn patch-package @dhis2-ui/header-bar", "import-plugin": "yarn del-plugin && yarn del-nm-cache && yarn cp-plugin && yarn patch-package @dhis2/app-service-plugin", - "import-offline": "yarn del-offline && yarn del-nm-cache && yarn cp-offline", + "import-offline": "yarn del-offline && yarn del-nm-cache && yarn cp-offline && yarn patch-package @dhis2/app-service-offline", "import-data": "yarn del-data && yarn del-nm-cache && yarn cp-data && yarn patch-package @dhis2/app-service-data" }, "devDependencies": { diff --git a/patches/@dhis2+app-service-offline+3.14.0.patch b/patches/@dhis2+app-service-offline+3.14.0.patch new file mode 100644 index 0000000..028d0de --- /dev/null +++ b/patches/@dhis2+app-service-offline+3.14.0.patch @@ -0,0 +1,78 @@ +diff --git a/node_modules/@dhis2/app-service-offline/build/cjs/lib/dhis2-connection-status/dhis2-connection-status.js b/node_modules/@dhis2/app-service-offline/build/cjs/lib/dhis2-connection-status/dhis2-connection-status.js +index afd68e7..5eed154 100644 +--- a/node_modules/@dhis2/app-service-offline/build/cjs/lib/dhis2-connection-status/dhis2-connection-status.js ++++ b/node_modules/@dhis2/app-service-offline/build/cjs/lib/dhis2-connection-status/dhis2-connection-status.js +@@ -136,21 +136,28 @@ const Dhis2ConnectionStatusProvider = _ref => { + callback: pingAndHandleStatus + }); + smartIntervalRef.current = smartInterval; +- const handleBlur = () => smartInterval.pause(); +- const handleFocus = () => smartInterval.resume(); ++ ++ // Use visibility change instead of focus/blur to continue while focus ++ // might be in iframes ++ const handleVisibilityChange = () => { ++ if (document.visibilityState === 'hidden') { ++ smartInterval.pause(); ++ } else { ++ // visibilityState === 'visible' ++ smartInterval.resume(); ++ } ++ }; + // Pinging when going offline should be low/no-cost in both online and + // local servers + const handleOffline = () => smartInterval.invokeCallbackImmediately(); + // Pinging when going online has a cost but improves responsiveness of + // the connection status -- only do it once every 15 seconds at most + const handleOnline = (0, _lodash.throttle)(() => smartInterval.invokeCallbackImmediately(), 15000); +- window.addEventListener('blur', handleBlur); +- window.addEventListener('focus', handleFocus); ++ document.addEventListener('visibilitychange', handleVisibilityChange); + window.addEventListener('offline', handleOffline); + window.addEventListener('online', handleOnline); + return () => { +- window.removeEventListener('blur', handleBlur); +- window.removeEventListener('focus', handleFocus); ++ document.removeEventListener('visibilitychange', handleVisibilityChange); + window.removeEventListener('offline', handleOffline); + window.removeEventListener('online', handleOnline); + +diff --git a/node_modules/@dhis2/app-service-offline/build/es/lib/dhis2-connection-status/dhis2-connection-status.js b/node_modules/@dhis2/app-service-offline/build/es/lib/dhis2-connection-status/dhis2-connection-status.js +index a7646bf..f7328b4 100644 +--- a/node_modules/@dhis2/app-service-offline/build/es/lib/dhis2-connection-status/dhis2-connection-status.js ++++ b/node_modules/@dhis2/app-service-offline/build/es/lib/dhis2-connection-status/dhis2-connection-status.js +@@ -127,21 +127,28 @@ export const Dhis2ConnectionStatusProvider = _ref => { + callback: pingAndHandleStatus + }); + smartIntervalRef.current = smartInterval; +- const handleBlur = () => smartInterval.pause(); +- const handleFocus = () => smartInterval.resume(); ++ ++ // Use visibility change instead of focus/blur to continue while focus ++ // might be in iframes ++ const handleVisibilityChange = () => { ++ if (document.visibilityState === 'hidden') { ++ smartInterval.pause(); ++ } else { ++ // visibilityState === 'visible' ++ smartInterval.resume(); ++ } ++ }; + // Pinging when going offline should be low/no-cost in both online and + // local servers + const handleOffline = () => smartInterval.invokeCallbackImmediately(); + // Pinging when going online has a cost but improves responsiveness of + // the connection status -- only do it once every 15 seconds at most + const handleOnline = throttle(() => smartInterval.invokeCallbackImmediately(), 15000); +- window.addEventListener('blur', handleBlur); +- window.addEventListener('focus', handleFocus); ++ document.addEventListener('visibilitychange', handleVisibilityChange); + window.addEventListener('offline', handleOffline); + window.addEventListener('online', handleOnline); + return () => { +- window.removeEventListener('blur', handleBlur); +- window.removeEventListener('focus', handleFocus); ++ document.removeEventListener('visibilitychange', handleVisibilityChange); + window.removeEventListener('offline', handleOffline); + window.removeEventListener('online', handleOnline); +