diff --git a/node/buildSrcCordova.js b/node/buildSrcCordova.js index e9988be90..b7bae5d0c 100644 --- a/node/buildSrcCordova.js +++ b/node/buildSrcCordova.js @@ -12,10 +12,6 @@ function addUShowStylesImport (fileTxt, path) { const hasMobileImport = fileTxt.match(/import.*?uShowMobile/) != null; const hasDeskTopImport = fileTxt.match(/import.*?uShowDesktopTablet/) != null; - if (path.includes('SuggestedFriendDisplayForList')) { - console.log(path); - } - // if import needs is already met, return unchanged if (!hasMobile && !hasMobileImport && !hasDeskTop && !hasDeskTopImport) return fileTxt; if (hasMobile && hasMobileImport && hasDeskTop && hasDeskTopImport) return fileTxt; @@ -50,21 +46,42 @@ function addUShowStylesImport (fileTxt, path) { return ret; } -function getVersionFromConfigXML () { +function getVersionsFromConfigXML () { const path = '../WeVoteCordova/config.xml'; + const versions = { + version: 'error', + iosBundleVersion: 'error', + androidBundleVersion: 'error', + }; const data = fs.readFileSync(path, 'utf-8'); - const regex = /version="(.*?)"/; - const found = data.match(regex); + let regex = /version="(.*?)"/; + let found = data.match(regex); if (found.length > 0) { console.log('version from config.xml: ', found[1]); - return found[1]; + versions.version = found[1]; } else { console.log('version from config.xml: error'); - return 'error'; } + regex = /ios-CFBundleVersion="(.*?)"/; + found = data.match(regex); + if (found.length > 0) { + console.log('ios-CFBundleVersion from config.xml: ', found[1]); + versions.iosBundleVersion = found[1]; + } else { + console.log('ios-CFBundleVersion from config.xml: error'); + } + regex = /android-versionCode="(.*?)"/; + found = data.match(regex); + if (found.length > 0) { + console.log('android-versionCode from config.xml: ', found[1]); + versions.androidBundleVersion = found[1]; + } else { + console.log('android-versionCode from config.xml: error'); + } + return versions; } -function fileRewriterForCordova (path, version) { +function fileRewriterForCordova (path, versions) { // console.log('Do ', path); if (path.endsWith('.css') || path.endsWith('cordovaOffsets.js')) { return; @@ -140,7 +157,9 @@ function fileRewriterForCordova (path, version) { newValue = addUShowStylesImport(newValue, path); // Inject version string - newValue = newValue.replace(/{window\.weVoteAppVersion}/, version); + newValue = newValue.replace(/window\.weVoteAppVersion/, versions.version); + newValue = newValue.replace(/window\.iosBundleVersion/, versions.iosBundleVersion); + newValue = newValue.replace(/window\.androidBundleVersion/, versions.androidBundleVersion); fs.writeFile(path, newValue, 'utf-8', (err2) => { if (err2) throw err2; @@ -152,7 +171,7 @@ function fileRewriterForCordova (path, version) { // Inline node console.log('> Cordova: Preparing to set up parallel /srcCordova directory.'); -const version = getVersionFromConfigXML(); +const versions = getVersionsFromConfigXML(); fs.remove('./build').then(() => { console.log('> Cordova: Removed build directory'); fs.remove('./srcCordova').then(() => { @@ -176,7 +195,7 @@ fs.remove('./build').then(() => { const path = listOfFiles[i]; // console.log(`path: ${path}`); if (path.length) { - fileRewriterForCordova(path, version); + fileRewriterForCordova(path, versions); } } console.log(`> Cordova: ${listOfFiles.length} files in ./srcCordova, rewritten without React.lazy`); diff --git a/src/js/common/utils/cordovaUtils.js b/src/js/common/utils/cordovaUtils.js index dc3de5334..a9d46dd03 100644 --- a/src/js/common/utils/cordovaUtils.js +++ b/src/js/common/utils/cordovaUtils.js @@ -833,6 +833,14 @@ export function cordovaLinkToBeSharedFixes (link) { linkToBeShared = linkToBeShared.replace('app://localhost/index.html#/', 'https://wevote.us/'); // Cordova iOS Nov 2021 return linkToBeShared; } + +export function getCordovaBuildVersion () { + const version = 'window.weVoteAppVersion'; + const iosBundleVersion = 'window.iosBundleVersion'; + const androidBundleVersion = 'window.androidBundleVersion'; + return `${version} (${isIOS() ? iosBundleVersion : androidBundleVersion})`; +} + // //////////////////////// // this was used in ShareButtonFooter before I started using cordovaLinkToBeSharedFixes above // getCurrentFullUrl () { diff --git a/src/js/components/Share/shareButtonCommon.jsx b/src/js/components/Share/shareButtonCommon.jsx index 230a5b737..af2f124a9 100644 --- a/src/js/components/Share/shareButtonCommon.jsx +++ b/src/js/components/Share/shareButtonCommon.jsx @@ -13,6 +13,7 @@ import VoterStore from '../../stores/VoterStore'; import { openSnackbar } from '../../common/components/Widgets/SnackNotifier'; import ShareModalOption from './ShareModalOption'; + export const shareStyles = () => ({ dialogPaper: { // marginTop: hasIPhoneNotch() ? 68 : 48, @@ -244,16 +245,19 @@ export function saveActionShareAnalytics () { } } -let close; function onEmailSendSuccess () { console.log('successfully shared via email'); - close(); + if (this.closeFunc) { + this.closeFunc(); + } openSnackbar({ message: 'You have successfully shared via email.' }); } function onEmailSendError (error) { console.log('share by email failed', error); - close(); + if (this.closeFunc) { + this.closeFunc(); + } if (error === 'not available') { openSnackbar({ message: 'Your device is not configured to send email' }); } else { @@ -262,7 +266,7 @@ function onEmailSendError (error) { } export function cordovaSocialSharingByEmail (subject, linkToBeShared, handleClose) { - close = handleClose; + this.closeFunc = handleClose; const body = `This is a website I am using to get ready to vote. ${linkToBeShared}`; console.log('cordovaSocialSharingByEmail ', subject, linkToBeShared); // window.plugins.socialsharing.canShareViaEmail((e) => {console.log("canShareViaEmail 1: " + e)}, (e) => {console.log("canShareViaEmail 2: " + e)}); diff --git a/src/js/components/Widgets/DeviceDialog.jsx b/src/js/components/Widgets/DeviceDialog.jsx index bf5bf7bfd..d4b906fe7 100644 --- a/src/js/components/Widgets/DeviceDialog.jsx +++ b/src/js/components/Widgets/DeviceDialog.jsx @@ -5,7 +5,7 @@ import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { Link } from 'react-router-dom'; import styled from 'styled-components'; -import { getAndroidSize, getIOSSizeString, hasIPhoneNotch, isAndroid, isIOS, isSimulator } from '../../common/utils/cordovaUtils'; +import { getAndroidSize, getCordovaBuildVersion, getIOSSizeString, hasIPhoneNotch, isAndroid, isIOS, isSimulator } from '../../common/utils/cordovaUtils'; import historyPush from '../../common/utils/historyPush'; import { getTabletSize } from '../../common/utils/isMobileScreenSize'; import { renderLog } from '../../common/utils/logging'; @@ -63,6 +63,7 @@ class DeviceDialog extends Component { } // HACK 10/2/23 const { diameter } = window.pbakondyScreenSize; const diameter = 'unknown'; + const version = getCordovaBuildVersion(); return ( Version - {window.weVoteAppVersion} + {version} Compile date diff --git a/src/js/pages/Settings/HamburgerMenu.jsx b/src/js/pages/Settings/HamburgerMenu.jsx index d28bcb61b..d308b9eb2 100644 --- a/src/js/pages/Settings/HamburgerMenu.jsx +++ b/src/js/pages/Settings/HamburgerMenu.jsx @@ -4,6 +4,7 @@ import { Helmet } from 'react-helmet-async'; import VoterSessionActions from '../../actions/VoterSessionActions'; import LazyImage from '../../common/components/LazyImage'; import LoadingWheel from '../../common/components/Widgets/LoadingWheel'; +import { getCordovaBuildVersion } from '../../common/utils/cordovaUtils'; import historyPush from '../../common/utils/historyPush'; import { isCordova } from '../../common/utils/isCordovaOrWebApp'; import isMobileScreenSize from '../../common/utils/isMobileScreenSize'; @@ -137,6 +138,7 @@ export default class HamburgerMenu extends Component { // `/voterguide/${voterOrganizationWeVoteId}`; const nextReleaseFeaturesEnabled = webAppConfig.ENABLE_NEXT_RELEASE_FEATURES === undefined ? false : webAppConfig.ENABLE_NEXT_RELEASE_FEATURES; // console.log(`Hamburger menu this.state.showDeviceDialog ${this.state.showDeviceDialog}`); + const version = getCordovaBuildVersion(); return ( @@ -320,7 +322,7 @@ export default class HamburgerMenu extends Component {
Version:   - {window.weVoteAppVersion} + {version}
diff --git a/src/js/pages/VoterGuide/OrganizationVoterGuide.jsx b/src/js/pages/VoterGuide/OrganizationVoterGuide.jsx index e2cdbb034..982e246f2 100755 --- a/src/js/pages/VoterGuide/OrganizationVoterGuide.jsx +++ b/src/js/pages/VoterGuide/OrganizationVoterGuide.jsx @@ -279,7 +279,7 @@ export default class OrganizationVoterGuide extends Component { goToVoterGuideDetailsPage (destinationTab) { const { pathname: editLink, href: editLinkCordova } = window.location; const editPathCordova = editLinkCordova.replace(/file:\/\/.*?Vote.app\/www\/index.html#\//, '') - .replace(/app.*?index.html#/, ''); + .replace(/(app|https:).*?index.html#/, ''); // iOS (app://localhost/index.html#/ppact) or Android (https://localhost/index.html#/ppact) historyPush(`${isWebApp() ? editLink : editPathCordova}/m/${destinationTab}`); }