feat: 웹이 앱(웹뷰 셸) 안인지 알아보고 앱 브리지로 구글 로그인·위치·공유를 처리 — user agent NalssigakApp/ 로 감지, 공유 이미지는 JPEG 로 줄여 전달, 앱 안에서는 설치 배너 숨김 (GA app_launch android_app, app_bridge_error, platform android_app)
This commit is contained in:
1 parent
c8287b4bf3
commit
2a94ebe85b
9 files changed
+204
-19
No files matched your search
@@ -4,7 +4,7 @@ import regionPages from '../../seo/region.json'
|
||||
import { nearestRegion } from '@nalssigak/shared/api/client/sdk.gen'
|
||||
import type { RegionData } from '@nalssigak/shared/api/client/types.gen'
|
||||
import { track } from '../lib/analytics'
|
||||
import { IS_TOSS, tossLocation } from '../lib/platform'
|
||||
import { appLocation, IS_APP, IS_TOSS, tossLocation } from '../lib/platform'
|
||||
import { DEFAULT_REGION, ownPage, pageOf, RegionContext, type LocateStatus } from './regionContext'
|
||||
|
||||
const KEY = 'nalssigak.b.region'
|
||||
@@ -50,7 +50,7 @@ export function RegionProvider({ children }: { children: ReactNode }) {
|
||||
const [chosen, setRegionState] = useState<RegionData>(() => (page ? regionIn(page, stored) : (stored ?? DEFAULT_REGION)))
|
||||
// 앱 안에서 다른 지역 페이지로 옮겨 가면 그 지역으로
|
||||
const region = page && !page.regions.some((g) => g.code === chosen.code) ? regionIn(page, stored) : chosen
|
||||
const canLocate = IS_TOSS || (typeof navigator !== 'undefined' && 'geolocation' in navigator)
|
||||
const canLocate = IS_TOSS || IS_APP || (typeof navigator !== 'undefined' && 'geolocation' in navigator)
|
||||
const [locateStatus, setLocateStatus] = useState<LocateStatus>(!landing && (!stored || IS_TOSS) && canLocate ? 'locating' : 'idle')
|
||||
|
||||
// 지역 페이지에서 고르면 주소도 그 지역 페이지로 바꿔, 공유한 링크가 보던 화면과 같게 한다
|
||||
@@ -72,15 +72,17 @@ export function RegionProvider({ children }: { children: ReactNode }) {
|
||||
})
|
||||
.catch(() => !quiet && setLocateStatus('error'))
|
||||
}
|
||||
if (IS_TOSS) {
|
||||
tossLocation(ask).then(
|
||||
// 토스·앱은 웹 위치 대신 호스트(토스 SDK·앱)에 위치를 묻는다
|
||||
if (IS_TOSS || IS_APP) {
|
||||
;(IS_TOSS ? tossLocation(ask) : appLocation(ask)).then(
|
||||
(loc) => {
|
||||
if (loc === null) setLocateStatus('idle')
|
||||
else if (loc === 'denied') setLocateStatus(quiet ? 'idle' : 'denied')
|
||||
else fromCoords(loc.lat, loc.lon)
|
||||
},
|
||||
(e: unknown) => {
|
||||
console.error('[region] toss location', e)
|
||||
console.error('[region] host location', e)
|
||||
if (IS_APP) track('app_bridge_error', { action: 'location' })
|
||||
setLocateStatus(quiet ? 'idle' : 'error')
|
||||
},
|
||||
)
|
||||
@@ -120,12 +122,18 @@ export function RegionProvider({ children }: { children: ReactNode }) {
|
||||
}
|
||||
// 지역 페이지로 들어오면 그 지역을 보여 준다. 구로 나뉜 시는 위치를 이미 허용했고 그 시 안에 있으면 지금 있는 구로
|
||||
if (landing.regions.length < 2) return
|
||||
const adopt = (r: RegionData) => {
|
||||
if (pageRef.current === landing && landing.regions.some((g) => g.code === r.code)) setRegionState(r)
|
||||
}
|
||||
// 앱은 웹의 위치 권한 상태를 알 수 없어, 앱이 이미 허용한 경우에만(ask=false) 앱에 위치를 묻는다
|
||||
if (IS_APP) {
|
||||
findNearest(adopt, true, false)
|
||||
return
|
||||
}
|
||||
navigator.permissions?.query({ name: 'geolocation' })
|
||||
.then((s) => {
|
||||
if (s.state !== 'granted') return
|
||||
findNearest((r) => {
|
||||
if (pageRef.current === landing && landing.regions.some((g) => g.code === r.code)) setRegionState(r)
|
||||
}, true)
|
||||
findNearest(adopt, true)
|
||||
})
|
||||
.catch((e) => console.warn('위치 권한 상태를 읽지 못함', e))
|
||||
}, [canLocate, landing, stored, findNearest, setRegion])
|
||||
|
||||
Reference in new issue
Block a user