From f78729ad1f02ad9b9a2b34ae250499236cfa0a6a Mon Sep 17 00:00:00 2001 From: mic704b Date: Sat, 25 Jan 2020 07:56:44 +1100 Subject: [PATCH] Cross-platform version number retrieval (#2355) * Add shim to retrieve application version. * Create shim to retrieve app version number. * Add a fall through handler to throw an error. --- ReactNativeClient/lib/shim-init-node.js | 9 +++++++++ ReactNativeClient/lib/shim-init-react.js | 5 +++++ ReactNativeClient/lib/shim.js | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/ReactNativeClient/lib/shim-init-node.js b/ReactNativeClient/lib/shim-init-node.js index a754ed5b3..81c34cb31 100644 --- a/ReactNativeClient/lib/shim-init-node.js +++ b/ReactNativeClient/lib/shim-init-node.js @@ -378,6 +378,15 @@ function shimInit() { }; shim.waitForFrame = () => {}; + + shim.appVersion = () => { + if (shim.isElectron()) { + const p = require('../packageInfo.js'); + return p.version; + } + const p = require('../package.json'); + return p.version; + }; } module.exports = { shimInit }; diff --git a/ReactNativeClient/lib/shim-init-react.js b/ReactNativeClient/lib/shim-init-react.js index f701560b7..89420d0b6 100644 --- a/ReactNativeClient/lib/shim-init-react.js +++ b/ReactNativeClient/lib/shim-init-react.js @@ -144,6 +144,11 @@ function shimInit() { return Platform.OS; }; + shim.appVersion = () => { + const p = require('react-native-version-info').default; + return p.appVersion; + }; + // NOTE: This is a limited version of createResourceFromPath - unlike the Node version, it // only really works with images. It does not resize the image either. shim.createResourceFromPath = async function(filePath, defaultProps = null) { diff --git a/ReactNativeClient/lib/shim.js b/ReactNativeClient/lib/shim.js index fa230c601..8a9e069e8 100644 --- a/ReactNativeClient/lib/shim.js +++ b/ReactNativeClient/lib/shim.js @@ -197,6 +197,10 @@ shim.waitForFrame = () => { throw new Error('Not implemented'); }; +shim.appVersion = () => { + throw new Error('Not implemented'); +}; + shim.injectedJs = name => ''; let isTestingEnv_ = false;