import { Injectable } from "@angular/core" ; import { Storage } from "@ionic/storage" ; import { ReaderSettings } from "../common/models/reader-settings" ; @ Injectable ( ) export class ReaderSettingsService { DEFAULTSETTINGS : ReaderSettings ; private READERSETTINGS : string = "readerSettings" ; public settings : ReaderSettings ; constructor ( private storage ) { console . log ( "Hello ReaderSettings Service" ) ; this . DEFAULTSETTINGS = new ReaderSettings ( ) ; this . settings = this . DEFAULTSETTINGS ; } init ( ) { return new Promise ( ( resolve , reject ) => { this . storage . get ( this . READERSETTINGS ) . then ( settings => { let availableSettings = settings || this . DEFAULTSETTINGS ; this . settings = availableSettings ; resolve ( availableSettings ) ; } ) . catch ( err => { resolve ( this . DEFAULTSETTINGS ) ; } ) ; } ) ; } set ( settings ) { this . storage . set ( this . READERSETTINGS , settings ) ; this . settings = settings ; } }