@@ -15,12 +15,13 @@ import { useUpselling } from '@proton/pass/components/Upsell/UpsellingProvider';
1515import { DEFAULT_LOCK_TTL , UpsellRef } from '@proton/pass/constants' ;
1616import { useDesktopUnlock } from '@proton/pass/hooks/auth/useDesktopUnlock' ;
1717import { useFeatureFlag } from '@proton/pass/hooks/useFeatureFlag' ;
18- import { useActionRequest } from '@proton/pass/hooks/useRequest' ;
18+ import { useActionRequest , useRequest } from '@proton/pass/hooks/useRequest' ;
19+ import { useRerender } from '@proton/pass/hooks/useRerender' ;
1920import type { UnlockDTO } from '@proton/pass/lib/auth/lock/types' ;
2021import { LockMode } from '@proton/pass/lib/auth/lock/types' ;
2122import { ReauthAction } from '@proton/pass/lib/auth/reauth' ;
2223import { isPaidPlan } from '@proton/pass/lib/user/user.predicates' ;
23- import { lockCreateIntent } from '@proton/pass/store/actions' ;
24+ import { lockCreateIntent , passwordOnLaunchToggle } from '@proton/pass/store/actions' ;
2425import { lockCreateRequest } from '@proton/pass/store/actions/requests' ;
2526import { selectLockMode , selectLockTTL , selectPassPlan } from '@proton/pass/store/selectors' ;
2627import type { Maybe , MaybeNull , Result } from '@proton/pass/types' ;
@@ -66,8 +67,10 @@ interface LockSetup {
6667 biometrics : BiometricsState ;
6768 extensionBiometrics : ExtensionBiometricsState ;
6869 password : PasswordState ;
70+ passwordOnLaunch : boolean ;
6971 setLockMode : ( mode : LockMode ) => Promise < void > ;
7072 setLockTTL : ( ttl : number ) => Promise < void > ;
73+ setPasswordOnLaunch : ( enabled : boolean ) => Promise < void > ;
7174}
7275
7376export const useLockSetup = ( ) : LockSetup => {
@@ -100,6 +103,7 @@ export const useLockSetup = (): LockSetup => {
100103 * this, we use an optimistic value for the next lock. */
101104 const [ nextLock , setNextLock ] = useState < MaybeNull < { ttl : number ; mode : LockMode } > > ( null ) ;
102105 const [ biometricsEnabled , setBiometricsEnabled ] = useState ( currentLockMode === LockMode . BIOMETRICS ) ;
106+ const [ , rerenderLaunchPassword ] = useRerender ( 'password-on-launch' ) ;
103107
104108 const unlock = useUnlock ( ( err ) => createNotification ( { type : 'error' , text : err . message } ) ) ;
105109
@@ -109,6 +113,7 @@ export const useLockSetup = (): LockSetup => {
109113 onFailure : ( ) => setNextLock ( null ) ,
110114 onSuccess : ( ) => setNextLock ( null ) ,
111115 } ) ;
116+ const launchPassword = useRequest ( passwordOnLaunchToggle , { initial : true , onSuccess : rerenderLaunchPassword } ) ;
112117
113118 const setLockMode = async ( mode : LockMode ) => {
114119 if ( isFreePlan && ( mode === LockMode . BIOMETRICS || mode === LockMode . DESKTOP ) ) {
@@ -328,11 +333,40 @@ export const useLockSetup = (): LockSetup => {
328333 }
329334 } ;
330335
336+ /** Mutating launch-password lock requires password confirmation.
337+ * The checkbox state is reread from `authStore` after the saga persists it. */
338+ const setPasswordOnLaunch = async ( enabled : boolean ) => {
339+ return confirmPassword ( {
340+ onSubmit : ( password ) => launchPassword . dispatch ( { enabled, password } ) ,
341+ message : passwordTypeSwitch ( {
342+ extra : enabled
343+ ? c ( 'Info' )
344+ . t `Please confirm your extra password in order to require it when ${ PASS_APP_NAME } launches.`
345+ : c ( 'Info' )
346+ . t `Please confirm your extra password in order to stop requiring it when ${ PASS_APP_NAME } launches.` ,
347+ sso : enabled
348+ ? c ( 'Info' )
349+ . t `Please confirm your backup password in order to require it when ${ PASS_APP_NAME } launches.`
350+ : c ( 'Info' )
351+ . t `Please confirm your backup password in order to stop requiring it when ${ PASS_APP_NAME } launches.` ,
352+ twoPwd : enabled
353+ ? c ( 'Info' )
354+ . t `Please confirm your second password in order to require it when ${ PASS_APP_NAME } launches.`
355+ : c ( 'Info' )
356+ . t `Please confirm your second password in order to stop requiring it when ${ PASS_APP_NAME } launches.` ,
357+ default : enabled
358+ ? c ( 'Info' ) . t `Please confirm your password in order to require it when ${ PASS_APP_NAME } launches.`
359+ : c ( 'Info' )
360+ . t `Please confirm your password in order to stop requiring it when ${ PASS_APP_NAME } launches.` ,
361+ } ) ,
362+ } ) ;
363+ } ;
364+
331365 useEffect ( ( ) => {
332366 /** Block reload/navigation if a lock request is on-going.
333367 * Custom `beforeunload` messages are now deprecated */
334368 const onBeforeUnload = ( evt : BeforeUnloadEvent ) => {
335- if ( createLock . loading ) {
369+ if ( createLock . loading || launchPassword . loading ) {
336370 evt . preventDefault ( ) ;
337371 evt . returnValue = '' ;
338372 return '' ;
@@ -341,7 +375,7 @@ export const useLockSetup = (): LockSetup => {
341375
342376 window . addEventListener ( 'beforeunload' , onBeforeUnload ) ;
343377 return ( ) => window . removeEventListener ( 'beforeunload' , onBeforeUnload ) ;
344- } , [ createLock . loading ] ) ;
378+ } , [ createLock . loading , launchPassword . loading ] ) ;
345379
346380 useEffect ( ( ) => {
347381 ( async ( ) => {
@@ -354,14 +388,14 @@ export const useLockSetup = (): LockSetup => {
354388 const lock = useMemo (
355389 ( ) => ( {
356390 orgControlled : Boolean ( orgLockTTL ) ,
357- loading : createLock . loading ,
391+ loading : createLock . loading || launchPassword . loading ,
358392 mode : nextLock ?. mode ?? currentLockMode ,
359393 ttl : {
360394 value : nextLock ?. ttl || orgLockTTL || lockTTL ,
361395 disabled : Boolean ( currentLockMode === LockMode . NONE || orgLockTTL ) ,
362396 } ,
363397 } ) ,
364- [ currentLockMode , nextLock , orgLockTTL , lockTTL , createLock . loading ]
398+ [ currentLockMode , nextLock , orgLockTTL , lockTTL , createLock . loading , launchPassword . loading ]
365399 ) ;
366400
367401 const biometrics = useMemo (
@@ -370,6 +404,7 @@ export const useLockSetup = (): LockSetup => {
370404 ) ;
371405
372406 const password = useMemo ( ( ) => ( { enabled : ! EXTENSION_BUILD } ) , [ ] ) ;
407+ const passwordOnLaunch = authStore ?. getLockPasswordOnLaunch ( ) ?? true ;
373408
374409 const extensionBiometrics = useMemo (
375410 ( ) => ( {
@@ -389,7 +424,9 @@ export const useLockSetup = (): LockSetup => {
389424 biometrics,
390425 extensionBiometrics,
391426 password,
427+ passwordOnLaunch,
392428 setLockMode,
393429 setLockTTL,
430+ setPasswordOnLaunch,
394431 } ;
395432} ;
0 commit comments