@@ -53,6 +53,9 @@ let mTabBar;
53
53
export function init ( ) {
54
54
mTargetWindow = TabsStore . getCurrentWindowId ( ) ;
55
55
mTabBar = document . querySelector ( '#tabbar' ) ;
56
+
57
+ if ( ! configs . persistCachedTree )
58
+ clearPersistentWindowCache ( ) ;
56
59
}
57
60
58
61
export function startTracking ( ) {
@@ -433,6 +436,20 @@ async function fixupTabsRestoredFromCache(tabElements, tabs, options = {}) {
433
436
// ===================================================================
434
437
435
438
function updateWindowCache ( key , value ) {
439
+ if ( ! configs . persistCachedTree &&
440
+ browser . storage . session ) {
441
+ const storagKey = `sidebarCache-window${ mTargetWindow } -${ key } ` ;
442
+ if ( value ) {
443
+ const data = { } ;
444
+ data [ storagKey ] = value ;
445
+ browser . storage . session . set ( data ) ;
446
+ }
447
+ else {
448
+ browser . storage . session . remove ( storagKey ) ;
449
+ }
450
+ return ;
451
+ }
452
+
436
453
if ( ! mLastWindowCacheOwner ||
437
454
! Tab . get ( mLastWindowCacheOwner . id ) )
438
455
return ;
@@ -448,11 +465,23 @@ function updateWindowCache(key, value) {
448
465
449
466
function clearWindowCache ( ) {
450
467
log ( 'clearWindowCache ' , { stack : configs . debug && new Error ( ) . stack } ) ;
468
+ if ( ! configs . persistCachedTree )
469
+ clearPersistentWindowCache ( ) ;
451
470
updateWindowCache ( Constants . kWINDOW_STATE_CACHED_SIDEBAR ) ;
452
471
updateWindowCache ( Constants . kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY ) ;
453
472
updateWindowCache ( Constants . kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY ) ;
454
473
}
455
474
475
+ function clearPersistentWindowCache ( ) {
476
+ if ( ! mLastWindowCacheOwner ||
477
+ ! Tab . get ( mLastWindowCacheOwner . id ) )
478
+ return ;
479
+ log ( 'clearPersistentWindowCache ' , { stack : configs . debug && new Error ( ) . stack } ) ;
480
+ browser . sessions . removeWindowValue ( mLastWindowCacheOwner . windowId , Constants . kWINDOW_STATE_CACHED_SIDEBAR ) . catch ( ApiTabs . createErrorSuppressor ( ) ) ;
481
+ browser . sessions . removeWindowValue ( mLastWindowCacheOwner . windowId , Constants . kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY ) . catch ( ApiTabs . createErrorSuppressor ( ) ) ;
482
+ browser . sessions . removeWindowValue ( mLastWindowCacheOwner . windowId , Constants . kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY ) . catch ( ApiTabs . createErrorSuppressor ( ) ) ;
483
+ }
484
+
456
485
export function markWindowCacheDirty ( key ) {
457
486
if ( markWindowCacheDirty . timeout )
458
487
clearTimeout ( markWindowCacheDirty . timeout ) ;
@@ -463,6 +492,15 @@ export function markWindowCacheDirty(key) {
463
492
}
464
493
465
494
async function getWindowCache ( key ) {
495
+ if ( ! configs . persistCachedTree ) {
496
+ const storageKey = `sidebarCache-window${ mTargetWindow } -${ key } ` ;
497
+ const defaultData = { } ;
498
+ defaultData [ storageKey ] = undefined ;
499
+ return browser . storage . session . get ( defaultData ) . then ( data => {
500
+ return data [ storageKey ] ;
501
+ } ) ;
502
+ }
503
+
466
504
if ( ! mLastWindowCacheOwner )
467
505
return null ;
468
506
return browser . sessions . getWindowValue ( mLastWindowCacheOwner . windowId , key ) . catch ( ApiTabs . createErrorHandler ( ) ) ;
@@ -527,6 +565,7 @@ async function updateCachedTabbar() {
527
565
function onConfigChange ( changedKey ) {
528
566
switch ( changedKey ) {
529
567
case 'useCachedTree' :
568
+ case 'persistCachedTree' :
530
569
if ( configs [ changedKey ] ) {
531
570
reserveToUpdateCachedTabbar ( ) ;
532
571
}
0 commit comments