From d8c4278fec12472020bf80a5ce4646fa2b6825d6 Mon Sep 17 00:00:00 2001 From: Maria Zadnepryanets Date: Sun, 19 Jun 2022 18:21:19 +0200 Subject: [PATCH 1/5] Add react-native-exit-app-v2 --- db/index.js | 10 ++++++++-- ios/drip.xcodeproj/project.pbxproj | 2 ++ package.json | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/db/index.js b/db/index.js index 5872ea3..8be5198 100644 --- a/db/index.js +++ b/db/index.js @@ -2,7 +2,10 @@ import Realm from 'realm' import { LocalDate, ChronoUnit } from 'js-joda' import nodejs from 'nodejs-mobile-react-native' import fs from 'react-native-fs' -import restart from 'react-native-restart' +// Current version of react-native-restart doesn't work with our ios setup +// therefore react-native-exit-app-v2 is used to close the app after setting pwd +// import restart from 'react-native-restart' +import RNExitApp from 'react-native-exit-app-v2' import schemas from './schemas' import cycleModule from '../lib/cycle' import maybeSetNewCycleStart from '../lib/set-new-cycle-start' @@ -213,7 +216,10 @@ export async function changeEncryptionAndRestartApp(hash) { db.close() await fs.unlink(defaultPath) await fs.moveFile(copyPath, defaultPath) - restart.Restart() + // Current version of react-native-restart doesn't work with our ios setup + // therefore react-native-exit-app-v2 is used to close the app after setting pwd + // restart.Restart() + RNExitApp.exitApp() } export function isDbEmpty() { diff --git a/ios/drip.xcodeproj/project.pbxproj b/ios/drip.xcodeproj/project.pbxproj index 5efee0e..c5d97e3 100644 --- a/ios/drip.xcodeproj/project.pbxproj +++ b/ios/drip.xcodeproj/project.pbxproj @@ -525,6 +525,7 @@ "${BUILT_PRODUCTS_DIR}/RCTTypeSafety/RCTTypeSafety.framework", "${BUILT_PRODUCTS_DIR}/RNCPushNotificationIOS/RNCPushNotificationIOS.framework", "${BUILT_PRODUCTS_DIR}/RNDateTimePicker/RNDateTimePicker.framework", + "${BUILT_PRODUCTS_DIR}/RNExitApp/RNExitApp.framework", "${BUILT_PRODUCTS_DIR}/RNFS/RNFS.framework", "${BUILT_PRODUCTS_DIR}/RNShare/RNShare.framework", "${BUILT_PRODUCTS_DIR}/RNVectorIcons/RNVectorIcons.framework", @@ -563,6 +564,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTTypeSafety.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNCPushNotificationIOS.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNDateTimePicker.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNExitApp.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNFS.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNShare.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNVectorIcons.framework", diff --git a/package.json b/package.json index 684bb71..39125fa 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "react-native": "0.61.0", "react-native-calendars": "^1.19.3", "react-native-document-picker": "^4.2.0", + "react-native-exit-app-v2": "^1.2.2", "react-native-fs": "^2.19.0", "react-native-hyperlink": "0.0.19", "react-native-modal-datetime-picker": "8.0.0", From 81cc3087fdcc50e89fb89b96f1c9bae1b2f29db7 Mon Sep 17 00:00:00 2001 From: Maria Zadnepryanets Date: Sun, 19 Jun 2022 18:24:57 +0200 Subject: [PATCH 2/5] Update wordings to advise user that app will close --- i18n/en/settings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/i18n/en/settings.js b/i18n/en/settings.js index 7150780..41437fb 100644 --- a/i18n/en/settings.js +++ b/i18n/en/settings.js @@ -114,10 +114,10 @@ export default { passwordsDontMatch: "Password and confirmation don't match", backupReminderTitle: 'Read this before making changes to your password', backupReminder: - 'Just to be safe, please backup your data using the export function before making changes to your password.\n\nLonger passwords are better! Consider using a passphrase.\n\nPlease also make sure you do not lose your password. There is no way to recover your data if you do.\n\nMaking any changes to your password setting will keep your data as it was before and restart the app.', + 'Just to be safe, please backup your data using the export function before making changes to your password.\n\nLonger passwords are better! Consider using a passphrase.\n\nPlease also make sure you do not lose your password. There is no way to recover your data if you do.\n\nMaking any changes to your password setting will keep your data as it was before. After the password is updated the app will automatically close. At the new app launch please use the new password.', deleteBackupReminderTitle: 'Read this before deleting your password', deleteBackupReminder: - 'Deleting your password means your data will no longer be encrypted.\n\nJust to be safe, please backup your data using the export function before deleting your password.\n\nMaking any changes to your password setting will keep your data as it was before and restart the app.', + 'Deleting your password means your data will no longer be encrypted.\n\nJust to be safe, please backup your data using the export function before deleting your password.\n\nMaking any changes to your password setting will keep your data as it was before and restart the app. . After the password is updated the app will automatically close. At the new app launch you will not be prompted to enter the password.', }, aboutSection: { title: 'About', From ae2a05f9b08c8fcf220b176660c55f304a66a562 Mon Sep 17 00:00:00 2001 From: BloodyMarie Date: Tue, 21 Jun 2022 10:12:59 +0200 Subject: [PATCH 3/5] Add package-lock.json after clear script --- package-lock.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package-lock.json b/package-lock.json index 61d390b..21e12f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8561,6 +8561,11 @@ "resolved": "https://registry.npmjs.org/react-native-document-picker/-/react-native-document-picker-4.3.0.tgz", "integrity": "sha512-ygcY0ijlVuhxzdWnhqd917yMUFT9FF0b4CM81LWoY4/bpQYz5PGUdRAdh25kS0VA+cEUYNL2iI7OpHXq00epPA==" }, + "react-native-exit-app-v2": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/react-native-exit-app-v2/-/react-native-exit-app-v2-1.2.2.tgz", + "integrity": "sha512-RWCfmus7h99M1aONqBnWG3g3TFRzKsmok6cLAuqN5NVQAxpcgzbJZgAryA/ADpmBrBP5EIJnCBFo64ApQGOZPw==" + }, "react-native-fs": { "version": "2.19.0", "resolved": "https://registry.npmjs.org/react-native-fs/-/react-native-fs-2.19.0.tgz", From f223616ee1cd4dab0a3b64dc383ace1d6e9a440f Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin Date: Thu, 23 Jun 2022 21:40:15 +0200 Subject: [PATCH 4/5] Fork restart functionality for different platforms --- .../settings/password/show-backup-reminder.js | 42 ++++++++++--------- db/index.js | 11 ++--- db/restart-app/index.android.js | 5 +++ db/restart-app/index.ios.js | 5 +++ i18n/en/settings.js | 27 +++++++++--- 5 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 db/restart-app/index.android.js create mode 100644 db/restart-app/index.ios.js diff --git a/components/settings/password/show-backup-reminder.js b/components/settings/password/show-backup-reminder.js index bf95646..28d6b59 100644 --- a/components/settings/password/show-backup-reminder.js +++ b/components/settings/password/show-backup-reminder.js @@ -1,28 +1,32 @@ -import { Alert } from 'react-native' +import { Alert, Platform } from 'react-native' import { shared } from '../../../i18n/en/labels' import labels from '../../../i18n/en/settings' export default function showBackUpReminder(okHandler, cancelHandler, isDelete) { - let title, message - if (isDelete) { - title = labels.passwordSettings.deleteBackupReminderTitle - message = labels.passwordSettings.deleteBackupReminder - } else { - title = labels.passwordSettings.backupReminderTitle - message = labels.passwordSettings.backupReminder - } + const { title, message } = isDelete + ? labels.passwordSettings.deleteBackupReminder + : labels.passwordSettings.backupReminder + + const { backupReminderAppendix } = labels.passwordSettings + const appendix = + Platform.OS === 'ios' + ? backupReminderAppendix.ios + : backupReminderAppendix.android Alert.alert( title, - message, - [{ - text: shared.cancel, - onPress: cancelHandler, - style: 'cancel' - }, { - text: shared.ok, - onPress: okHandler - }], + message + appendix, + [ + { + text: shared.cancel, + onPress: cancelHandler, + style: 'cancel', + }, + { + text: shared.ok, + onPress: okHandler, + }, + ], { onDismiss: cancelHandler } ) -} \ No newline at end of file +} diff --git a/db/index.js b/db/index.js index 8be5198..2212823 100644 --- a/db/index.js +++ b/db/index.js @@ -2,10 +2,8 @@ import Realm from 'realm' import { LocalDate, ChronoUnit } from 'js-joda' import nodejs from 'nodejs-mobile-react-native' import fs from 'react-native-fs' -// Current version of react-native-restart doesn't work with our ios setup -// therefore react-native-exit-app-v2 is used to close the app after setting pwd -// import restart from 'react-native-restart' -import RNExitApp from 'react-native-exit-app-v2' +import { restartApp } from './restart-app' + import schemas from './schemas' import cycleModule from '../lib/cycle' import maybeSetNewCycleStart from '../lib/set-new-cycle-start' @@ -216,10 +214,7 @@ export async function changeEncryptionAndRestartApp(hash) { db.close() await fs.unlink(defaultPath) await fs.moveFile(copyPath, defaultPath) - // Current version of react-native-restart doesn't work with our ios setup - // therefore react-native-exit-app-v2 is used to close the app after setting pwd - // restart.Restart() - RNExitApp.exitApp() + restartApp() } export function isDbEmpty() { diff --git a/db/restart-app/index.android.js b/db/restart-app/index.android.js new file mode 100644 index 0000000..3a84dc2 --- /dev/null +++ b/db/restart-app/index.android.js @@ -0,0 +1,5 @@ +// Current version of react-native-restart doesn't work with our ios setup +// therefore we have a fork and use different libraries on the platforms +import restart from 'react-native-restart' + +export const restartApp = restart.Restart diff --git a/db/restart-app/index.ios.js b/db/restart-app/index.ios.js new file mode 100644 index 0000000..2d15425 --- /dev/null +++ b/db/restart-app/index.ios.js @@ -0,0 +1,5 @@ +// Current version of react-native-restart doesn't work with our ios setup +// therefore we have a fork and use different libraries on the platforms +import RNExitApp from 'react-native-exit-app-v2' + +export const restartApp = RNExitApp.exitApp diff --git a/i18n/en/settings.js b/i18n/en/settings.js index 41437fb..bb77e13 100644 --- a/i18n/en/settings.js +++ b/i18n/en/settings.js @@ -112,12 +112,27 @@ export default { enterNew: 'Please enter a new password', confirmPassword: 'Please confirm your password', passwordsDontMatch: "Password and confirmation don't match", - backupReminderTitle: 'Read this before making changes to your password', - backupReminder: - 'Just to be safe, please backup your data using the export function before making changes to your password.\n\nLonger passwords are better! Consider using a passphrase.\n\nPlease also make sure you do not lose your password. There is no way to recover your data if you do.\n\nMaking any changes to your password setting will keep your data as it was before. After the password is updated the app will automatically close. At the new app launch please use the new password.', - deleteBackupReminderTitle: 'Read this before deleting your password', - deleteBackupReminder: - 'Deleting your password means your data will no longer be encrypted.\n\nJust to be safe, please backup your data using the export function before deleting your password.\n\nMaking any changes to your password setting will keep your data as it was before and restart the app. . After the password is updated the app will automatically close. At the new app launch you will not be prompted to enter the password.', + backupReminder: { + title: 'Read this before making changes to your password', + message: ` +Just to be safe, please backup your data using the export function before making any changes to your password.\n +Longer passwords are better! Consider using a passphrase.\n +Please also make sure you do not lose your password. There is no way to recover your data if you do.\n +Making any changes to your password setting will keep your data as it was before.\n`, + }, + deleteBackupReminder: { + title: 'Read this before deleting your password', + message: ` +Deleting your password means your data will no longer be encrypted.\n +Just to be safe, please backup your data using the export function before deleting your password.\n +Making any changes to your password setting will keep your data as it was before and restart the app.\n + `, + }, + backupReminderAppendix: { + android: + 'After the password is updated the app will automatically restart.', + ios: 'After the password is updated the app will automatically close. Please reopen it manually.', + }, }, aboutSection: { title: 'About', From 7a6643cc1a7af760a846a41e02133fd5553dff98 Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin Date: Thu, 23 Jun 2022 21:46:41 +0200 Subject: [PATCH 5/5] Add alert before closing --- db/restart-app/index.ios.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/db/restart-app/index.ios.js b/db/restart-app/index.ios.js index 2d15425..0f3db9b 100644 --- a/db/restart-app/index.ios.js +++ b/db/restart-app/index.ios.js @@ -1,5 +1,11 @@ // Current version of react-native-restart doesn't work with our ios setup // therefore we have a fork and use different libraries on the platforms import RNExitApp from 'react-native-exit-app-v2' +import { Alert } from 'react-native' -export const restartApp = RNExitApp.exitApp +export const restartApp = () => { + Alert.alert('Closing app', 'App is shutting down. Please restart.') + setTimeout(() => { + RNExitApp.exitApp() + }, 3000) +}