diff --git a/.env b/.env index e066840..3032f25 100644 --- a/.env +++ b/.env @@ -1,4 +1,7 @@ SERVER_URL="https://nerimity.com" +DEFAULT_URL="https://nerimity.com" +LATEST_URL="https://latest.nerimity.com" +DEV_URL="http://local.nerimity.com:3000" DEV_MODE="true" TURNSTILE_SITEKEY="0x4AAAAAAABO1ilip_YaVHJk" EMOJI_URL="https://nerimity.com/twemojis/" diff --git a/.github/workflows/build-apk.yml b/.github/workflows/build-apk.yml index 6ecc23b..5c99e7a 100644 --- a/.github/workflows/build-apk.yml +++ b/.github/workflows/build-apk.yml @@ -31,6 +31,9 @@ jobs: uses: SpicyPizza/create-envfile@v1.3 with: envkey_SERVER_URL: "https://nerimity.com" + envkey_DEFAULT_URL: "https://nerimity.com" + envkey_LATEST_URL: "https://latest.nerimity.com" + envkey_DEV_URL: "http://local.nerimity.com:3000" envkey_DEV_MODE: "false" envkey_APP_VERSION: "dev" envkey_TURNSTILE_SITEKEY: "0x4AAAAAAABO1ilip_YaVHJk" diff --git a/App.tsx b/App.tsx index 45286e2..160c83a 100644 --- a/App.tsx +++ b/App.tsx @@ -1,5 +1,6 @@ import React, {useCallback, useEffect, useRef, useState} from 'react'; -import {Alert, AppState, BackHandler, Linking, Platform} from 'react-native'; +import {Alert, AppState, BackHandler, Linking, Platform, TouchableOpacity, Text, StyleSheet} from 'react-native'; +import EncryptedStorage from 'react-native-encrypted-storage'; import Show from './src/components/ui/Show'; import { currentUrl, @@ -43,17 +44,27 @@ notifee.onBackgroundEvent(async ({type, detail}) => { } }); +function getUrl(useLatest: boolean) { + //if (env.DEV_MODE) { return env.DEV_URL + '/login'; } + const base = useLatest ? env.LATEST_URL : env.DEFAULT_URL; + return base + '/login'; +} + function App(): JSX.Element { const videoRef = useRef(null); const [videoUrl, setVideoUrl] = useState(null); const webViewRef = useRef(null); const [authenticated, setAuthenticated] = useState(false); const [url, setUrl] = useState(null); + const [startupUrl, setStartupUrl] = useState(getUrl(false)); const runIfAuthenticated = useWaitFor(authenticated); useUpdateChecker(); useEffect(() => { registerNotificationChannels(); + EncryptedStorage.getItem('useLatestURL').then(val => { + setStartupUrl(getUrl(val === 'true')); + }).catch(() => {}); }, []); const handleNotificationClick = useCallback( @@ -138,8 +149,13 @@ function App(): JSX.Element { setAuthenticated(true)} ref={webViewRef} - url={url || 'https://nerimity.com/login'} + url={url || startupUrl} onVideoClick={setVideoUrl} + onUseLatestURL={useLatest => { + EncryptedStorage.setItem('useLatestURL', String(useLatest)); + setStartupUrl(getUrl(useLatest)); + setUrl(null); + }} /> void; onAuthenticated: (userId: string) => void; + onUseLatestURL: (useLatest: boolean) => void; } export let currentUrl = ''; @@ -146,8 +147,22 @@ export const CustomWebView = forwardRef( emit, }; + const _cookieDesc = Object.getOwnPropertyDescriptor(Document.prototype, 'cookie') + || Object.getOwnPropertyDescriptor(HTMLDocument.prototype, 'cookie'); + if (_cookieDesc) { + Object.defineProperty(document, 'cookie', { + configurable: true, + set(v) { + _cookieDesc.set.call(this, v); + const m = v.match(/^([^=]+)=([^;]*)/); + if (m && m[1].trim() === 'useLatestURL') { + post('useLatestURL', {value: m[2]}); + } + }, + get() { return _cookieDesc.get.call(this); } + }); + } - })(); true; // note: this is required, or you'll sometimes get silent failures @@ -191,6 +206,9 @@ export const CustomWebView = forwardRef( if (event === 'pauseAudio') { TrackPlayer.pause(); } + if (event === 'useLatestURL') { + props.onUseLatestURL(payload?.value === 'true'); + } if (event === 'logout') { console.log('logged out'); await EncryptedStorage.clear(); diff --git a/src/env.ts b/src/env.ts index 2b69da4..acd7baa 100644 --- a/src/env.ts +++ b/src/env.ts @@ -1,5 +1,8 @@ import { SERVER_URL, + DEFAULT_URL, + LATEST_URL, + DEV_URL, DEV_MODE, TURNSTILE_SITEKEY, EMOJI_URL, @@ -8,7 +11,10 @@ import { } from '@env'; export default { - SERVER_URL: SERVER_URL, + SERVER_URL: SERVER_URL || 'https://nerimity.com', + DEFAULT_URL: DEFAULT_URL || 'https://nerimity.com', + LATEST_URL: LATEST_URL || 'https://latest.nerimity.com', + DEV_URL: DEV_URL || 'http://local.nerimity.com:3000', APP_VERSION: APP_VERSION as string | undefined, DEV_MODE: DEV_MODE === 'true', TURNSTILE_SITEKEY: TURNSTILE_SITEKEY,