A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: migrate page-visibility.js to typescript (#2166)
Abdulrehman-Jafer167c7125d2d4
diff --git a/apps/web/src/utils/page-visibility.js b/apps/web/src/utils/page-visibility.tssimilarity index 58%rename from apps/web/src/utils/page-visibility.jsrename to apps/web/src/utils/page-visibility.tsindex 50b044640..05a4f8ff6 100644--- a/apps/web/src/utils/page-visibility.js+++ b/apps/web/src/utils/page-visibility.ts@@ -17,37 +17,41 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-var hidden, visibilityChange;-if (typeof document.hidden !== "undefined") {- // Opera 12.10 and Firefox 18 and later support- hidden = "hidden";- visibilityChange = "visibilitychange";-} else if (typeof document.msHidden !== "undefined") {- hidden = "msHidden";- visibilityChange = "msvisibilitychange";-} else if (typeof document.webkitHidden !== "undefined") {- hidden = "webkitHidden";- visibilityChange = "webkitvisibilitychange";+function getVisibilityChangeParams() {+ if ("msHidden" in document) {+ return ["msHidden", "msvisibilityChange"] as const;+ } else if ("webkitHidden" in document) {+ return ["webkitHidden", "webkitvisibilityChange"] as const;+ } else {+ // Opera 12.10 and Firefox 18 and later support+ return ["hidden", "visibilityChange"] as const;+ }}-export function onPageVisibilityChanged(handler) {+export function onPageVisibilityChanged(+ handler: (+ status: "online" | "offline" | "visibilitychange",+ bool: boolean+ ) => void+) {onDeviceOnline(() => handler("online", false));onDeviceOffline(() => handler("offline", false));// Handle page visibility change+ const [hidden, visibilityChange] = getVisibilityChangeParams();document.addEventListener(visibilityChange, () =>- handler("visibilitychange", document[hidden])+ handler("visibilitychange", (document as any)[hidden]));}-function onDeviceOnline(handler) {+function onDeviceOnline(handler: () => void) {window.addEventListener("online", function () {- handler && handler();+ handler();});}-function onDeviceOffline(handler) {+function onDeviceOffline(handler: () => void) {window.addEventListener("offline", function () {- handler && handler();+ handler();});}