import { Injectable } from 'angular-ts-decorators' ; import autobind from 'autobind-decorator' ; import { FailedLocalStorageError } from '../../../shared/errors/errors' ; import { StoreKey } from '../../../shared/store/store.enum' ; import { V160UpgradeProviderService } from '../../../shared/upgrade/v1.6.0-upgrade-provider/v1.6.0-upgrade-provider.service' ; @ autobind @ Injectable ( 'V160UpgradeProviderService' ) export class AndroidV160UpgradeProviderService extends V160UpgradeProviderService { static $inject = [ '$q' , 'BookmarkHelperService' , 'PlatformService' , 'StoreService' , 'UtilityService' ] ; getAllFromNativeStorage ( ) { return this . $q < any > ( ( resolve , reject ) => { const nativeStorageItems = { } ; const failure = ( err = new Error ( ) ) => { if ( ( err as any ) . code === 2 ) { return resolve ( null ) ; } reject ( new FailedLocalStorageError ( undefined , err ) ) ; } ; const success = ( keys ) => { this . $q . all ( keys . map ( ( key ) => { return this . $q ( ( resolveGetItem , rejectGetItem ) => { window . NativeStorage . getItem ( key , ( result ) => { nativeStorageItems [ key ] = result ; resolveGetItem ( ) ; } , rejectGetItem ) ; } ) ; } ) ) . then ( ( ) => { resolve ( nativeStorageItems ) ; } ) . catch ( failure ) ; } ; window . NativeStorage . keys ( success , failure ) ; } ) ; } upgradeApp ( upgradingFromVersion ? ) { return this . getAllFromNativeStorage ( ) . then ( ( cachedData ) => { return this . storeSvc . init ( ) . then ( ( ) => { if ( ! cachedData || Object . keys ( cachedData ) . length === 0 ) { return ; } return this . $q . all ( Object . keys ( cachedData ) . map ( ( key ) => { if ( key === 'appVersion' || key === 'traceLog' ) { return ; } if ( key === 'displaySearchBarBeneathResults' ) { const keyValue = cachedData [ key ] ; key = StoreKey . AlternateSearchBarPosition ; cachedData [ key ] = keyValue ; } return this . storeSvc . set ( key , cachedData [ key ] ) ; } ) ) ; } ) . then ( ( ) => { } ) ; } ) ; } }