diff --git a/www/js/services/controlHelper.ts b/www/js/services/controlHelper.ts index da2e60ed7..9334ee318 100644 --- a/www/js/services/controlHelper.ts +++ b/www/js/services/controlHelper.ts @@ -39,48 +39,38 @@ export function getMyDataHelpers(fileName: string, startTimeString: string, endT function localShareData() { return new Promise((resolve, reject) => { window['resolveLocalFileSystemURL'](window['cordova'].file.cacheDirectory, (fs) => { - fs.filesystem.root.getFile(fileName, null, (fileEntry) => { - logDebug(`fileEntry ${fileEntry.nativeURL} is file? ${fileEntry.isFile.toString()}`); - fileEntry.file( - (file) => { - const reader = new FileReader(); - - reader.onloadend = () => { - const readResult = this.result as string; - logDebug(`Successfull file read with ${readResult.length} characters`); - const dataArray = JSON.parse(readResult); - logDebug(`Successfully read resultList of size ${dataArray.length}`); - let attachFile = fileEntry.nativeURL; - const shareObj = { - files: [attachFile], - message: i18next.t( - 'shareFile-service.send-data.body-data-consists-of-list-of-entries', - ), - subject: i18next.t('shareFile-service.send-data.subject-data-dump-from-to', { - start: startTimeString, - end: endTimeString, - }), - }; - window['plugins'].socialsharing.shareWithOptions( - shareObj, - (result) => { - logDebug(`Share Completed? ${result.completed}`); // On Android, most likely returns false - logDebug(`Shared to app: ${result.app}`); - resolve(); - }, - (msg) => { - logDebug(`Sharing failed with message ${msg}`); - }, - ); - }; - reader.readAsText(file); - }, - (error) => { - displayError(error, 'Error while downloading JSON dump'); - reject(error); - }, - ); - }); + fs.filesystem.root.getFile( + fileName, + null, + (fileEntry) => { + logDebug(`fileEntry ${fileEntry.nativeURL} is file? ${fileEntry.isFile.toString()}`); + const shareObj = { + files: [fileEntry.nativeURL], + message: i18next.t( + 'shareFile-service.send-data.body-data-consists-of-list-of-entries', + ), + subject: i18next.t('shareFile-service.send-data.subject-data-dump-from-to', { + start: startTimeString, + end: endTimeString, + }), + }; + window['plugins'].socialsharing.shareWithOptions( + shareObj, + (result) => { + logDebug(`Share Completed? ${result.completed}`); // On Android, most likely returns false + logDebug(`Shared to app: ${result.app}`); + resolve(); + }, + (error) => { + displayError(error, `Sharing failed with message`); + }, + ); + }, + (error) => { + displayError(error, 'Error while downloading JSON dump'); + reject(error); + }, + ); }); }); } @@ -117,7 +107,7 @@ export function getMyDataHelpers(fileName: string, startTimeString: string, endT * getMyData fetches timeline data for a given day, and then gives the user a prompt to share the data * @param timeStamp initial timestamp of the timeline to be fetched. */ -export function getMyData(timeStamp: Date) { +export async function getMyData(timeStamp: Date) { // We are only retrieving data for a single day to avoid // running out of memory on the phone const endTime = DateTime.fromJSDate(timeStamp); @@ -125,7 +115,8 @@ export function getMyData(timeStamp: Date) { const startTimeString = startTime.toFormat("yyyy'-'MM'-'dd"); const endTimeString = endTime.toFormat("yyyy'-'MM'-'dd"); - const dumpFile = startTimeString + '.' + endTimeString + '.timeline'; + // let's rename this to .txt so that we can email it on iPhones + const dumpFile = startTimeString + '.' + endTimeString + '.timeline.txt'; alert(`Going to retrieve data to ${dumpFile}`); const getDataMethods = getMyDataHelpers(dumpFile, startTimeString, endTimeString);