@@ -110,6 +110,12 @@ const utils = window.FolderViewPlusUtils || {
110110 }
111111} ;
112112const dockerRuntimeShared = window . FolderViewDockerRuntimeShared || { } ;
113+ const dockerStorageWriter = typeof utils . createBatchedStorageWriter === 'function'
114+ ? utils . createBatchedStorageWriter ( window . localStorage , {
115+ defaultDelayMs : 72 ,
116+ idleTimeoutMs : 900
117+ } )
118+ : null ;
113119const createDockerRuntimeStateStore = typeof dockerRuntimeShared . createRuntimeStateStore === 'function'
114120 ? dockerRuntimeShared . createRuntimeStateStore
115121 : ( initialState = { } ) => {
@@ -351,7 +357,15 @@ const isDockerRuntimeWidthDebugEnabled = () => {
351357const setDockerRuntimeWidthDebugEnabled = ( enabled ) => {
352358 const next = enabled === true ;
353359 try {
354- localStorage . setItem ( DOCKER_RUNTIME_WIDTH_DEBUG_STORAGE_KEY , next ? '1' : '0' ) ;
360+ if ( dockerStorageWriter && typeof dockerStorageWriter . setItem === 'function' ) {
361+ dockerStorageWriter . setItem (
362+ DOCKER_RUNTIME_WIDTH_DEBUG_STORAGE_KEY ,
363+ next ? '1' : '0' ,
364+ { delayMs : 0 , idle : false }
365+ ) ;
366+ } else {
367+ localStorage . setItem ( DOCKER_RUNTIME_WIDTH_DEBUG_STORAGE_KEY , next ? '1' : '0' ) ;
368+ }
355369 } catch ( _error ) {
356370 // Ignore localStorage limitations.
357371 }
@@ -533,15 +547,40 @@ const persistDockerRuntimeColumnWidths = (widthMap) => {
533547 const normalized = normalizeDockerRuntimeColumnWidthMap ( widthMap ) ;
534548 try {
535549 if ( Object . keys ( normalized ) . length > 0 ) {
536- localStorage . setItem ( DOCKER_RUNTIME_COLUMN_WIDTHS_STORAGE_KEY , JSON . stringify ( normalized ) ) ;
550+ if ( dockerStorageWriter && typeof dockerStorageWriter . setItem === 'function' ) {
551+ dockerStorageWriter . setItem (
552+ DOCKER_RUNTIME_COLUMN_WIDTHS_STORAGE_KEY ,
553+ JSON . stringify ( normalized ) ,
554+ { delayMs : 96 , idle : true }
555+ ) ;
556+ } else {
557+ localStorage . setItem ( DOCKER_RUNTIME_COLUMN_WIDTHS_STORAGE_KEY , JSON . stringify ( normalized ) ) ;
558+ }
537559 if ( normalized [ 1 ] ) {
538- localStorage . setItem ( DOCKER_RUNTIME_LEGACY_APP_WIDTH_STORAGE_KEY , String ( normalized [ 1 ] ) ) ;
560+ if ( dockerStorageWriter && typeof dockerStorageWriter . setItem === 'function' ) {
561+ dockerStorageWriter . setItem (
562+ DOCKER_RUNTIME_LEGACY_APP_WIDTH_STORAGE_KEY ,
563+ String ( normalized [ 1 ] ) ,
564+ { delayMs : 96 , idle : true }
565+ ) ;
566+ } else {
567+ localStorage . setItem ( DOCKER_RUNTIME_LEGACY_APP_WIDTH_STORAGE_KEY , String ( normalized [ 1 ] ) ) ;
568+ }
539569 } else {
540- localStorage . removeItem ( DOCKER_RUNTIME_LEGACY_APP_WIDTH_STORAGE_KEY ) ;
570+ if ( dockerStorageWriter && typeof dockerStorageWriter . removeItem === 'function' ) {
571+ dockerStorageWriter . removeItem ( DOCKER_RUNTIME_LEGACY_APP_WIDTH_STORAGE_KEY , { delayMs : 40 , idle : true } ) ;
572+ } else {
573+ localStorage . removeItem ( DOCKER_RUNTIME_LEGACY_APP_WIDTH_STORAGE_KEY ) ;
574+ }
541575 }
542576 } else {
543- localStorage . removeItem ( DOCKER_RUNTIME_COLUMN_WIDTHS_STORAGE_KEY ) ;
544- localStorage . removeItem ( DOCKER_RUNTIME_LEGACY_APP_WIDTH_STORAGE_KEY ) ;
577+ if ( dockerStorageWriter && typeof dockerStorageWriter . removeItem === 'function' ) {
578+ dockerStorageWriter . removeItem ( DOCKER_RUNTIME_COLUMN_WIDTHS_STORAGE_KEY , { delayMs : 40 , idle : true } ) ;
579+ dockerStorageWriter . removeItem ( DOCKER_RUNTIME_LEGACY_APP_WIDTH_STORAGE_KEY , { delayMs : 40 , idle : true } ) ;
580+ } else {
581+ localStorage . removeItem ( DOCKER_RUNTIME_COLUMN_WIDTHS_STORAGE_KEY ) ;
582+ localStorage . removeItem ( DOCKER_RUNTIME_LEGACY_APP_WIDTH_STORAGE_KEY ) ;
583+ }
545584 }
546585 } catch ( _error ) {
547586 // Ignore localStorage quota/privacy failures.
@@ -1220,7 +1259,12 @@ const readDockerLockedFolderIds = () => {
12201259const writeDockerLockedFolderIds = ( ids ) => {
12211260 try {
12221261 if ( window . localStorage ) {
1223- window . localStorage . setItem ( DOCKER_LOCKED_STATE_KEY , JSON . stringify ( normalizeLockedFolderIdList ( ids ) ) ) ;
1262+ const payload = JSON . stringify ( normalizeLockedFolderIdList ( ids ) ) ;
1263+ if ( dockerStorageWriter && typeof dockerStorageWriter . setItem === 'function' ) {
1264+ dockerStorageWriter . setItem ( DOCKER_LOCKED_STATE_KEY , payload , { delayMs : 70 , idle : true } ) ;
1265+ } else {
1266+ window . localStorage . setItem ( DOCKER_LOCKED_STATE_KEY , payload ) ;
1267+ }
12241268 }
12251269 } catch ( _error ) {
12261270 // Best effort only.
@@ -1808,7 +1852,12 @@ const writeDockerExpandedStateMap = (map) => {
18081852 try {
18091853 const payload = map && typeof map === 'object' ? map : { } ;
18101854 if ( window . localStorage ) {
1811- window . localStorage . setItem ( DOCKER_EXPANDED_STATE_KEY , JSON . stringify ( payload ) ) ;
1855+ const serialized = JSON . stringify ( payload ) ;
1856+ if ( dockerStorageWriter && typeof dockerStorageWriter . setItem === 'function' ) {
1857+ dockerStorageWriter . setItem ( DOCKER_EXPANDED_STATE_KEY , serialized , { delayMs : 80 , idle : true } ) ;
1858+ } else {
1859+ window . localStorage . setItem ( DOCKER_EXPANDED_STATE_KEY , serialized ) ;
1860+ }
18121861 }
18131862 } catch ( _error ) {
18141863 // Ignore storage failures so runtime rendering never breaks.
0 commit comments