diff options
author | Sebastian <sebasjm@gmail.com> | 2023-06-02 14:26:28 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-06-02 14:26:28 -0300 |
commit | 1961f4744ca0db4666a2df4335c768ed86fc4e2f (patch) | |
tree | 26d3aa5d7a9d05c84eeb3176061de1a49cf4c5f1 /packages/taler-wallet-webextension/src/platform/chrome.ts | |
parent | 9853f54201cc4c563b7f3b51564eeab54862a223 (diff) | |
download | wallet-core-1961f4744ca0db4666a2df4335c768ed86fc4e2f.tar.xz |
remove deprecated notifications, implement isOffline
Diffstat (limited to 'packages/taler-wallet-webextension/src/platform/chrome.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/platform/chrome.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/packages/taler-wallet-webextension/src/platform/chrome.ts b/packages/taler-wallet-webextension/src/platform/chrome.ts index 0f6b5fb0d..34057a310 100644 --- a/packages/taler-wallet-webextension/src/platform/chrome.ts +++ b/packages/taler-wallet-webextension/src/platform/chrome.ts @@ -58,6 +58,7 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = { sendMessageToBackground, useServiceWorkerAsBackgroundProcess, keepAlive, + listenNetworkConnectionState, }; export default api; @@ -762,3 +763,20 @@ async function findTalerUriInActiveTab(): Promise<string | undefined> { if (!tab || tab.id === undefined) return; return findTalerUriInTab(tab.id); } + +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); + }; +} |