diff options
author | Ansh <anshnanda10@gmail.com> | 2023-08-23 16:28:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-23 16:28:51 -0700 |
commit | 8ab5eb6583b6ddd4ed03ef2b1a55ef83fa0c0625 (patch) | |
tree | 06ab22c1f0faf121f1de89247ccc43bf353408c7 /src/lib/api/debug-appview-proxy-header.ts | |
parent | 32b9648931589311667423ce377ee42a1c78a84f (diff) | |
download | voidsky-8ab5eb6583b6ddd4ed03ef2b1a55ef83fa0c0625.tar.zst |
[APP-786] Native notifications (#1095)
* move `notifee.ts` to notifications folder * install expo notifications * add UIBackgroundMode `remote-notifications` to app.json * fix notifee import in Debug.tsx * add `google-services.json` * add `development-device` class to eas.json * Add `notifications.ts` for native notification handling * send push token to server * update `@atproto/api` * fix putting notif token to server * fix how push token is uploaded * fix lint * enable debug appview proxy header on all platforms * setup `notifications.ts` to work with app view notifs * clean up notification handler * add comments * update packages to correct versions * remove notifee * clean up code a lil * rename push token endpoint * remove unnecessary comments * fix comments * Remove old background scheduler * Fixes to push notifications API use * Bump @atproto/api@0.6.6 --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>
Diffstat (limited to 'src/lib/api/debug-appview-proxy-header.ts')
-rw-r--r-- | src/lib/api/debug-appview-proxy-header.ts | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/src/lib/api/debug-appview-proxy-header.ts b/src/lib/api/debug-appview-proxy-header.ts index 39890b7c3..7571bd37f 100644 --- a/src/lib/api/debug-appview-proxy-header.ts +++ b/src/lib/api/debug-appview-proxy-header.ts @@ -8,23 +8,30 @@ * version of the app. */ -import {useState, useCallback} from 'react' +import {useState, useCallback, useEffect} from 'react' import {BskyAgent} from '@atproto/api' import {isWeb} from 'platform/detection' +import * as Storage from 'lib/storage' export function useDebugHeaderSetting(agent: BskyAgent): [boolean, () => void] { - const [enabled, setEnabled] = useState<boolean>(isEnabled()) + const [enabled, setEnabled] = useState<boolean>(false) - const toggle = useCallback(() => { - if (!isWeb || typeof window === 'undefined') { - return + useEffect(() => { + async function check() { + if (await isEnabled()) { + setEnabled(true) + } } + check() + }, []) + + const toggle = useCallback(() => { if (!enabled) { - localStorage.setItem('set-header-x-appview-proxy', 'yes') + Storage.saveString('set-header-x-appview-proxy', 'yes') agent.api.xrpc.setHeader('x-appview-proxy', 'true') setEnabled(true) } else { - localStorage.removeItem('set-header-x-appview-proxy') + Storage.remove('set-header-x-appview-proxy') agent.api.xrpc.unsetHeader('x-appview-proxy') setEnabled(false) } @@ -34,30 +41,24 @@ export function useDebugHeaderSetting(agent: BskyAgent): [boolean, () => void] { } export function setDebugHeader(agent: BskyAgent, enabled: boolean) { - if (!isWeb || typeof window === 'undefined') { - return - } if (enabled) { - localStorage.setItem('set-header-x-appview-proxy', 'yes') + Storage.saveString('set-header-x-appview-proxy', 'yes') agent.api.xrpc.setHeader('x-appview-proxy', 'true') } else { - localStorage.removeItem('set-header-x-appview-proxy') + Storage.remove('set-header-x-appview-proxy') agent.api.xrpc.unsetHeader('x-appview-proxy') } } -export function applyDebugHeader(agent: BskyAgent) { +export async function applyDebugHeader(agent: BskyAgent) { if (!isWeb) { return } - if (isEnabled()) { + if (await isEnabled()) { agent.api.xrpc.setHeader('x-appview-proxy', 'true') } } -function isEnabled() { - if (!isWeb || typeof window === 'undefined') { - return false - } - return localStorage.getItem('set-header-x-appview-proxy') === 'yes' +async function isEnabled() { + return (await Storage.loadString('set-header-x-appview-proxy')) === 'yes' } |