@@ -49,6 +49,13 @@ export class UpdateContext {
4949
5050 private initPreferences ( ) {
5151 try {
52+ try {
53+ if ( typeof preferences . removePreferencesFromCacheSync === 'function' ) {
54+ preferences . removePreferencesFromCacheSync ( this . context , 'update' ) ;
55+ }
56+ } catch ( e ) {
57+ console . error ( 'Failed to remove preferences from cache:' , e ) ;
58+ }
5259 this . preferences = preferences . getPreferencesSync ( this . context , {
5360 name : 'update' ,
5461 } ) ;
@@ -147,6 +154,10 @@ export class UpdateContext {
147154 flushablePreferences . flushSync ( ) ;
148155 return ;
149156 }
157+ if ( typeof this . preferences . flush === 'function' ) {
158+ this . preferences . flush ( ) ;
159+ return ;
160+ }
150161 throw Error ( 'preferences.flushSync is not available' ) ;
151162 } catch ( error ) {
152163 console . error ( `Failed to flush preferences for ${ reason } :` , error ) ;
@@ -167,6 +178,7 @@ export class UpdateContext {
167178 }
168179
169180 private getStateSnapshot ( ) : StateCoreResult {
181+ this . initPreferences ( ) ;
170182 return {
171183 packageVersion : this . readString ( 'packageVersion' ) ,
172184 buildTime : this . readString ( 'buildTime' ) ,
@@ -198,6 +210,7 @@ export class UpdateContext {
198210 clearFirstLoadMarker ?: boolean ;
199211 } = { } ,
200212 ) : void {
213+ this . initPreferences ( ) ;
201214 if ( options . clearExisting ) {
202215 this . preferences . clear ( ) ;
203216 }
@@ -275,11 +288,13 @@ export class UpdateContext {
275288 }
276289
277290 public setKv ( key : string , value : string ) : void {
291+ this . initPreferences ( ) ;
278292 this . preferences . putSync ( key , value ) ;
279293 this . flushPreferences ( `set key ${ key } ` ) ;
280294 }
281295
282296 public getKv ( key : string ) : string {
297+ this . initPreferences ( ) ;
283298 return this . readString ( key ) ;
284299 }
285300
@@ -397,6 +412,7 @@ export class UpdateContext {
397412 }
398413
399414 public consumeFirstLoadMarker ( ) : boolean {
415+ this . initPreferences ( ) ;
400416 const marked = this . readString ( 'firstLoadMarked' ) === 'true' ;
401417 if ( marked ) {
402418 this . preferences . deleteSync ( 'firstLoadMarked' ) ;
0 commit comments