From efb48e6145f31b754481287e53ad5bf7bd0a0806 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Tue, 4 Jun 2024 01:53:49 -0700 Subject: [PATCH] Mobile: Show WebView version in settings (#10518) --- .eslintignore | 1 + .gitignore | 1 + .../java/net/cozic/joplin/MainApplication.kt | 2 + .../SystemVersionInformationPackage.java | 61 +++++++++++++++++++ .../screens/ConfigScreen/ConfigScreen.tsx | 13 +--- .../app-mobile/utils/getVersionInfoText.ts | 50 +++++++++++++++ 6 files changed, 117 insertions(+), 11 deletions(-) create mode 100644 packages/app-mobile/android/app/src/main/java/net/cozic/joplin/versioninfo/SystemVersionInformationPackage.java create mode 100644 packages/app-mobile/utils/getVersionInfoText.ts diff --git a/.eslintignore b/.eslintignore index ce45d2b3e..c4bbcf7a6 100644 --- a/.eslintignore +++ b/.eslintignore @@ -694,6 +694,7 @@ packages/app-mobile/utils/fs-driver/tarExtract.js packages/app-mobile/utils/fs-driver/testUtil/createFilesFromPathRecord.js packages/app-mobile/utils/fs-driver/testUtil/verifyDirectoryMatches.js packages/app-mobile/utils/getPackageInfo.js +packages/app-mobile/utils/getVersionInfoText.js packages/app-mobile/utils/initializeCommandService.js packages/app-mobile/utils/ipc/RNToWebViewMessenger.js packages/app-mobile/utils/ipc/WebViewToRNMessenger.js diff --git a/.gitignore b/.gitignore index 42146371b..ff1e1ae64 100644 --- a/.gitignore +++ b/.gitignore @@ -673,6 +673,7 @@ packages/app-mobile/utils/fs-driver/tarExtract.js packages/app-mobile/utils/fs-driver/testUtil/createFilesFromPathRecord.js packages/app-mobile/utils/fs-driver/testUtil/verifyDirectoryMatches.js packages/app-mobile/utils/getPackageInfo.js +packages/app-mobile/utils/getVersionInfoText.js packages/app-mobile/utils/initializeCommandService.js packages/app-mobile/utils/ipc/RNToWebViewMessenger.js packages/app-mobile/utils/ipc/WebViewToRNMessenger.js diff --git a/packages/app-mobile/android/app/src/main/java/net/cozic/joplin/MainApplication.kt b/packages/app-mobile/android/app/src/main/java/net/cozic/joplin/MainApplication.kt index e8bc836e8..76075257e 100644 --- a/packages/app-mobile/android/app/src/main/java/net/cozic/joplin/MainApplication.kt +++ b/packages/app-mobile/android/app/src/main/java/net/cozic/joplin/MainApplication.kt @@ -11,6 +11,7 @@ import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost import com.facebook.react.defaults.DefaultReactNativeHost import com.facebook.soloader.SoLoader +import net.cozic.joplin.versioninfo.SystemVersionInformationPackage import net.cozic.joplin.share.SharePackage import net.cozic.joplin.ssl.SslPackage import net.cozic.joplin.textinput.TextInputPackage @@ -23,6 +24,7 @@ class MainApplication : Application(), ReactApplication { add(SharePackage()) add(SslPackage()) add(TextInputPackage()) + add(SystemVersionInformationPackage()) } override fun getJSMainModuleName(): String = "index" diff --git a/packages/app-mobile/android/app/src/main/java/net/cozic/joplin/versioninfo/SystemVersionInformationPackage.java b/packages/app-mobile/android/app/src/main/java/net/cozic/joplin/versioninfo/SystemVersionInformationPackage.java new file mode 100644 index 000000000..e60f38bc6 --- /dev/null +++ b/packages/app-mobile/android/app/src/main/java/net/cozic/joplin/versioninfo/SystemVersionInformationPackage.java @@ -0,0 +1,61 @@ +package net.cozic.joplin.versioninfo; + +import android.content.pm.PackageInfo; +import android.os.Build; +import android.webkit.WebView; + +import com.facebook.react.ReactPackage; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.Promise; +import com.facebook.react.bridge.ReactApplicationContext; + +import androidx.annotation.NonNull; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.uimanager.ViewManager; +import com.facebook.react.bridge.ReactMethod; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class SystemVersionInformationPackage implements ReactPackage { + + @NonNull + @Override + public List createNativeModules(@NonNull ReactApplicationContext reactContext) { + return Collections.singletonList(new SystemVersionInformationModule(reactContext)); + } + + @NonNull + @Override + public List createViewManagers(@NonNull ReactApplicationContext reactContext) { + return Collections.emptyList(); + } + + public static class SystemVersionInformationModule extends ReactContextBaseJavaModule { + public SystemVersionInformationModule(@NonNull ReactApplicationContext context) { + super(context); + } + + @Override + public Map getConstants() { + final Map result = new HashMap(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + PackageInfo webViewPackage = WebView.getCurrentWebViewPackage(); + + if (webViewPackage != null) { + result.put("webViewVersion", webViewPackage.versionName); + result.put("webViewPackage", webViewPackage.packageName); + } + } + return result; + } + + @NonNull + @Override + public String getName() { + return "SystemVersionInformationModule"; + } + } +} \ No newline at end of file diff --git a/packages/app-mobile/components/screens/ConfigScreen/ConfigScreen.tsx b/packages/app-mobile/components/screens/ConfigScreen/ConfigScreen.tsx index 56f029aac..cdb2a4204 100644 --- a/packages/app-mobile/components/screens/ConfigScreen/ConfigScreen.tsx +++ b/packages/app-mobile/components/screens/ConfigScreen/ConfigScreen.tsx @@ -33,8 +33,7 @@ import PluginUploadButton, { canInstallPluginsFromFile, buttonLabel as pluginUpl import NoteImportButton, { importButtonDefaultTitle, importButtonDescription } from './NoteExportSection/NoteImportButton'; import SectionDescription from './SectionDescription'; import EnablePluginSupportPage from './plugins/EnablePluginSupportPage'; -import getPackageInfo from '../../../utils/getPackageInfo'; -import versionInfo from '@joplin/lib/versionInfo'; +import getVersionInfoText from '../../../utils/getVersionInfoText'; interface ConfigScreenState { // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied @@ -619,15 +618,7 @@ class ConfigScreenComponent extends BaseScreenComponent { diff --git a/packages/app-mobile/utils/getVersionInfoText.ts b/packages/app-mobile/utils/getVersionInfoText.ts new file mode 100644 index 000000000..11d598647 --- /dev/null +++ b/packages/app-mobile/utils/getVersionInfoText.ts @@ -0,0 +1,50 @@ +import versionInfo from '@joplin/lib/versionInfo'; +import { Platform, NativeModules } from 'react-native'; +import getPackageInfo from './getPackageInfo'; +import PluginService, { PluginSettings } from '@joplin/lib/services/plugins/PluginService'; +import Setting from '@joplin/lib/models/Setting'; +import { _ } from '@joplin/lib/locale'; + +const getWebViewVersionText = () => { + if (Platform.OS === 'android') { + const constants = NativeModules.SystemVersionInformationModule.getConstants(); + return [ + _('WebView version: %s', constants.webViewVersion), + _('WebView package: %s', constants.webViewPackage), + ].join('\n'); + } + return null; +}; + +const getOSVersion = (): string => { + if (Platform.OS === 'android') { + return _('Android API level: %d', Platform.Version); + } else { + return _('iOS version: %s', Platform.Version); + } +}; + +const getVersionInfoText = (pluginStates: PluginSettings) => { + const packageInfo = getPackageInfo(); + const appInfo = versionInfo(packageInfo, PluginService.instance().enabledPlugins(pluginStates)); + const versionInfoLines = [ + appInfo.body, + '', + getOSVersion(), + ]; + + const webViewVersion = getWebViewVersionText(); + if (webViewVersion) { + versionInfoLines.push(webViewVersion); + } + + versionInfoLines.push( + _('FTS enabled: %d', Setting.value('db.ftsEnabled')), + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Partially refactored old code before rule was applied + _('Hermes enabled: %d', (global as any).HermesInternal ? 1 : 0), + ); + + return versionInfoLines.join('\n'); +}; + +export default getVersionInfoText;