diff --git a/package.json b/package.json index e8006429..bd7f0357 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "@react-navigation/native": "^5.8.10", "@react-navigation/stack": "^5.12.8", "@standardnotes/sncrypto-common": "1.2.9", - "@standardnotes/snjs": "^2.0.57", + "@standardnotes/snjs": "^2.0.59", "js-base64": "^3.5.2", "moment": "^2.29.1", "react": "16.13.1", diff --git a/src/lib/application.ts b/src/lib/application.ts index f79dbdaa..3e0e9b3a 100644 --- a/src/lib/application.ts +++ b/src/lib/application.ts @@ -1,6 +1,9 @@ import { SCREEN_AUTHENTICATE } from '@Screens/screens'; import { Challenge, + ChallengePrompt, + ChallengeReason, + ChallengeValidation, DeinitSource, Environment, platformFromString, @@ -10,7 +13,7 @@ import { import { Platform } from 'react-native'; import VersionInfo from 'react-native-version-info'; import { AlertService } from './alert_service'; -import { ApplicationState } from './application_state'; +import { ApplicationState, UnlockTiming } from './application_state'; import { BackupsService } from './backups_service'; import { ComponentGroup } from './component_group'; import { ComponentManager } from './component_manager'; @@ -39,6 +42,8 @@ export class MobileApplication extends SNApplication { private startedDeinit: boolean = false; public Uuid: string; // UI remounts when Uuid changes + static previouslyLaunched: boolean = false; + constructor(deviceInterface: MobileDeviceInterface, identifier: string) { super( Environment.Mobile, @@ -63,6 +68,14 @@ export class MobileApplication extends SNApplication { this.componentGroup = new ComponentGroup(this); } + static getPreviouslyLaunched() { + return this.previouslyLaunched; + } + + static setPreviouslyLaunched() { + this.previouslyLaunched = true; + } + public hasStartedDeinit() { return this.startedDeinit; } @@ -83,6 +96,33 @@ export class MobileApplication extends SNApplication { super.deinit(source); } + /** @override */ + getLaunchChallenge() { + const challenge = super.getLaunchChallenge(); + + if (!challenge) { + return undefined; + } + + const previouslyLaunched = MobileApplication.getPreviouslyLaunched(); + const biometricsTiming = this.getAppState().biometricsTiming; + + if (previouslyLaunched && biometricsTiming === UnlockTiming.OnQuit) { + const filteredPrompts = challenge.prompts.filter( + (prompt: ChallengePrompt) => + prompt.validation !== ChallengeValidation.Biometric + ); + + return new Challenge( + filteredPrompts, + ChallengeReason.ApplicationUnlock, + false + ); + } + + return challenge; + } + promptForChallenge(challenge: Challenge) { push(SCREEN_AUTHENTICATE, { challenge, title: challenge.modalTitle }); } diff --git a/src/lib/application_state.ts b/src/lib/application_state.ts index 31d4e579..f558285e 100644 --- a/src/lib/application_state.ts +++ b/src/lib/application_state.ts @@ -171,10 +171,12 @@ export class ApplicationState extends ApplicationService { } } ); + + await this.loadUnlockTiming(); } async onAppLaunch() { - await this.getUnlockTiming(); + MobileApplication.setPreviouslyLaunched(); this.setScreenshotPrivacy(); } @@ -248,7 +250,7 @@ export class ApplicationState extends ApplicationService { } } - private async getUnlockTiming() { + private async loadUnlockTiming() { this.passcodeTiming = await this.getPasscodeTiming(); this.biometricsTiming = await this.getBiometricsTiming(); } diff --git a/yarn.lock b/yarn.lock index 80a467cc..4f6d0004 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1385,10 +1385,10 @@ resolved "https://registry.yarnpkg.com/@standardnotes/sncrypto-common/-/sncrypto-common-1.2.9.tgz#5212a959e4ec563584e42480bfd39ef129c3cbdf" integrity sha512-xJ5IUGOZztjSgNP/6XL+Ut5+q9UgSTv6xMtKkcQC5aJxCOkJy9u6RamPLdF00WQgwibxx2tu0e43bKUjTgzMig== -"@standardnotes/snjs@^2.0.57": - version "2.0.57" - resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.0.57.tgz#758d30d9074aa463ca2b642783d929a10a1a1c9f" - integrity sha512-s2FP024TziZnt0nJ10Tbja3IQ2KOITA67EGchadAN+vapXEicTDX2MSCPzlvk2D1M494zu15vWwQX1ryeHvHHA== +"@standardnotes/snjs@^2.0.59": + version "2.0.59" + resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.0.59.tgz#ff9b60407d7810910d9bcc92e3db6bede5f28f1f" + integrity sha512-qt6C7KOapNaMFv+thy37scgpD/66NEwlY/RddSwxQzKFP9VWY39LYYVuDOhVgDVg18+8cK38rMTRtJag11Xy0Q== dependencies: "@standardnotes/sncrypto-common" "^1.2.9"