@@ -25,7 +25,6 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
2525 message . info . windowWidth
2626 ) ;
2727 } else if ( message . action === "cachePassphrase" ) {
28- document . cookie = `passphrase="${ message . value } ${ getCookieExpiry ( ) } "` ;
2928 cachedPassphrase = message . value ;
3029 clearTimeout ( autolockTimeout ) ;
3130 setAutolock ( ) ;
@@ -405,25 +404,37 @@ chrome.commands.onCommand.addListener(async (command: string) => {
405404 }
406405} ) ;
407406
408- function setAutolock ( ) {
407+ async function setAutolock ( ) {
408+ const enforcedAutolock = Number ( await ManagedStorage . get ( "enforceAutolock" ) ) ;
409+
410+ if ( enforcedAutolock ) {
411+ if ( enforcedAutolock > 0 ) {
412+ document . cookie = `passphrase="${ getCachedPassphrase ( ) } ${ getCookieExpiry (
413+ enforcedAutolock
414+ ) } "`;
415+ autolockTimeout = setTimeout ( ( ) => {
416+ cachedPassphrase = "" ;
417+ } , enforcedAutolock * 60000 ) ;
418+ return ;
419+ }
420+ }
421+
409422 if ( Number ( localStorage . autolock ) > 0 ) {
410- document . cookie = `passphrase="${ getCachedPassphrase ( ) } ${ getCookieExpiry ( ) } "` ;
423+ document . cookie = `passphrase="${ getCachedPassphrase ( ) } ${ getCookieExpiry (
424+ Number ( localStorage . autolock )
425+ ) } "`;
411426 autolockTimeout = setTimeout ( ( ) => {
412427 cachedPassphrase = "" ;
413428 } , Number ( localStorage . autolock ) * 60000 ) ;
414429 }
415430}
416431
417- function getCookieExpiry ( ) {
418- if ( localStorage . autolock && Number ( localStorage . autolock ) > 0 ) {
419- const offset = Number ( localStorage . autolock ) * 60000 ;
420- const now = new Date ( ) . getTime ( ) ;
421- const autolockExpiry = new Date ( now + offset ) . toUTCString ( ) ;
432+ function getCookieExpiry ( time : number ) {
433+ const offset = time * 60000 ;
434+ const now = new Date ( ) . getTime ( ) ;
435+ const autolockExpiry = new Date ( now + offset ) . toUTCString ( ) ;
422436
423- return `;expires=${ autolockExpiry } ` ;
424- } else {
425- return "" ;
426- }
437+ return `;expires=${ autolockExpiry } ` ;
427438}
428439
429440function getCachedPassphrase ( ) {
0 commit comments