From 8a392c187ffe419c0cba9132f8dddc16eb720999 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 21 Jul 2022 12:19:36 -0500 Subject: [PATCH] Add eslint-plugin-compat --- .eslintrc.js | Bin 7096 -> 7269 bytes .../actions/push_notifications/registerer.ts | 12 ++- app/soapbox/components/error_boundary.tsx | 11 +- app/soapbox/features/audio/index.js | Bin 15917 -> 15963 bytes package.json | 1 + yarn.lock | 97 +++++++++++++++++- 6 files changed, 110 insertions(+), 11 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c140fa5245f51074613d96d0f5368e2b6ea45d45..0ff74336c45b7d3800a2032ac028acb89952f0ec 100644 GIT binary patch delta 182 zcmdmC{?uYZwv2*;dO=QUdS;$ga(-?>Vu^lHDv*(znwOHAvN7!;Q@w&hL4HnUT4qj8 zv6VtJmjW25rxsf!=H#gB!1!sYCCM2Gu4i6JYEf}&a!F=>o_|ttYEfBg5kfYgC_gu| iI29of8svk*2~JHcO3nyKEK1DfEQZR&Zgyral>h*qCN%c| delta 15 XcmaEAvBP{q_Qsw&Oq;(j7fJvCKhFnN diff --git a/app/soapbox/actions/push_notifications/registerer.ts b/app/soapbox/actions/push_notifications/registerer.ts index 893814b025..e66e3a01ac 100644 --- a/app/soapbox/actions/push_notifications/registerer.ts +++ b/app/soapbox/actions/push_notifications/registerer.ts @@ -12,13 +12,19 @@ import type { Me } from 'soapbox/types/soapbox'; const urlBase64ToUint8Array = (base64String: string) => { const padding = '='.repeat((4 - base64String.length % 4) % 4); const base64 = (base64String + padding) - .replace(/\-/g, '+') + .replace(/-/g, '+') .replace(/_/g, '/'); return decodeBase64(base64); }; -const getRegistration = () => navigator.serviceWorker.ready; +const getRegistration = () => { + if (navigator.serviceWorker) { + return navigator.serviceWorker.ready; + } else { + throw 'Your browser does not support Service Workers.'; + } +}; const getPushSubscription = (registration: ServiceWorkerRegistration) => registration.pushManager.getSubscription() @@ -52,6 +58,7 @@ const sendSubscriptionToBackend = (subscription: PushSubscription, me: Me) => }; // Last one checks for payload support: https://web-push-book.gauntface.com/chapter-06/01-non-standards-browsers/#no-payload +// eslint-disable-next-line compat/compat const supportsPushNotifications = ('serviceWorker' in navigator && 'PushManager' in window && 'getKey' in PushSubscription.prototype); const register = () => @@ -112,7 +119,6 @@ const register = () => } }) .catch(error => { - console.error(error); if (error.code === 20 && error.name === 'AbortError') { console.warn('Your browser supports Web Push Notifications, but does not seem to implement the VAPID protocol.'); } else if (error.code === 5 && error.name === 'InvalidCharacterError') { diff --git a/app/soapbox/components/error_boundary.tsx b/app/soapbox/components/error_boundary.tsx index f28fecd0ca..abc051f020 100644 --- a/app/soapbox/components/error_boundary.tsx +++ b/app/soapbox/components/error_boundary.tsx @@ -16,11 +16,12 @@ const goHome = () => location.href = '/'; /** Unregister the ServiceWorker */ // https://stackoverflow.com/a/49771828/8811886 -const unregisterSw = async() => { - if (!navigator.serviceWorker) return; - const registrations = await navigator.serviceWorker.getRegistrations(); - const unregisterAll = registrations.map(r => r.unregister()); - await Promise.all(unregisterAll); +const unregisterSw = async(): Promise => { + if (navigator.serviceWorker) { + const registrations = await navigator.serviceWorker.getRegistrations(); + const unregisterAll = registrations.map(r => r.unregister()); + await Promise.all(unregisterAll); + } }; const mapStateToProps = (state: RootState) => { diff --git a/app/soapbox/features/audio/index.js b/app/soapbox/features/audio/index.js index 2a6732ec93614ecb9816924eb6eab0c31b600196..07edf9eae246d6ec581a8304a898206b5d19588c 100644 GIT binary patch delta 54 zcmZ2mbGv54HhE2beTCHGoXoru-IUDY#H5^5-MrL_5?!E3szP#pZb4#+K7`u5QNBhF E09$kwasU7T delta 12 Tcmcazv$kf#Hu=p@