1
1
const ONESIGNAL_SDK_ID = 'onesignal-sdk' ;
2
- const ONE_SIGNAL_SCRIPT_SRC = "https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js" ;
2
+ const ONE_SIGNAL_SCRIPT_SRC =
3
+ 'https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js' ;
3
4
4
5
// true if the script is successfully loaded from CDN.
5
6
let isOneSignalInitialized = false ;
@@ -39,7 +40,7 @@ function addSDKScript() {
39
40
// This is important for users who may block cdn.onesignal.com w/ adblock.
40
41
script . onerror = ( ) => {
41
42
handleOnError ( ) ;
42
- }
43
+ } ;
43
44
44
45
document . head . appendChild ( script ) ;
45
46
}
@@ -57,20 +58,26 @@ function isPushNotificationsSupported() {
57
58
58
59
function isMacOSSafariInIframe ( ) : boolean {
59
60
// Fallback detection for Safari on macOS in an iframe context
60
- return window . top !== window && // isContextIframe
61
- navigator . vendor === "Apple Computer, Inc." && // isSafari
62
- navigator . platform === "MacIntel" ; // isMacOS
61
+ return (
62
+ window . top !== window && // isContextIframe
63
+ navigator . vendor === 'Apple Computer, Inc.' && // isSafari
64
+ navigator . platform === 'MacIntel'
65
+ ) ; // isMacOS
63
66
}
64
67
65
68
function supportsSafariPush ( ) : boolean {
66
- return ( window . safari && typeof window . safari . pushNotification !== "undefined" ) ||
67
- isMacOSSafariInIframe ( ) ;
69
+ return (
70
+ ( window . safari && typeof window . safari . pushNotification !== 'undefined' ) ||
71
+ isMacOSSafariInIframe ( )
72
+ ) ;
68
73
}
69
74
70
75
// Does the browser support the standard Push API
71
76
function supportsVapidPush ( ) : boolean {
72
- return typeof PushSubscriptionOptions !== "undefined" &&
73
- PushSubscriptionOptions . prototype . hasOwnProperty ( "applicationServerKey" ) ;
77
+ return (
78
+ typeof PushSubscriptionOptions !== 'undefined' &&
79
+ PushSubscriptionOptions . prototype . hasOwnProperty ( 'applicationServerKey' )
80
+ ) ;
74
81
}
75
82
/* E N D */
76
83
@@ -82,7 +89,7 @@ function supportsVapidPush(): boolean {
82
89
*/
83
90
const isPushSupported = ( ) : boolean => {
84
91
return isPushNotificationsSupported ( ) ;
85
- }
92
+ } ;
86
93
87
94
/**
88
95
* @PublicApi
@@ -93,19 +100,21 @@ const init = (options: IInitObject): Promise<void> => {
93
100
}
94
101
95
102
if ( ! options || ! options . appId ) {
96
- throw new Error ( 'You need to provide your OneSignal appId.' ) ;
103
+ return Promise . reject ( 'You need to provide your OneSignal appId.' ) ;
97
104
}
98
105
99
106
if ( ! document ) {
100
107
return Promise . reject ( `Document is not defined.` ) ;
101
108
}
102
109
103
- return new Promise < void > ( ( resolve ) => {
110
+ return new Promise < void > ( ( resolve , reject ) => {
104
111
window . OneSignalDeferred ?. push ( ( OneSignal ) => {
105
- OneSignal . init ( options ) . then ( ( ) => {
106
- isOneSignalInitialized = true ;
107
- resolve ( ) ;
108
- } ) ;
112
+ OneSignal . init ( options )
113
+ . then ( ( ) => {
114
+ isOneSignalInitialized = true ;
115
+ resolve ( ) ;
116
+ } )
117
+ . catch ( reject ) ;
109
118
} ) ;
110
119
} ) ;
111
120
} ;
@@ -117,7 +126,7 @@ export interface IOneSignalTagCategory { tag: string; label: string; checked?: b
117
126
export type PushSubscriptionNamespaceProperties = { id : string | null | undefined ; token : string | null | undefined ; optedIn : boolean ; } ;
118
127
export type SubscriptionChangeEvent = { previous : PushSubscriptionNamespaceProperties ; current : PushSubscriptionNamespaceProperties ; } ;
119
128
export type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay' ;
120
- export type SlidedownEventName = 'slidedownShown' ;
129
+ export type SlidedownEventName = 'slidedownAllowClick' | 'slidedownCancelClick' | 'slidedownClosed' | 'slidedownQueued' | ' slidedownShown';
121
130
export type OneSignalDeferredLoadedCallback = ( onesignal : IOneSignalOneSignal ) => void ;
122
131
export interface IOSNotification {
123
132
/**
0 commit comments