Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-apk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 18 additions & 2 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<CustomVideoRef | null>(null);
const [videoUrl, setVideoUrl] = useState<string | null>(null);
const webViewRef = useRef<CustomWebViewRef | null>(null);
const [authenticated, setAuthenticated] = useState(false);
const [url, setUrl] = useState<string | null>(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(
Expand Down Expand Up @@ -138,8 +149,13 @@ function App(): JSX.Element {
<CustomWebView
onAuthenticated={() => 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);
}}
/>
<Show when={videoUrl}>
<CustomVideo
Expand Down
20 changes: 19 additions & 1 deletion src/components/CustomWebView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface CustomWebViewProps {
url?: string | null;
onVideoClick: (url: string) => void;
onAuthenticated: (userId: string) => void;
onUseLatestURL: (useLatest: boolean) => void;
}

export let currentUrl = '';
Expand Down Expand Up @@ -146,8 +147,22 @@ export const CustomWebView = forwardRef<CustomWebViewRef, CustomWebViewProps>(
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
Expand Down Expand Up @@ -191,6 +206,9 @@ export const CustomWebView = forwardRef<CustomWebViewRef, CustomWebViewProps>(
if (event === 'pauseAudio') {
TrackPlayer.pause();
}
if (event === 'useLatestURL') {
props.onUseLatestURL(payload?.value === 'true');
}
if (event === 'logout') {
console.log('logged out');
await EncryptedStorage.clear();
Expand Down
8 changes: 7 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {
SERVER_URL,
DEFAULT_URL,
LATEST_URL,
DEV_URL,
DEV_MODE,
TURNSTILE_SITEKEY,
EMOJI_URL,
Expand All @@ -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,
Expand Down