@@ -4,40 +4,13 @@ import { MessagingOptions, PushNotificationModel } from './messaging';
44declare const com ;
55
66let _launchNotification = null ;
7- // let _senderId: string = null;
8-
9- // function getSenderId(): Promise<string> {
10- // return new Promise((resolve, reject) => {
11- // if (_senderId !== null) {
12- // resolve(_senderId);
13- // }
14-
15- // const setSenderIdAndResolve = () => {
16- // const senderIdResourceId = application.android.context
17- // .getResources()
18- // .getIdentifier('gcm_defaultSenderId', 'string', application.android.context.getPackageName());
19- // if (senderIdResourceId === 0) {
20- // throw new Error(
21- // "####################### Seems like you did not include 'google-services.json' in your project! Firebase Messaging will not work properly. #######################"
22- // );
23- // }
24- // _senderId = application.android.context.getString(senderIdResourceId);
25- // resolve(_senderId);
26- // };
27-
28- // if (!application.android.context) {
29- // // throw new Error("Don't call this function before your app has started.");
30- // application.on(application.launchEvent, () => setSenderIdAndResolve());
31- // } else {
32- // setSenderIdAndResolve();
33- // }
34- // });
35- // }
367
8+ let initialized = false ;
379async function initPushMessaging ( options ?: MessagingOptions ) {
38- if ( ! options ) {
10+ if ( ! options || initialized ) {
3911 return ;
4012 }
13+ initialized = true ;
4114 if ( options . showNotificationsWhenInForeground !== undefined ) {
4215 com . nativescript . push . PushMessagingService . showNotificationsWhenInForeground = options . showNotificationsWhenInForeground ;
4316 }
@@ -111,7 +84,7 @@ export function getCurrentPushToken(): Promise<string> {
11184
11285let _receivedNotificationCallback ;
11386function addOnMessageReceivedCallback ( callback ) {
114- return new Promise ( ( resolve , reject ) => {
87+ return new Promise < void > ( ( resolve , reject ) => {
11588 try {
11689 _receivedNotificationCallback = callback ;
11790
@@ -137,7 +110,7 @@ function addOnMessageReceivedCallback(callback) {
137110}
138111
139112function addOnPushTokenReceivedCallback ( callback ) {
140- return new Promise ( ( resolve , reject ) => {
113+ return new Promise < void > ( ( resolve , reject ) => {
141114 try {
142115 let tokenReturned = false ;
143116 com . nativescript . push . PushMessagingService . setOnPushTokenReceivedCallback (
@@ -220,7 +193,7 @@ export function unregisterForPushNotifications(): Promise<void> {
220193}
221194
222195export function subscribeToTopic ( topicName ) {
223- return new Promise ( ( resolve , reject ) => {
196+ return new Promise < void > ( ( resolve , reject ) => {
224197 try {
225198 const onCompleteListener = new com . google . android . gms . tasks . OnCompleteListener ( {
226199 onComplete : ( task ) => {
@@ -247,7 +220,7 @@ export function subscribeToTopic(topicName) {
247220}
248221
249222export function unsubscribeFromTopic ( topicName ) {
250- return new Promise ( ( resolve , reject ) => {
223+ return new Promise < void > ( ( resolve , reject ) => {
251224 try {
252225 const onCompleteListener = new com . google . android . gms . tasks . OnCompleteListener ( {
253226 onComplete : ( task ) => {
0 commit comments