{"version":3,"file":"chunk-o52laa07.js","sources":["packages/vanilla/lib/shared/native-app/src/wrapper-settings.service.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\nimport { NativeAppConfig, NativeAppService, NativeEvent, NativeEventType } from '@frontend/vanilla/core';\nimport { BehaviorSubject, Observable, filter, first, of, timeout } from 'rxjs';\n\n/**\n * @whatItDoes Interface for settings of native wrapper application.\n *\n * @stable\n */\nexport interface WrapperSettings {\n sliderGamesEnabled: boolean;\n keepMeSignedInEnabled?: boolean;\n deviceTouchSupported: boolean;\n isTouchIDLoginEnabled?: boolean;\n deviceFaceSupported: boolean;\n isFaceIDLoginEnabled?: boolean;\n}\n\n/**\n * @stable\n */\nexport interface WrapperUpdateSettings {\n sliderGamesEnabled?: boolean;\n keepMeSignedInEnabled?: boolean;\n deviceTouchSupported?: boolean;\n isTouchIDLoginEnabled?: boolean;\n isFaceIDLoginEnabled?: boolean;\n}\n\n/**\n * @whatItDoes Maintains state of native wrapper settings and allows to update them.\n *\n * @howToUse\n * ```\n * const setting = wrapperSettingsService.current.isTouchIDLoginEnabled; // read\n *\n * wrapperSettingsService.update({ isTouchIDLoginEnabled: true }); // update\n * ```\n *\n * @stable\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class WrapperSettingsService {\n private currentSettings: WrapperSettings | undefined;\n private applicationSettingsFiredEvents: BehaviorSubject = new BehaviorSubject(false);\n\n constructor(\n private nativeAppService: NativeAppService,\n private config: NativeAppConfig,\n ) {}\n\n get current(): WrapperSettings {\n return this.currentSettings || {};\n }\n\n get applicationSettingsFired(): Observable {\n return this.nativeAppService.isNativeWrapper ? this.applicationSettingsFiredEvents.pipe(filter((received) => received)) : of(true);\n }\n\n load(): Promise {\n if (!this.nativeAppService.isNativeWrapper) {\n this.sendSetApplicationSettingsEvent();\n return Promise.resolve();\n }\n\n return new Promise((resolve) => {\n this.nativeAppService.eventsFromNative\n .pipe(\n filter((event: NativeEvent) => event.eventName === NativeEventType.SET_APPLICATION_SETTINGS),\n first(),\n timeout(this.config.appSettingsTimeout),\n )\n .subscribe({\n next: (event: NativeEvent) => {\n this.currentSettings = event.parameters;\n this.sendSetApplicationSettingsEvent();\n resolve();\n },\n error: () => {\n this.sendSetApplicationSettingsEvent();\n resolve(); // do nothing\n },\n });\n\n this.nativeAppService.sendToNative({ eventName: NativeEventType.GET_APPLICATION_SETTINGS });\n });\n }\n\n update(updates: WrapperUpdateSettings) {\n if (!this.nativeAppService.isNativeWrapper) {\n return;\n }\n\n this.nativeAppService.sendToNative({\n eventName: NativeEventType.UPDATE_APPLICATION_SETTINGS,\n parameters: updates,\n });\n\n if (this.currentSettings) {\n Object.assign(this.currentSettings, updates);\n }\n }\n\n private sendSetApplicationSettingsEvent() {\n this.applicationSettingsFiredEvents.next(true);\n }\n}\n"],"names":["WrapperSettingsService","constructor","nativeAppService","config","applicationSettingsFiredEvents","BehaviorSubject","current","currentSettings","applicationSettingsFired","isNativeWrapper","pipe","filter","received","of","load","Promise","resolve","eventsFromNative","event","eventName","NativeEventType","SET_APPLICATION_SETTINGS","first","timeout","appSettingsTimeout","subscribe","next","parameters","sendSetApplicationSettingsEvent","error","sendToNative","GET_APPLICATION_SETTINGS","update","updates","UPDATE_APPLICATION_SETTINGS","Object","assign","ɵɵinject","NativeAppService","NativeAppConfig","factory","ɵfac","providedIn","_WrapperSettingsService"],"mappings":"kHA6CA,IAAaA,GAAsB,IAAA,CAA7B,IAAOA,CAAP,CAAA,MAAOA,CAAsB,CAI/BC,WAAAA,CACYC,CACAC,CAAAA,CAAAA,CAAuB,CADvB,IAAAD,CAAAA,gBAAAA,CAAAA,EACA,IAAAC,CAAAA,MAAAA,CAAAA,EAJJ,IAAAC,CAAAA,8BAAAA,CAA2D,IAAIC,EAAAA,CAAyB,EAAK,EAKlG,CAEH,IAAIC,OAAO,EAAA,CACP,OAAO,IAAKC,CAAAA,eAAAA,EAAwB,EACxC,CAEA,IAAIC,wBAAwB,EAAA,CACxB,OAAO,IAAKN,CAAAA,gBAAA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