mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at offline-indicator 63 lines 1.7 kB view raw
1/** 2 * APP-700 3 * 4 * This is a temporary debug setting we're running on the Web build to 5 * help the protocol team test some changes. 6 * 7 * It should be removed in ~2 weeks. It should only be used on the Web 8 * version of the app. 9 */ 10 11import {useState, useCallback} from 'react' 12import {BskyAgent} from '@atproto/api' 13import {isWeb} from 'platform/detection' 14 15export function useDebugHeaderSetting(agent: BskyAgent): [boolean, () => void] { 16 const [enabled, setEnabled] = useState<boolean>(isEnabled()) 17 18 const toggle = useCallback(() => { 19 if (!isWeb || typeof window === 'undefined') { 20 return 21 } 22 if (!enabled) { 23 localStorage.setItem('set-header-x-appview-proxy', 'yes') 24 agent.api.xrpc.setHeader('x-appview-proxy', 'true') 25 setEnabled(true) 26 } else { 27 localStorage.removeItem('set-header-x-appview-proxy') 28 agent.api.xrpc.unsetHeader('x-appview-proxy') 29 setEnabled(false) 30 } 31 }, [setEnabled, enabled, agent]) 32 33 return [enabled, toggle] 34} 35 36export function setDebugHeader(agent: BskyAgent, enabled: boolean) { 37 if (!isWeb || typeof window === 'undefined') { 38 return 39 } 40 if (enabled) { 41 localStorage.setItem('set-header-x-appview-proxy', 'yes') 42 agent.api.xrpc.setHeader('x-appview-proxy', 'true') 43 } else { 44 localStorage.removeItem('set-header-x-appview-proxy') 45 agent.api.xrpc.unsetHeader('x-appview-proxy') 46 } 47} 48 49export function applyDebugHeader(agent: BskyAgent) { 50 if (!isWeb) { 51 return 52 } 53 if (isEnabled()) { 54 agent.api.xrpc.setHeader('x-appview-proxy', 'true') 55 } 56} 57 58function isEnabled() { 59 if (!isWeb || typeof window === 'undefined') { 60 return false 61 } 62 return localStorage.getItem('set-header-x-appview-proxy') === 'yes' 63}