From f25a2e97c348f888704d750836f62765e908d4de Mon Sep 17 00:00:00 2001
From: Katie Rischpater <98350084+the-bay-kay@users.noreply.github.com>
Date: Tue, 21 May 2024 14:32:48 -0700
Subject: [PATCH 01/11] Refractored `emailService` into `shareLocalDBFile` -
Moved into `services/` directory - Refractored `emailService.ts` to now use
sharePlugin, to match controlHelper - To reflect this change, renamed the
service to `shareLocalDBFile` - Reworked 18next translations to reflect
change
---
package.cordovabuild.json | 2 --
www/i18n/en.json | 12 +++----
www/js/control/LogPage.tsx | 4 +--
www/js/control/ProfileSettings.tsx | 6 ++--
www/js/control/SensedPage.tsx | 4 +--
www/js/control/emailService.ts | 52 -----------------------------
www/js/services/controlHelper.ts | 4 +--
www/js/services/shareLocalDBFile.ts | 40 ++++++++++++++++++++++
8 files changed, 54 insertions(+), 70 deletions(-)
delete mode 100644 www/js/control/emailService.ts
create mode 100644 www/js/services/shareLocalDBFile.ts
diff --git a/package.cordovabuild.json b/package.cordovabuild.json
index d84baa02c..0864d8184 100644
--- a/package.cordovabuild.json
+++ b/package.cordovabuild.json
@@ -67,7 +67,6 @@
"ANDROID_HOST": " ",
"ANDROID_PATHPREFIX": "/"
},
- "cordova-plugin-email-composer": {},
"cordova-plugin-x-socialsharing": {
"PHOTO_LIBRARY_ADD_USAGE_DESCRIPTION": "This app requires photo library access to share photos on social media.",
"PHOTO_LIBRARY_USAGE_DESCRIPTION": "This app requires photo library access to share photos on social media."
@@ -128,7 +127,6 @@
"cordova-plugin-em-settings": "git+https://github.com/e-mission/cordova-connection-settings.git#v1.2.3",
"cordova-plugin-em-unifiedlogger": "git+https://github.com/e-mission/cordova-unified-logger.git#v1.3.6",
"cordova-plugin-em-usercache": "git+https://github.com/e-mission/cordova-usercache.git#v1.1.9",
- "cordova-plugin-email-composer": "git+https://github.com/katzer/cordova-plugin-email-composer.git#0.10.1",
"cordova-plugin-file": "8.0.0",
"cordova-plugin-inappbrowser": "5.0.0",
"cordova-plugin-ionic-keyboard": "2.2.0",
diff --git a/www/i18n/en.json b/www/i18n/en.json
index 2834219af..39685cde6 100644
--- a/www/i18n/en.json
+++ b/www/i18n/en.json
@@ -23,7 +23,7 @@
"force-sync": "Force sync",
"share": "Share",
"download-json-dump": "Download json dump",
- "email-log": "Email log",
+ "share-log": "Share log",
"upload-log": "Upload log",
"view-privacy": "View Privacy Policy",
"user-data": "User data",
@@ -260,16 +260,14 @@
"reading-unprocessed-data": "Reading unprocessed data..."
},
- "email-service": {
- "email-account-not-configured": "Email account is not configured, cannot send email",
- "email-account-mail-app": "You must have the mail app on your phone configured with an email address. Otherwise, this won't work",
- "going-to-email": "Going to email database from {{parentDir}}",
- "email-log": {
+ "shareFile-service": {
+ "send-to": "Please send this file to k.shankari@nrel.gov, or another OpenPATH team member.",
+ "send-log": {
"subject-logs": "emission logs",
"body-please-fill-in-what-is-wrong": "please fill in what is wrong"
},
"no-email-address-configured": "No email address configured.",
- "email-data": {
+ "send-data": {
"subject-data-dump-from-to": "Data dump from {{start}} to {{end}}",
"body-data-consists-of-list-of-entries": "Data consists of a list of entries.\nEntry formats are at https://github.com/e-mission/e-mission-server/tree/master/emission/core/wrapper \nData can be loaded locally using instructions at https://github.com/e-mission/e-mission-server#loading-test-data \n and can be manipulated using the example at https://github.com/e-mission/e-mission-server/blob/master/Timeseries_Sample.ipynb"
}
diff --git a/www/js/control/LogPage.tsx b/www/js/control/LogPage.tsx
index 96ef290b3..0d7a362c0 100644
--- a/www/js/control/LogPage.tsx
+++ b/www/js/control/LogPage.tsx
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
import { FlashList } from '@shopify/flash-list';
import { DateTime } from 'luxon';
import { AlertManager } from '../components/AlertBar';
-import { sendEmail } from './emailService';
+import { sendLocalDBFile } from '../services/shareLocalDBFile';
import { displayError, logDebug } from '../plugin/logger';
import NavBar from '../components/NavBar';
@@ -93,7 +93,7 @@ const LogPage = ({ pageVis, setPageVis }) => {
}
function emailLog() {
- sendEmail('loggerDB');
+ sendLocalDBFile('loggerDB');
}
const separator = () => ;
diff --git a/www/js/control/ProfileSettings.tsx b/www/js/control/ProfileSettings.tsx
index ab381e594..279eb570f 100644
--- a/www/js/control/ProfileSettings.tsx
+++ b/www/js/control/ProfileSettings.tsx
@@ -13,7 +13,7 @@ import useAppConfig from '../useAppConfig';
import { AlertManager } from '../components/AlertBar';
import DataDatePicker from './DataDatePicker';
import PrivacyPolicyModal from './PrivacyPolicyModal';
-import { sendEmail } from './emailService';
+import { sendLocalDBFile } from '../services/shareLocalDBFile';
import { uploadFile } from './uploadService';
import ActionMenu from '../components/ActionMenu';
import SensedPage from './SensedPage';
@@ -441,9 +441,9 @@ const ProfileSettings = () => {
action={() => setDateDumpVis(true)}>
{logUploadSection}
sendEmail('loggerDB')}>
+ action={() => sendLocalDBFile('loggerDB')}>
{
@@ -60,7 +60,7 @@ const SensedPage = ({ pageVis, setPageVis }) => {
updateEntries()} />
- sendEmail('userCacheDB')} />
+ sendLocalDBFile('userCacheDB')} />
{
- return new Promise((resolve, reject) => {
- window['cordova'].plugins['email'].hasAccount((hasAct) => {
- resolve(hasAct);
- });
- });
-}
-
-export async function sendEmail(database: string) {
- let parentDir = 'unknown';
-
- if (window['cordova'].platformId == 'ios' && !(await hasAccount())) {
- alert(i18next.t('email-service.email-account-not-configured'));
- return;
- }
-
- if (window['cordova'].platformId == 'android') {
- parentDir = 'app://databases';
- }
-
- if (window['cordova'].platformId == 'ios') {
- alert(i18next.t('email-service.email-account-mail-app'));
- logDebug(window['cordova'].file.dataDirectory);
- parentDir = window['cordova'].file.dataDirectory + '../LocalDatabase';
- }
-
- if (parentDir === 'unknown') {
- alert('parentDir unexpectedly = ' + parentDir + '!');
- }
-
- logInfo('Going to email ' + database);
- parentDir = parentDir + '/' + database;
-
- alert(i18next.t('email-service.going-to-email', { parentDir: parentDir }));
-
- let emailConfig = `k.shankari@nrel.gov`;
-
- let emailData = {
- to: emailConfig,
- attachments: [parentDir],
- subject: i18next.t('email-service.email-log.subject-logs'),
- body: i18next.t('email-service.email-log.body-please-fill-in-what-is-wrong'),
- };
-
- window['cordova'].plugins['email'].open(emailData, () => {
- logWarn(`Email app closed while sending,
- emailData = ${JSON.stringify(emailData)}`);
- });
-}
diff --git a/www/js/services/controlHelper.ts b/www/js/services/controlHelper.ts
index 1a9016557..da2e60ed7 100644
--- a/www/js/services/controlHelper.ts
+++ b/www/js/services/controlHelper.ts
@@ -54,9 +54,9 @@ export function getMyDataHelpers(fileName: string, startTimeString: string, endT
const shareObj = {
files: [attachFile],
message: i18next.t(
- 'email-service.email-data.body-data-consists-of-list-of-entries',
+ 'shareFile-service.send-data.body-data-consists-of-list-of-entries',
),
- subject: i18next.t('email-service.email-data.subject-data-dump-from-to', {
+ subject: i18next.t('shareFile-service.send-data.subject-data-dump-from-to', {
start: startTimeString,
end: endTimeString,
}),
diff --git a/www/js/services/shareLocalDBFile.ts b/www/js/services/shareLocalDBFile.ts
new file mode 100644
index 000000000..8d9a49e53
--- /dev/null
+++ b/www/js/services/shareLocalDBFile.ts
@@ -0,0 +1,40 @@
+import i18next from 'i18next';
+import { displayErrorMsg, logDebug, logInfo, logWarn } from '../plugin/logger';
+
+export async function sendLocalDBFile(database: string) {
+ let parentDir = 'unknown';
+
+ if (window['cordova'].platformId == 'android') {
+ parentDir = 'app://databases';
+ }
+
+ if (window['cordova'].platformId == 'ios') {
+ logDebug(window['cordova'].file.dataDirectory);
+ parentDir = window['cordova'].file.dataDirectory + '../LocalDatabase';
+ }
+
+ if (parentDir == 'unknown') {
+ displayErrorMsg('parentDir unexpectedly = ' + parentDir + '!');
+ return;
+ }
+
+ logInfo('Going to email ' + database);
+ parentDir = parentDir + '/' + database;
+
+ const shareObj = {
+ files: [parentDir],
+ message: i18next.t('shareFile-service.send-log.body-please-fill-in-what-is-wrong'),
+ subject: i18next.t('shareFile-service.send-log.subject-logs'),
+ };
+
+ alert(i18next.t('shareFile-service.send-to'));
+ window['plugins'].socialsharing.shareWithOptions(
+ shareObj,
+ (result) => {
+ logDebug(`Shared to app: ${result.app}`);
+ },
+ (err) => {
+ logWarn(`Sharing failed with error: ${err}`);
+ },
+ );
+}
From 3e0ddb8ff0f973005c8e40d24ee8e64e2e811b05 Mon Sep 17 00:00:00 2001
From: Katie Rischpater <98350084+the-bay-kay@users.noreply.github.com>
Date: Wed, 22 May 2024 11:33:29 -0700
Subject: [PATCH 02/11] Re-Added email plugin for Android
- Issues with socialSharing, `loggerDB` file, and Gmail App
- Because Gmail is default mail on Android, we want to make sure it works
- Reverting to old plugin to make sure this sends correctly
- Tested and confirmed send works on iOS & Android Hardware
- Please see PR for further details
---
package.cordovabuild.json | 2 +
www/js/services/shareLocalDBFile.ts | 60 +++++++++++++++++++----------
www/js/usePermissionStatus.ts | 16 ++++----
3 files changed, 50 insertions(+), 28 deletions(-)
diff --git a/package.cordovabuild.json b/package.cordovabuild.json
index 0864d8184..d84baa02c 100644
--- a/package.cordovabuild.json
+++ b/package.cordovabuild.json
@@ -67,6 +67,7 @@
"ANDROID_HOST": " ",
"ANDROID_PATHPREFIX": "/"
},
+ "cordova-plugin-email-composer": {},
"cordova-plugin-x-socialsharing": {
"PHOTO_LIBRARY_ADD_USAGE_DESCRIPTION": "This app requires photo library access to share photos on social media.",
"PHOTO_LIBRARY_USAGE_DESCRIPTION": "This app requires photo library access to share photos on social media."
@@ -127,6 +128,7 @@
"cordova-plugin-em-settings": "git+https://github.com/e-mission/cordova-connection-settings.git#v1.2.3",
"cordova-plugin-em-unifiedlogger": "git+https://github.com/e-mission/cordova-unified-logger.git#v1.3.6",
"cordova-plugin-em-usercache": "git+https://github.com/e-mission/cordova-usercache.git#v1.1.9",
+ "cordova-plugin-email-composer": "git+https://github.com/katzer/cordova-plugin-email-composer.git#0.10.1",
"cordova-plugin-file": "8.0.0",
"cordova-plugin-inappbrowser": "5.0.0",
"cordova-plugin-ionic-keyboard": "2.2.0",
diff --git a/www/js/services/shareLocalDBFile.ts b/www/js/services/shareLocalDBFile.ts
index 8d9a49e53..2f4c3e4fb 100644
--- a/www/js/services/shareLocalDBFile.ts
+++ b/www/js/services/shareLocalDBFile.ts
@@ -6,35 +6,55 @@ export async function sendLocalDBFile(database: string) {
if (window['cordova'].platformId == 'android') {
parentDir = 'app://databases';
+ logInfo('Going to email ' + database);
+
+ parentDir = parentDir + '/' + database;
+
+ const emailData = {
+ to: 'k.shankari@nrel.gov',
+ attachments: [parentDir],
+ subject: i18next.t('shareFile-service.send-log.body-please-fill-in-what-is-wrong'),
+ body: i18next.t('shareFile-service.send-log.subject-logs'),
+ };
+
+ alert(i18next.t('shareFile-service.send-to'));
+
+ // Gmail app has issues attatching `loggerDB` file when using the `socialSharing`
+ // plugin. As such, we'll keep using this plugin for Android - since GMail is
+ // the default on Android, we want to support this!
+ window['cordova'].plugins['email'].open(emailData, () => {
+ logWarn(`Email app closed while sending,
+ emailData = ${JSON.stringify(emailData)}`);
+ });
}
if (window['cordova'].platformId == 'ios') {
logDebug(window['cordova'].file.dataDirectory);
parentDir = window['cordova'].file.dataDirectory + '../LocalDatabase';
+
+ logInfo('Going to email ' + database);
+ parentDir = parentDir + '/' + database;
+
+ const shareObj = {
+ files: [parentDir],
+ message: i18next.t('shareFile-service.send-log.body-please-fill-in-what-is-wrong'),
+ subject: i18next.t('shareFile-service.send-log.subject-logs'),
+ };
+
+ alert(i18next.t('shareFile-service.send-to'));
+ window['plugins'].socialsharing.shareWithOptions(
+ shareObj,
+ (result) => {
+ logDebug(`Shared to app: ${result.app}`);
+ },
+ (err) => {
+ logWarn(`Sharing failed with error: ${err}`);
+ },
+ );
}
if (parentDir == 'unknown') {
displayErrorMsg('parentDir unexpectedly = ' + parentDir + '!');
return;
}
-
- logInfo('Going to email ' + database);
- parentDir = parentDir + '/' + database;
-
- const shareObj = {
- files: [parentDir],
- message: i18next.t('shareFile-service.send-log.body-please-fill-in-what-is-wrong'),
- subject: i18next.t('shareFile-service.send-log.subject-logs'),
- };
-
- alert(i18next.t('shareFile-service.send-to'));
- window['plugins'].socialsharing.shareWithOptions(
- shareObj,
- (result) => {
- logDebug(`Shared to app: ${result.app}`);
- },
- (err) => {
- logWarn(`Sharing failed with error: ${err}`);
- },
- );
}
diff --git a/www/js/usePermissionStatus.ts b/www/js/usePermissionStatus.ts
index f8fef085b..34f215a4a 100644
--- a/www/js/usePermissionStatus.ts
+++ b/www/js/usePermissionStatus.ts
@@ -136,12 +136,12 @@ const usePermissionStatus = () => {
androidVersion < 6
? 'intro.appstatus.locperms.description.android-lt-6'
: androidVersion < 10
- ? 'intro.appstatus.locperms.description.android-6-9'
- : androidVersion < 11
- ? 'intro.appstatus.locperms.description.android-10'
- : androidVersion < 12
- ? 'intro.appstatus.locperms.description.android-11'
- : 'intro.appstatus.locperms.description.android-gte-12';
+ ? 'intro.appstatus.locperms.description.android-6-9'
+ : androidVersion < 11
+ ? 'intro.appstatus.locperms.description.android-10'
+ : androidVersion < 12
+ ? 'intro.appstatus.locperms.description.android-11'
+ : 'intro.appstatus.locperms.description.android-gte-12';
logDebug('description tags are ' + androidSettingsDescTag + ' ' + androidPermDescTag);
// location settings
let locSettingsCheck = {
@@ -392,8 +392,8 @@ const usePermissionStatus = () => {
androidVersion == 12
? 'intro.appstatus.unusedapprestrict.description.android-disable-12'
: androidVersion < 12
- ? 'intro.appstatus.unusedapprestrict.description.android-disable-lt-12'
- : 'intro.appstatus.unusedapprestrict.description.android-disable-gte-13';
+ ? 'intro.appstatus.unusedapprestrict.description.android-disable-lt-12'
+ : 'intro.appstatus.unusedapprestrict.description.android-disable-gte-13';
let unusedAppsUnrestrictedCheck = {
name: t('intro.appstatus.unusedapprestrict.name'),
desc: t(androidUnusedDescTag),
From 7704af9a1b27e8df6ab1cd26c3b0f0e02c047c0e Mon Sep 17 00:00:00 2001
From: Katie Rischpater <98350084+the-bay-kay@users.noreply.github.com>
Date: Wed, 22 May 2024 11:52:00 -0700
Subject: [PATCH 03/11] Fixed Prettier Formatting
---
www/js/usePermissionStatus.ts | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/www/js/usePermissionStatus.ts b/www/js/usePermissionStatus.ts
index 34f215a4a..f8fef085b 100644
--- a/www/js/usePermissionStatus.ts
+++ b/www/js/usePermissionStatus.ts
@@ -136,12 +136,12 @@ const usePermissionStatus = () => {
androidVersion < 6
? 'intro.appstatus.locperms.description.android-lt-6'
: androidVersion < 10
- ? 'intro.appstatus.locperms.description.android-6-9'
- : androidVersion < 11
- ? 'intro.appstatus.locperms.description.android-10'
- : androidVersion < 12
- ? 'intro.appstatus.locperms.description.android-11'
- : 'intro.appstatus.locperms.description.android-gte-12';
+ ? 'intro.appstatus.locperms.description.android-6-9'
+ : androidVersion < 11
+ ? 'intro.appstatus.locperms.description.android-10'
+ : androidVersion < 12
+ ? 'intro.appstatus.locperms.description.android-11'
+ : 'intro.appstatus.locperms.description.android-gte-12';
logDebug('description tags are ' + androidSettingsDescTag + ' ' + androidPermDescTag);
// location settings
let locSettingsCheck = {
@@ -392,8 +392,8 @@ const usePermissionStatus = () => {
androidVersion == 12
? 'intro.appstatus.unusedapprestrict.description.android-disable-12'
: androidVersion < 12
- ? 'intro.appstatus.unusedapprestrict.description.android-disable-lt-12'
- : 'intro.appstatus.unusedapprestrict.description.android-disable-gte-13';
+ ? 'intro.appstatus.unusedapprestrict.description.android-disable-lt-12'
+ : 'intro.appstatus.unusedapprestrict.description.android-disable-gte-13';
let unusedAppsUnrestrictedCheck = {
name: t('intro.appstatus.unusedapprestrict.name'),
desc: t(androidUnusedDescTag),
From 1233e58abe0a08b14a44d3cbc05b11b88772fc7c Mon Sep 17 00:00:00 2001
From: Katie Rischpater <98350084+the-bay-kay@users.noreply.github.com>
Date: Mon, 24 Jun 2024 11:51:41 -0700
Subject: [PATCH 04/11] Revert "Fixed Prettier Formatting"
This reverts commit 7704af9a1b27e8df6ab1cd26c3b0f0e02c047c0e.
Reverting to restore parity on iOS / Android
---
www/js/usePermissionStatus.ts | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/www/js/usePermissionStatus.ts b/www/js/usePermissionStatus.ts
index f8fef085b..34f215a4a 100644
--- a/www/js/usePermissionStatus.ts
+++ b/www/js/usePermissionStatus.ts
@@ -136,12 +136,12 @@ const usePermissionStatus = () => {
androidVersion < 6
? 'intro.appstatus.locperms.description.android-lt-6'
: androidVersion < 10
- ? 'intro.appstatus.locperms.description.android-6-9'
- : androidVersion < 11
- ? 'intro.appstatus.locperms.description.android-10'
- : androidVersion < 12
- ? 'intro.appstatus.locperms.description.android-11'
- : 'intro.appstatus.locperms.description.android-gte-12';
+ ? 'intro.appstatus.locperms.description.android-6-9'
+ : androidVersion < 11
+ ? 'intro.appstatus.locperms.description.android-10'
+ : androidVersion < 12
+ ? 'intro.appstatus.locperms.description.android-11'
+ : 'intro.appstatus.locperms.description.android-gte-12';
logDebug('description tags are ' + androidSettingsDescTag + ' ' + androidPermDescTag);
// location settings
let locSettingsCheck = {
@@ -392,8 +392,8 @@ const usePermissionStatus = () => {
androidVersion == 12
? 'intro.appstatus.unusedapprestrict.description.android-disable-12'
: androidVersion < 12
- ? 'intro.appstatus.unusedapprestrict.description.android-disable-lt-12'
- : 'intro.appstatus.unusedapprestrict.description.android-disable-gte-13';
+ ? 'intro.appstatus.unusedapprestrict.description.android-disable-lt-12'
+ : 'intro.appstatus.unusedapprestrict.description.android-disable-gte-13';
let unusedAppsUnrestrictedCheck = {
name: t('intro.appstatus.unusedapprestrict.name'),
desc: t(androidUnusedDescTag),
From e81164c6ecb01edfced445772ab008f20e6301f9 Mon Sep 17 00:00:00 2001
From: Katie Rischpater <98350084+the-bay-kay@users.noreply.github.com>
Date: Mon, 24 Jun 2024 11:52:20 -0700
Subject: [PATCH 05/11] Revert "Re-Added email plugin for Android"
This reverts commit 3e0ddb8ff0f973005c8e40d24ee8e64e2e811b05.
Reverting to restory parity on iOS / Android
---
package.cordovabuild.json | 2 -
www/js/services/shareLocalDBFile.ts | 60 ++++++++++-------------------
www/js/usePermissionStatus.ts | 16 ++++----
3 files changed, 28 insertions(+), 50 deletions(-)
diff --git a/package.cordovabuild.json b/package.cordovabuild.json
index d84baa02c..0864d8184 100644
--- a/package.cordovabuild.json
+++ b/package.cordovabuild.json
@@ -67,7 +67,6 @@
"ANDROID_HOST": " ",
"ANDROID_PATHPREFIX": "/"
},
- "cordova-plugin-email-composer": {},
"cordova-plugin-x-socialsharing": {
"PHOTO_LIBRARY_ADD_USAGE_DESCRIPTION": "This app requires photo library access to share photos on social media.",
"PHOTO_LIBRARY_USAGE_DESCRIPTION": "This app requires photo library access to share photos on social media."
@@ -128,7 +127,6 @@
"cordova-plugin-em-settings": "git+https://github.com/e-mission/cordova-connection-settings.git#v1.2.3",
"cordova-plugin-em-unifiedlogger": "git+https://github.com/e-mission/cordova-unified-logger.git#v1.3.6",
"cordova-plugin-em-usercache": "git+https://github.com/e-mission/cordova-usercache.git#v1.1.9",
- "cordova-plugin-email-composer": "git+https://github.com/katzer/cordova-plugin-email-composer.git#0.10.1",
"cordova-plugin-file": "8.0.0",
"cordova-plugin-inappbrowser": "5.0.0",
"cordova-plugin-ionic-keyboard": "2.2.0",
diff --git a/www/js/services/shareLocalDBFile.ts b/www/js/services/shareLocalDBFile.ts
index 2f4c3e4fb..8d9a49e53 100644
--- a/www/js/services/shareLocalDBFile.ts
+++ b/www/js/services/shareLocalDBFile.ts
@@ -6,55 +6,35 @@ export async function sendLocalDBFile(database: string) {
if (window['cordova'].platformId == 'android') {
parentDir = 'app://databases';
- logInfo('Going to email ' + database);
-
- parentDir = parentDir + '/' + database;
-
- const emailData = {
- to: 'k.shankari@nrel.gov',
- attachments: [parentDir],
- subject: i18next.t('shareFile-service.send-log.body-please-fill-in-what-is-wrong'),
- body: i18next.t('shareFile-service.send-log.subject-logs'),
- };
-
- alert(i18next.t('shareFile-service.send-to'));
-
- // Gmail app has issues attatching `loggerDB` file when using the `socialSharing`
- // plugin. As such, we'll keep using this plugin for Android - since GMail is
- // the default on Android, we want to support this!
- window['cordova'].plugins['email'].open(emailData, () => {
- logWarn(`Email app closed while sending,
- emailData = ${JSON.stringify(emailData)}`);
- });
}
if (window['cordova'].platformId == 'ios') {
logDebug(window['cordova'].file.dataDirectory);
parentDir = window['cordova'].file.dataDirectory + '../LocalDatabase';
-
- logInfo('Going to email ' + database);
- parentDir = parentDir + '/' + database;
-
- const shareObj = {
- files: [parentDir],
- message: i18next.t('shareFile-service.send-log.body-please-fill-in-what-is-wrong'),
- subject: i18next.t('shareFile-service.send-log.subject-logs'),
- };
-
- alert(i18next.t('shareFile-service.send-to'));
- window['plugins'].socialsharing.shareWithOptions(
- shareObj,
- (result) => {
- logDebug(`Shared to app: ${result.app}`);
- },
- (err) => {
- logWarn(`Sharing failed with error: ${err}`);
- },
- );
}
if (parentDir == 'unknown') {
displayErrorMsg('parentDir unexpectedly = ' + parentDir + '!');
return;
}
+
+ logInfo('Going to email ' + database);
+ parentDir = parentDir + '/' + database;
+
+ const shareObj = {
+ files: [parentDir],
+ message: i18next.t('shareFile-service.send-log.body-please-fill-in-what-is-wrong'),
+ subject: i18next.t('shareFile-service.send-log.subject-logs'),
+ };
+
+ alert(i18next.t('shareFile-service.send-to'));
+ window['plugins'].socialsharing.shareWithOptions(
+ shareObj,
+ (result) => {
+ logDebug(`Shared to app: ${result.app}`);
+ },
+ (err) => {
+ logWarn(`Sharing failed with error: ${err}`);
+ },
+ );
}
diff --git a/www/js/usePermissionStatus.ts b/www/js/usePermissionStatus.ts
index 34f215a4a..f8fef085b 100644
--- a/www/js/usePermissionStatus.ts
+++ b/www/js/usePermissionStatus.ts
@@ -136,12 +136,12 @@ const usePermissionStatus = () => {
androidVersion < 6
? 'intro.appstatus.locperms.description.android-lt-6'
: androidVersion < 10
- ? 'intro.appstatus.locperms.description.android-6-9'
- : androidVersion < 11
- ? 'intro.appstatus.locperms.description.android-10'
- : androidVersion < 12
- ? 'intro.appstatus.locperms.description.android-11'
- : 'intro.appstatus.locperms.description.android-gte-12';
+ ? 'intro.appstatus.locperms.description.android-6-9'
+ : androidVersion < 11
+ ? 'intro.appstatus.locperms.description.android-10'
+ : androidVersion < 12
+ ? 'intro.appstatus.locperms.description.android-11'
+ : 'intro.appstatus.locperms.description.android-gte-12';
logDebug('description tags are ' + androidSettingsDescTag + ' ' + androidPermDescTag);
// location settings
let locSettingsCheck = {
@@ -392,8 +392,8 @@ const usePermissionStatus = () => {
androidVersion == 12
? 'intro.appstatus.unusedapprestrict.description.android-disable-12'
: androidVersion < 12
- ? 'intro.appstatus.unusedapprestrict.description.android-disable-lt-12'
- : 'intro.appstatus.unusedapprestrict.description.android-disable-gte-13';
+ ? 'intro.appstatus.unusedapprestrict.description.android-disable-lt-12'
+ : 'intro.appstatus.unusedapprestrict.description.android-disable-gte-13';
let unusedAppsUnrestrictedCheck = {
name: t('intro.appstatus.unusedapprestrict.name'),
desc: t(androidUnusedDescTag),
From 55c32186586bfe590dc884ea6250189b299a07ac Mon Sep 17 00:00:00 2001
From: Katie Rischpater <98350084+the-bay-kay@users.noreply.github.com>
Date: Wed, 26 Jun 2024 14:32:26 -0700
Subject: [PATCH 06/11] Reworked ShareLocalDB, add extension when sharing -
Added File I/O to send logs with `.txt` extension - See PR 1160 for further
details
---
www/js/services/shareLocalDBFile.ts | 132 ++++++++++++++++++++++------
1 file changed, 104 insertions(+), 28 deletions(-)
diff --git a/www/js/services/shareLocalDBFile.ts b/www/js/services/shareLocalDBFile.ts
index 8d9a49e53..6a54f7377 100644
--- a/www/js/services/shareLocalDBFile.ts
+++ b/www/js/services/shareLocalDBFile.ts
@@ -1,40 +1,116 @@
import i18next from 'i18next';
-import { displayErrorMsg, logDebug, logInfo, logWarn } from '../plugin/logger';
+import { displayError, displayErrorMsg, logDebug, logWarn } from '../plugin/logger';
-export async function sendLocalDBFile(database: string) {
- let parentDir = 'unknown';
+function localDBHelpers(fileName: string, fileExtension: string = '.txt') {
+ async function localCopyFile() {
+ return new Promise((resolve, reject) => {
+ let pathToFile, parentDirectory;
+ if (window['cordova'].platformId == 'android') {
+ parentDirectory = window['cordova'].file.dataDirectory;
+ pathToFile = fileName;
+ } else if (window['cordova'].platformId == 'ios') {
+ parentDirectory = window['cordova'].file.dataDirectory + '../';
+ pathToFile = 'LocalDatabase/' + fileName;
+ } else {
+ displayErrorMsg('Error: Unknown OS!');
+ throw new Error('Error: Unknown OS!');
+ }
- if (window['cordova'].platformId == 'android') {
- parentDir = 'app://databases';
- }
+ window['resolveLocalFileSystemURL'](parentDirectory, (fs) => {
+ fs.filesystem.root.getFile(pathToFile, { create: false, exclusive: false }, (fileEntry) => {
+ // logDebug(`fileEntry ${fileEntry.nativeURL} is file? ${fileEntry.isFile.toString()}`);
+ logDebug(`fileEntry is: ${JSON.stringify(fileEntry, null, 2)}`);
+ window['resolveLocalFileSystemURL'](window['cordova'].file.cacheDirectory, (copyDir) => {
+ logDebug(`DirectoryEntry is: ${JSON.stringify(copyDir.filesystem.root, null, 2)}`);
- if (window['cordova'].platformId == 'ios') {
- logDebug(window['cordova'].file.dataDirectory);
- parentDir = window['cordova'].file.dataDirectory + '../LocalDatabase';
+ fileEntry.copyTo(
+ copyDir.filesystem.root,
+ fileName + fileExtension,
+ (res) => {
+ logDebug(`Res: ${res}`);
+ resolve();
+ },
+ (rej) => {
+ logDebug(`Rej: ${JSON.stringify(rej, null, 2)}`);
+ reject();
+ },
+ );
+ });
+ });
+ });
+ });
}
- if (parentDir == 'unknown') {
- displayErrorMsg('parentDir unexpectedly = ' + parentDir + '!');
- return;
+ function localShareFile() {
+ return new Promise((resolve, reject) => {
+ window['resolveLocalFileSystemURL'](window['cordova'].file.cacheDirectory, (fs) => {
+ fs.filesystem.root.getFile(
+ fileName + fileExtension,
+ null,
+ (fileEntry) => {
+ const shareObj = {
+ files: [fileEntry.nativeURL],
+ message: i18next.t('shareFile-service.send-log.body-please-fill-in-what-is-wrong'),
+ subject: i18next.t('shareFile-service.send-log.subject-logs'),
+ };
+ 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}`);
+ },
+ );
+ },
+ (error) => {
+ displayError(error, 'Error while sharing logs');
+ reject(error);
+ },
+ );
+ });
+ });
}
- logInfo('Going to email ' + database);
- parentDir = parentDir + '/' + database;
+ function localClearData() {
+ return new Promise((resolve, reject) => {
+ window['resolveLocalFileSystemURL'](window['cordova'].file.cacheDirectory, (fs) => {
+ fs.filesystem.root.getFile(fileName + fileExtension, null, (fileEntry) => {
+ fileEntry.remove(
+ () => {
+ logDebug(`Successfully cleaned up file ${fileName}`);
+ resolve();
+ },
+ (err) => {
+ logWarn(`Error deleting ${fileName} : ${err}`);
+ reject(err);
+ },
+ );
+ });
+ });
+ });
+ }
- const shareObj = {
- files: [parentDir],
- message: i18next.t('shareFile-service.send-log.body-please-fill-in-what-is-wrong'),
- subject: i18next.t('shareFile-service.send-log.subject-logs'),
+ return {
+ copyFile: localCopyFile,
+ shareData: localShareFile,
+ clearData: localClearData,
};
-
+}
+export async function sendLocalDBFile(database: string) {
alert(i18next.t('shareFile-service.send-to'));
- window['plugins'].socialsharing.shareWithOptions(
- shareObj,
- (result) => {
- logDebug(`Shared to app: ${result.app}`);
- },
- (err) => {
- logWarn(`Sharing failed with error: ${err}`);
- },
- );
+
+ const dataMethods = localDBHelpers(database);
+ dataMethods
+ .copyFile()
+ .then(dataMethods.shareData)
+ .then(dataMethods.clearData)
+ .then(() => {
+ logDebug(`File Shared!`);
+ })
+ .catch((err) => {
+ displayError(err);
+ });
}
From d5ab4aba3b25999e031105c98d5548ec4da048c8 Mon Sep 17 00:00:00 2001
From: louisg1337
Date: Tue, 2 Jul 2024 14:54:56 -0400
Subject: [PATCH 07/11] Added in fix to get Android to work
---
www/js/services/shareLocalDBFile.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/www/js/services/shareLocalDBFile.ts b/www/js/services/shareLocalDBFile.ts
index 6a54f7377..2454133f0 100644
--- a/www/js/services/shareLocalDBFile.ts
+++ b/www/js/services/shareLocalDBFile.ts
@@ -6,8 +6,8 @@ function localDBHelpers(fileName: string, fileExtension: string = '.txt') {
return new Promise((resolve, reject) => {
let pathToFile, parentDirectory;
if (window['cordova'].platformId == 'android') {
- parentDirectory = window['cordova'].file.dataDirectory;
- pathToFile = fileName;
+ parentDirectory = window['cordova'].file.dataDirectory.replace('files', 'databases')
+ pathToFile = parentDirectory.replace('file://', '') + fileName;
} else if (window['cordova'].platformId == 'ios') {
parentDirectory = window['cordova'].file.dataDirectory + '../';
pathToFile = 'LocalDatabase/' + fileName;
From a7e1124e9ce2d4f92a398e0c96d38ce43c12525d Mon Sep 17 00:00:00 2001
From: louisg1337
Date: Tue, 2 Jul 2024 15:56:37 -0400
Subject: [PATCH 08/11] Ran prettier
---
www/js/services/shareLocalDBFile.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/www/js/services/shareLocalDBFile.ts b/www/js/services/shareLocalDBFile.ts
index 2454133f0..9578c72ec 100644
--- a/www/js/services/shareLocalDBFile.ts
+++ b/www/js/services/shareLocalDBFile.ts
@@ -6,7 +6,7 @@ function localDBHelpers(fileName: string, fileExtension: string = '.txt') {
return new Promise((resolve, reject) => {
let pathToFile, parentDirectory;
if (window['cordova'].platformId == 'android') {
- parentDirectory = window['cordova'].file.dataDirectory.replace('files', 'databases')
+ parentDirectory = window['cordova'].file.dataDirectory.replace('files', 'databases');
pathToFile = parentDirectory.replace('file://', '') + fileName;
} else if (window['cordova'].platformId == 'ios') {
parentDirectory = window['cordova'].file.dataDirectory + '../';
From 8d4aeda48748770bf9e5399e04cfef5617565e64 Mon Sep 17 00:00:00 2001
From: louisg1337
Date: Fri, 5 Jul 2024 17:36:16 -0400
Subject: [PATCH 09/11] Fixed translation. Added in more comments and better
error handling to sharing functions
---
www/i18n/en.json | 2 +-
www/js/services/shareLocalDBFile.ts | 11 ++++++++---
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/www/i18n/en.json b/www/i18n/en.json
index 0545624ab..7347f8e46 100644
--- a/www/i18n/en.json
+++ b/www/i18n/en.json
@@ -279,7 +279,7 @@
},
"shareFile-service": {
- "send-to": "Please send this file to k.shankari@nrel.gov, or another OpenPATH team member.",
+ "send-to": "Please send this file to openpath@nrel.gov, or another OpenPATH team member.",
"send-log": {
"subject-logs": "emission logs",
"body-please-fill-in-what-is-wrong": "please fill in what is wrong"
diff --git a/www/js/services/shareLocalDBFile.ts b/www/js/services/shareLocalDBFile.ts
index 9578c72ec..593b5c84e 100644
--- a/www/js/services/shareLocalDBFile.ts
+++ b/www/js/services/shareLocalDBFile.ts
@@ -6,9 +6,12 @@ function localDBHelpers(fileName: string, fileExtension: string = '.txt') {
return new Promise((resolve, reject) => {
let pathToFile, parentDirectory;
if (window['cordova'].platformId == 'android') {
+ // parentDirectory: file:///data/user/0/edu.berkeley.eecs.emission/files/
parentDirectory = window['cordova'].file.dataDirectory.replace('files', 'databases');
+ // pathToFile: /data/user/0/edu.berkeley.eecs.emission/files/
pathToFile = parentDirectory.replace('file://', '') + fileName;
} else if (window['cordova'].platformId == 'ios') {
+ // parentDirectory: file:///var/mobile/Containers/Data/Application/<32-hex-digit-id>/Library/NoCloud/../
parentDirectory = window['cordova'].file.dataDirectory + '../';
pathToFile = 'LocalDatabase/' + fileName;
} else {
@@ -17,6 +20,8 @@ function localDBHelpers(fileName: string, fileExtension: string = '.txt') {
}
window['resolveLocalFileSystemURL'](parentDirectory, (fs) => {
+ // On iOS, pass in relative path to getFile https://github.com/e-mission/e-mission-phone/pull/1160#issuecomment-2192112472
+ // On Android, pass in absolute path to getFile https://github.com/e-mission/e-mission-phone/pull/1160#issuecomment-2204297874
fs.filesystem.root.getFile(pathToFile, { create: false, exclusive: false }, (fileEntry) => {
// logDebug(`fileEntry ${fileEntry.nativeURL} is file? ${fileEntry.isFile.toString()}`);
logDebug(`fileEntry is: ${JSON.stringify(fileEntry, null, 2)}`);
@@ -31,7 +36,7 @@ function localDBHelpers(fileName: string, fileExtension: string = '.txt') {
resolve();
},
(rej) => {
- logDebug(`Rej: ${JSON.stringify(rej, null, 2)}`);
+ displayErrorMsg(`Rej: ${JSON.stringify(rej, null, 2)}`);
reject();
},
);
@@ -61,7 +66,7 @@ function localDBHelpers(fileName: string, fileExtension: string = '.txt') {
resolve();
},
(msg) => {
- logDebug(`Sharing failed with message ${msg}`);
+ displayErrorMsg(`Sharing failed with message ${msg}`);
},
);
},
@@ -84,7 +89,7 @@ function localDBHelpers(fileName: string, fileExtension: string = '.txt') {
resolve();
},
(err) => {
- logWarn(`Error deleting ${fileName} : ${err}`);
+ displayError(err, `Error deleting ${fileName}`);
reject(err);
},
);
From 21e9b708786bee07f43586e545668a32e05824dd Mon Sep 17 00:00:00 2001
From: louisg1337
Date: Fri, 5 Jul 2024 17:52:05 -0400
Subject: [PATCH 10/11] Renamed clear data to something more accurate
---
www/js/services/shareLocalDBFile.ts | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/www/js/services/shareLocalDBFile.ts b/www/js/services/shareLocalDBFile.ts
index 593b5c84e..1aae281b9 100644
--- a/www/js/services/shareLocalDBFile.ts
+++ b/www/js/services/shareLocalDBFile.ts
@@ -79,7 +79,7 @@ function localDBHelpers(fileName: string, fileExtension: string = '.txt') {
});
}
- function localClearData() {
+ function localClearTmpFile() {
return new Promise((resolve, reject) => {
window['resolveLocalFileSystemURL'](window['cordova'].file.cacheDirectory, (fs) => {
fs.filesystem.root.getFile(fileName + fileExtension, null, (fileEntry) => {
@@ -101,7 +101,7 @@ function localDBHelpers(fileName: string, fileExtension: string = '.txt') {
return {
copyFile: localCopyFile,
shareData: localShareFile,
- clearData: localClearData,
+ clearTmpFile: localClearTmpFile,
};
}
export async function sendLocalDBFile(database: string) {
@@ -111,7 +111,7 @@ export async function sendLocalDBFile(database: string) {
dataMethods
.copyFile()
.then(dataMethods.shareData)
- .then(dataMethods.clearData)
+ .then(dataMethods.clearTmpFile)
.then(() => {
logDebug(`File Shared!`);
})
From f3211a08f01b6494adafaf1c71823bce6c28e238 Mon Sep 17 00:00:00 2001
From: Louis Grassi <79764532+louisg1337@users.noreply.github.com>
Date: Mon, 8 Jul 2024 15:12:29 -0400
Subject: [PATCH 11/11] Updated error handling
Co-authored-by: K. Shankari
---
www/js/services/shareLocalDBFile.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/www/js/services/shareLocalDBFile.ts b/www/js/services/shareLocalDBFile.ts
index 1aae281b9..484604371 100644
--- a/www/js/services/shareLocalDBFile.ts
+++ b/www/js/services/shareLocalDBFile.ts
@@ -65,8 +65,8 @@ function localDBHelpers(fileName: string, fileExtension: string = '.txt') {
logDebug(`Shared to app: ${result.app}`);
resolve();
},
- (msg) => {
- displayErrorMsg(`Sharing failed with message ${msg}`);
+ (error) => {
+ displayError(error, `Sharing failed with error`);
},
);
},