/
AirshipPreferenceCenter.ts
62 lines (57 loc) · 1.91 KB
/
AirshipPreferenceCenter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type { PluginListenerHandle } from '@capacitor/core';
import { EventType } from './EventType';
import type { AirshipPluginWrapper } from './AirshipPlugin';
import type { DisplayPreferenceCenterEvent, PreferenceCenter } from './types';
/**
* Airship Preference Center.
*/
export class AirshipPreferenceCenter {
constructor(private readonly plugin: AirshipPluginWrapper) {}
/**
* Requests to display a preference center.
*
* Will either emit an event to display the
* Preference Center if auto launch is disabled,
* or display the OOTB UI.
* @param preferenceCenterId The preference center Id.
* @returns A promise.
*/
public display(preferenceCenterId: string): Promise<void> {
return this.plugin.perform('preferenceCenter#display', preferenceCenterId);
}
/**
* Gets the preference center config.
* @param preferenceCenterId The preference center Id.
* @returns A promise with the result.
*/
public getConfig(preferenceCenterId: string): Promise<PreferenceCenter> {
return this.plugin.perform(
'preferenceCenter#getConfig',
preferenceCenterId,
);
}
/**
* Enables or disables showing the OOTB UI when requested to display by either
* `display` or by a notification with some other action.
* @param preferenceCenterId The preference center Id.
* @param autoLaunch true to show OOTB UI, false to emit events.
* @returns A promise with the result.
*/
public setAutoLaunchDefaultPreferenceCenter(
preferenceCenterId: string,
autoLaunch: boolean,
): Promise<void> {
return this.plugin.perform('preferenceCenter#getConfig', [
preferenceCenterId,
autoLaunch,
]);
}
/**
* Adds a display message center listener.
*/
public onDisplay(
listener: (event: DisplayPreferenceCenterEvent) => void,
): Promise<PluginListenerHandle> {
return this.plugin.addListener(EventType.DisplayPreferenceCenter, listener);
}
}