1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00

Mobile: Show WebView version in settings (#10518)

This commit is contained in:
Henry Heino 2024-06-04 01:53:49 -07:00 committed by GitHub
parent f94c16b22e
commit efb48e6145
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 117 additions and 11 deletions

View File

@ -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

1
.gitignore vendored
View File

@ -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

View File

@ -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"

View File

@ -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<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
return Collections.singletonList(new SystemVersionInformationModule(reactContext));
}
@NonNull
@Override
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
return Collections.emptyList();
}
public static class SystemVersionInformationModule extends ReactContextBaseJavaModule {
public SystemVersionInformationModule(@NonNull ReactApplicationContext context) {
super(context);
}
@Override
public Map<String, Object> getConstants() {
final Map<String, Object> result = new HashMap<String, Object>();
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";
}
}
}

View File

@ -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<ConfigScreenProps, Confi
addSettingLink('website_link', _('Joplin website'), 'https://joplinapp.org/');
addSettingLink('privacy_link', _('Privacy Policy'), 'https://joplinapp.org/privacy/');
const packageInfo = getPackageInfo();
const appInfo = versionInfo(packageInfo, PluginService.instance().enabledPlugins(settings['plugins.states']));
const versionInfoText = [
appInfo.body,
'',
_('FTS enabled: %d', this.props.settings['db.ftsEnabled']),
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
_('Hermes enabled: %d', (global as any).HermesInternal ? 1 : 0),
].join('\n');
const versionInfoText = getVersionInfoText(settings['plugins.states']);
addSettingText('version_info', versionInfoText);
addSettingButton('copy_app_info', _('Copy version info'), () => {

View File

@ -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;