@@ -3201,6 +3201,9 @@ const DOCKER_RUNTIME_PRIVACY_TOGGLE_SHELL_ID = 'fvplus-docker-runtime-privacy-sh
32013201const DOCKER_RUNTIME_PRIVACY_TOGGLE_FALLBACK_HOST_ID = 'fvplus-docker-runtime-toolbar-controls' ;
32023202const DOCKER_LEGACY_HOST_BOOTSTRAP_RENDER_COMPAT = false ;
32033203let dockerRuntimePrivacyToggleMountQueued = false ;
3204+ let dockerRuntimePrivacyPersistPromise = null ;
3205+ let dockerRuntimePrivacyPendingEnabled = null ;
3206+ let dockerRuntimePrivacyPersistedPrefs = null ;
32043207
32053208const readDockerRuntimePrivacyMode = ( ) => utils . normalizePrefs ( folderTypePrefs || { } ) . dashboard ?. privacyMode === true ;
32063209
@@ -3249,18 +3252,22 @@ const findDockerRuntimeListViewToggleAnchor = () => {
32493252 ] . filter ( Boolean ) ;
32503253 const switchSelector = 'input[type="checkbox"], .switch-button, .switch-button-background' ;
32513254 for ( const scope of scopes ) {
3252- const candidates = Array . from ( scope . querySelectorAll ( 'label, div, span, td, th' ) ) ;
3253- for ( const candidate of candidates ) {
3254- const text = String ( candidate . textContent || '' ) . replace ( / \s + / g, ' ' ) . trim ( ) . toLowerCase ( ) ;
3255- if ( ! text . includes ( 'basic view' ) ) {
3256- continue ;
3257- }
3258- if ( candidate . querySelector ( switchSelector ) ) {
3255+ const switches = Array . from ( scope . querySelectorAll ( switchSelector ) ) ;
3256+ for ( const toggleNode of switches ) {
3257+ const candidates = [
3258+ toggleNode . closest ( 'label' ) ,
3259+ toggleNode . closest ( 'span' ) ,
3260+ toggleNode . closest ( 'div' ) ,
3261+ toggleNode . parentElement ,
3262+ toggleNode . parentElement ?. parentElement
3263+ ] . filter ( Boolean ) ;
3264+ for ( const candidate of candidates ) {
3265+ const text = String ( candidate . textContent || '' ) . replace ( / \s + / g, ' ' ) . trim ( ) . toLowerCase ( ) ;
3266+ if ( ! text . includes ( 'basic view' ) ) {
3267+ continue ;
3268+ }
32593269 return candidate ;
32603270 }
3261- if ( candidate . parentElement && candidate . parentElement . querySelector ( switchSelector ) ) {
3262- return candidate . parentElement ;
3263- }
32643271 }
32653272 }
32663273 return null ;
@@ -3320,7 +3327,7 @@ const renderDockerRuntimePrivacyToggle = () => {
33203327 shell = document . createElement ( 'div' ) ;
33213328 shell . id = DOCKER_RUNTIME_PRIVACY_TOGGLE_SHELL_ID ;
33223329 }
3323- shell . className = `fvplus-docker-runtime-toggle-shell${ mount . fallback ? ' is-fallback' : '' } ` ;
3330+ shell . className = `fvplus-docker-runtime-toggle-shell${ mount . anchor ? ' is-inline-cluster' : '' } ${ mount . fallback ? ' is-fallback' : '' } ` ;
33243331 if ( mount . anchor ) {
33253332 if ( mount . anchor . nextElementSibling !== shell ) {
33263333 mount . anchor . insertAdjacentElement ( 'afterend' , shell ) ;
@@ -3329,9 +3336,10 @@ const renderDockerRuntimePrivacyToggle = () => {
33293336 mount . host . insertBefore ( shell , mount . host . firstChild ) ;
33303337 }
33313338 const enabled = readDockerRuntimePrivacyMode ( ) ;
3339+ const savePending = dockerRuntimePrivacyPersistPromise !== null ;
33323340 shell . innerHTML = `
33333341 <span class="fvplus-docker-runtime-toggle-label">Privacy</span>
3334- <input id="${ DOCKER_RUNTIME_PRIVACY_TOGGLE_ID } " class="basic-switch fvplus-docker-runtime-privacy-switch" type="checkbox" ${ enabled ? 'checked' : '' } >
3342+ <input id="${ DOCKER_RUNTIME_PRIVACY_TOGGLE_ID } " class="basic-switch fvplus-docker-runtime-privacy-switch" type="checkbox" ${ enabled ? 'checked' : '' } ${ savePending ? 'disabled' : '' } >
33353343 ` ;
33363344 const $input = $ ( `#${ DOCKER_RUNTIME_PRIVACY_TOGGLE_ID } ` ) ;
33373345 if ( ! $input . length ) {
@@ -3366,36 +3374,57 @@ const queueDockerRuntimePrivacyToggleMount = () => {
33663374 setTimeout ( flush , 0 ) ;
33673375} ;
33683376
3377+ const getDockerRuntimePersistedPrefs = ( ) => utils . normalizePrefs ( dockerRuntimePrivacyPersistedPrefs || folderTypePrefs || { } ) ;
3378+
3379+ const flushDockerRuntimePrivacyModePersistence = async ( ) => {
3380+ if ( dockerRuntimePrivacyPersistPromise ) {
3381+ return dockerRuntimePrivacyPersistPromise ;
3382+ }
3383+ dockerRuntimePrivacyPersistPromise = ( async ( ) => {
3384+ try {
3385+ while ( dockerRuntimePrivacyPendingEnabled !== null ) {
3386+ const targetEnabled = dockerRuntimePrivacyPendingEnabled === true ;
3387+ dockerRuntimePrivacyPendingEnabled = null ;
3388+ const response = await persistDockerRuntimePrivacyMode ( targetEnabled ) ;
3389+ folderTypePrefs = utils . normalizePrefs ( response ?. prefs || buildDockerRuntimePrivacyPrefsPayload ( targetEnabled ) ) ;
3390+ dockerRuntimePrivacyPersistedPrefs = folderTypePrefs ;
3391+ applyRuntimePrefs ( folderTypePrefs ) ;
3392+ queueDockerRuntimePrivacyToggleMount ( ) ;
3393+ }
3394+ } finally {
3395+ dockerRuntimePrivacyPersistPromise = null ;
3396+ queueDockerRuntimePrivacyToggleMount ( ) ;
3397+ }
3398+ } ) ( ) ;
3399+ return dockerRuntimePrivacyPersistPromise ;
3400+ } ;
3401+
33693402const setDockerRuntimePrivacyMode = async ( enabled , options = { } ) => {
33703403 const nextEnabled = enabled === true ;
3371- const previousPrefs = utils . normalizePrefs ( folderTypePrefs || { } ) ;
3404+ const previousPrefs = getDockerRuntimePersistedPrefs ( ) ;
33723405 const previousEnabled = previousPrefs . dashboard ?. privacyMode === true ;
3373- if ( previousEnabled === nextEnabled ) {
3406+ if ( readDockerRuntimePrivacyMode ( ) === nextEnabled && dockerRuntimePrivacyPendingEnabled === null && ! dockerRuntimePrivacyPersistPromise ) {
33743407 queueDockerRuntimePrivacyToggleMount ( ) ;
33753408 return ;
33763409 }
3410+ dockerRuntimePrivacyPendingEnabled = nextEnabled ;
33773411 folderTypePrefs = buildDockerRuntimePrivacyPrefsPayload ( nextEnabled ) ;
33783412 applyRuntimePrefs ( folderTypePrefs ) ;
33793413 queueDockerRuntimePrivacyToggleMount ( ) ;
33803414 if ( options . persist === false ) {
33813415 return ;
33823416 }
3383- const result = await dockerSafeUiActionRunner . run ( 'docker-runtime-privacy-toggle' , async ( ) => {
3384- const response = await persistDockerRuntimePrivacyMode ( nextEnabled ) ;
3385- folderTypePrefs = utils . normalizePrefs ( response ?. prefs || folderTypePrefs ) ;
3386- applyRuntimePrefs ( folderTypePrefs ) ;
3387- queueDockerRuntimePrivacyToggleMount ( ) ;
3388- return response ;
3389- } , {
3390- userVisible : false
3391- } ) ;
3392- if ( ! result . ok ) {
3417+ try {
3418+ await flushDockerRuntimePrivacyModePersistence ( ) ;
3419+ } catch ( error ) {
3420+ dockerRuntimePrivacyPendingEnabled = null ;
33933421 folderTypePrefs = previousPrefs ;
3422+ dockerRuntimePrivacyPersistedPrefs = previousPrefs ;
33943423 applyRuntimePrefs ( folderTypePrefs ) ;
33953424 queueDockerRuntimePrivacyToggleMount ( ) ;
33963425 swal ( {
33973426 title : 'Privacy toggle save failed' ,
3398- text : `${ escapeHtml ( String ( result . error ?. message || 'FolderView Plus could not save the Docker privacy toggle.' ) ) } <br>Reverted to the previous state.` ,
3427+ text : `${ escapeHtml ( String ( error ?. message || 'FolderView Plus could not save the Docker privacy toggle.' ) ) } <br>Reverted to the previous state.` ,
33993428 type : 'error' ,
34003429 html : true ,
34013430 confirmButtonText : 'OK'
@@ -6239,6 +6268,9 @@ const scheduleLiveRefresh = (prefs) => {
62396268const applyRuntimePrefs = ( prefs ) => {
62406269 const normalized = utils . normalizePrefs ( prefs || { } ) ;
62416270 lastAppliedRuntimePrefs = normalized ;
6271+ if ( ! dockerRuntimePrivacyPersistPromise && dockerRuntimePrivacyPendingEnabled === null ) {
6272+ dockerRuntimePrivacyPersistedPrefs = normalized ;
6273+ }
62426274 if ( document . body && typeof document . body . setAttribute === 'function' ) {
62436275 document . body . setAttribute ( 'data-fvplus-docker-page-view' , resolveDockerPageViewMode ( normalized ) ) ;
62446276 }
@@ -6402,4 +6434,3 @@ if (FOLDER_VIEW_DEBUG_MODE) console.log('[FV3_DEBUG] docker.js: End of script ex
64026434
64036435
64046436
6405-
0 commit comments