Skip to content

Commit

Permalink
Merge pull request #3777 from SailingSteve/steveWebAppNov10-434pm
Browse files Browse the repository at this point in the history
Fixed path handling for "Followers" link on OrganizationVoterGuide in Cordova Android
  • Loading branch information
DaleMcGrew authored Nov 11, 2023
2 parents 8ab2426 + 21ace3f commit 74e1180
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 21 deletions.
45 changes: 32 additions & 13 deletions node/buildSrcCordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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(() => {
Expand All @@ -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`);
Expand Down
8 changes: 8 additions & 0 deletions src/js/common/utils/cordovaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
12 changes: 8 additions & 4 deletions src/js/components/Share/shareButtonCommon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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)});
Expand Down
5 changes: 3 additions & 2 deletions src/js/components/Widgets/DeviceDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -63,6 +63,7 @@ class DeviceDialog extends Component {
}
// HACK 10/2/23 const { diameter } = window.pbakondyScreenSize;
const diameter = 'unknown';
const version = getCordovaBuildVersion();

return (
<Dialog
Expand Down Expand Up @@ -132,7 +133,7 @@ class DeviceDialog extends Component {
</TableRow>
<TableRow>
<StyledTableCell>Version</StyledTableCell>
<StyledTableCell>{window.weVoteAppVersion}</StyledTableCell>
<StyledTableCell>{version}</StyledTableCell>
</TableRow>
<TableRow>
<StyledTableCell>Compile date</StyledTableCell>
Expand Down
4 changes: 3 additions & 1 deletion src/js/pages/Settings/HamburgerMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 (
<PageContentContainer>
Expand Down Expand Up @@ -320,7 +322,7 @@ export default class HamburgerMenu extends Component {
<div>
<span className="hamburger-terms__text" style={{ color: 'black', opacity: '0.7', fontSize: '10px' }}>
Version:&nbsp;&nbsp;
{window.weVoteAppVersion}
{version}
</span>
</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion src/js/pages/VoterGuide/OrganizationVoterGuide.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}

Expand Down

0 comments on commit 74e1180

Please sign in to comment.