diff options
author | Sebastian <sebasjm@gmail.com> | 2024-05-29 10:13:20 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-05-29 12:00:24 -0300 |
commit | 38c9f87ae471d340fd45b96bb42afb937373324a (patch) | |
tree | 3f64aa251bb12267c3ae64e2d3a0d0b91aa15474 /packages/taler-wallet-webextension/src/platform | |
parent | 4755c83053faaae4879812d41522aeb6b59d098b (diff) | |
download | wallet-core-38c9f87ae471d340fd45b96bb42afb937373324a.tar.xz |
prepare #8767
Diffstat (limited to 'packages/taler-wallet-webextension/src/platform')
-rw-r--r-- | packages/taler-wallet-webextension/src/platform/chrome.ts | 30 | ||||
-rw-r--r-- | packages/taler-wallet-webextension/src/platform/dev.ts | 20 |
2 files changed, 27 insertions, 23 deletions
diff --git a/packages/taler-wallet-webextension/src/platform/chrome.ts b/packages/taler-wallet-webextension/src/platform/chrome.ts index e63040f5c..056351e3f 100644 --- a/packages/taler-wallet-webextension/src/platform/chrome.ts +++ b/packages/taler-wallet-webextension/src/platform/chrome.ts @@ -732,15 +732,35 @@ function listenNetworkConnectionState( function notifyOnline() { notify("on"); } - notify(window.navigator.onLine ? "on" : "off"); - window.addEventListener("offline", notifyOffline); - window.addEventListener("online", notifyOnline); + function notifyChange() { + if (nav.onLine) { + notifyOnline(); + } else { + notifyOnline(); + } + } + notify(navigator.onLine ? "on" : "off"); + + const nav: any = navigator; + if (typeof nav.connection !== "undefined") { + nav.connection.addEventListener("change", notifyChange); + } + if (typeof window !== "undefined") { + window.addEventListener("offline", notifyOffline); + window.addEventListener("online", notifyOnline); + } return () => { - window.removeEventListener("offline", notifyOffline); - window.removeEventListener("online", notifyOnline); + if (typeof nav.connection !== "undefined") { + nav.connection.removeEventListener("change", notifyChange); + } + if (typeof window !== "undefined") { + window.removeEventListener("offline", notifyOffline); + window.removeEventListener("online", notifyOnline); + } }; } + function runningOnPrivateMode(): boolean { return chrome.extension.inIncognitoContext; } diff --git a/packages/taler-wallet-webextension/src/platform/dev.ts b/packages/taler-wallet-webextension/src/platform/dev.ts index d6e743147..b53e8f3c4 100644 --- a/packages/taler-wallet-webextension/src/platform/dev.ts +++ b/packages/taler-wallet-webextension/src/platform/dev.ts @@ -35,11 +35,11 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = { keepAlive: (cb: VoidFunction) => cb(), findTalerUriInActiveTab: async () => undefined, findTalerUriInClipboard: async () => undefined, - listenNetworkConnectionState, + listenNetworkConnectionState: () => () => undefined, openNewURLFromPopup: () => undefined, triggerWalletEvent: () => undefined, setAlertedIcon: () => undefined, - setNormalIcon : () => undefined, + setNormalIcon: () => undefined, getPermissionsApi: () => ({ containsClipboardPermissions: async () => true, removeClipboardPermissions: async () => false, @@ -200,19 +200,3 @@ interface IframeMessageCommand { export default api; -function listenNetworkConnectionState( - notify: (state: "on" | "off") => void, -): () => void { - function notifyOffline() { - notify("off"); - } - function notifyOnline() { - notify("on"); - } - window.addEventListener("offline", notifyOffline); - window.addEventListener("online", notifyOnline); - return () => { - window.removeEventListener("offline", notifyOffline); - window.removeEventListener("online", notifyOnline); - }; -} |