chore: show android system webview update prompt if app fails to load (#2318)
This commit is contained in:
@@ -16,7 +16,14 @@
|
|||||||
window.plansUrl = "https://standardnotes.com/plans";
|
window.plansUrl = "https://standardnotes.com/plans";
|
||||||
window.dashboardUrl = "https://standardnotes.com/dashboard";
|
window.dashboardUrl = "https://standardnotes.com/dashboard";
|
||||||
</script>
|
</script>
|
||||||
|
<script>
|
||||||
|
window.onerror = function (message, source, lineno, colno, error) {
|
||||||
|
if (document.readyState === "complete") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
window.ReactNativeWebView.postMessage("appLoadError");
|
||||||
|
};
|
||||||
|
</script>
|
||||||
<script src="web-src/app.js"></script>
|
<script src="web-src/app.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ReactNativeToWebEvent } from '@standardnotes/snjs'
|
import { ReactNativeToWebEvent } from '@standardnotes/snjs'
|
||||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import { Keyboard, Platform } from 'react-native'
|
import { Button, Keyboard, Platform, Text, View } from 'react-native'
|
||||||
import VersionInfo from 'react-native-version-info'
|
import VersionInfo from 'react-native-version-info'
|
||||||
import { WebView, WebViewMessageEvent } from 'react-native-webview'
|
import { WebView, WebViewMessageEvent } from 'react-native-webview'
|
||||||
import { OnShouldStartLoadWithRequest } from 'react-native-webview/lib/WebViewTypes'
|
import { OnShouldStartLoadWithRequest } from 'react-native-webview/lib/WebViewTypes'
|
||||||
@@ -34,6 +34,8 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
|
|||||||
[androidBackHandlerService, colorSchemeService, stateService],
|
[androidBackHandlerService, colorSchemeService, stateService],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const [showAndroidWebviewUpdatePrompt, setShowAndroidWebviewUpdatePrompt] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const removeStateServiceListener = stateService.addEventObserver((event: ReactNativeToWebEvent) => {
|
const removeStateServiceListener = stateService.addEventObserver((event: ReactNativeToWebEvent) => {
|
||||||
webViewRef.current?.postMessage(JSON.stringify({ reactNativeEvent: event, messageType: 'event' }))
|
webViewRef.current?.postMessage(JSON.stringify({ reactNativeEvent: event, messageType: 'event' }))
|
||||||
@@ -228,6 +230,10 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
|
|||||||
|
|
||||||
const onMessage = (event: WebViewMessageEvent) => {
|
const onMessage = (event: WebViewMessageEvent) => {
|
||||||
const message = event.nativeEvent.data
|
const message = event.nativeEvent.data
|
||||||
|
if (message === 'appLoadError' && Platform.OS === 'android') {
|
||||||
|
setShowAndroidWebviewUpdatePrompt(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const functionData = JSON.parse(message)
|
const functionData = JSON.parse(message)
|
||||||
void onFunctionMessage(functionData.functionName, functionData.messageId, functionData.args)
|
void onFunctionMessage(functionData.functionName, functionData.messageId, functionData.args)
|
||||||
@@ -277,6 +283,47 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
|
|||||||
const requireInlineMediaPlaybackForMomentsFeature = true
|
const requireInlineMediaPlaybackForMomentsFeature = true
|
||||||
const requireMediaUserInteractionForMomentsFeature = false
|
const requireMediaUserInteractionForMomentsFeature = false
|
||||||
|
|
||||||
|
if (showAndroidWebviewUpdatePrompt) {
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
backgroundColor: 'black',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
color: 'white',
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: 'bold',
|
||||||
|
marginBottom: 20,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Could not load app
|
||||||
|
</Text>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
color: 'white',
|
||||||
|
fontSize: 16,
|
||||||
|
marginBottom: 20,
|
||||||
|
textAlign: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Please make sure your Android System Webview is updated to the latest version
|
||||||
|
</Text>
|
||||||
|
<Button
|
||||||
|
title={'Update'}
|
||||||
|
onPress={() => {
|
||||||
|
setShowAndroidWebviewUpdatePrompt(false)
|
||||||
|
device.openUrl('https://play.google.com/store/apps/details?id=com.google.android.webview')
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WebView
|
<WebView
|
||||||
ref={webViewRef}
|
ref={webViewRef}
|
||||||
|
|||||||
Reference in New Issue
Block a user