Skip to content

Commit 9c761ea

Browse files
committed
simplify safari logic
1 parent 88d3195 commit 9c761ea

File tree

16 files changed

+51
-286
lines changed

16 files changed

+51
-286
lines changed

src/core/types/subscription.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export const SubscriptionType = {
1212
Email: 'Email',
1313
SMS: 'SMS',
1414
SafariPush: 'SafariPush',
15-
SafariLegacyPush: 'SafariLegacyPush',
1615
FirefoxPush: 'FirefoxPush',
1716
// And others but not relevant for Web SDK
1817
// macOSPush: 'macOSPush',

src/global.d.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
11
import { OneSignalDeferredLoadedCallback } from './page/models/OneSignalDeferredLoadedCallback';
22

3-
/**
4-
* Types and names collected from:
5-
* - https://developer.apple.com/documentation/safariextensions/safariremotenotification
6-
* - https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/NotificationProgrammingGuideForWebsites/PushNotifications/PushNotifications.html
7-
*/
8-
interface SafariRemoteNotificationPermission {
9-
readonly deviceToken: string | null;
10-
readonly permission: 'default' | 'granted' | 'denied';
11-
}
12-
13-
interface SafariRemoteNotification {
14-
permission(
15-
websitePushID: string | undefined,
16-
): SafariRemoteNotificationPermission;
17-
requestPermission(
18-
webAPIURL: string,
19-
websitePushID: string | undefined,
20-
queryParameterDictionary: unknown,
21-
callback: (permissionData: SafariRemoteNotificationPermission) => void,
22-
): void;
23-
}
24-
253
type _OneSignal = typeof import('./onesignal/OneSignal').default;
264

275
declare global {
@@ -31,8 +9,6 @@ declare global {
319
OneSignal: _OneSignal;
3210
OneSignalDeferred?: OneSignalDeferredLoadedCallback[];
3311
__oneSignalSdkLoadCount?: number;
34-
safari?: {
35-
pushNotification?: SafariRemoteNotification;
36-
};
12+
safari?: {};
3713
}
3814
}

src/page/bell/Dialog.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import OneSignalEvent from '../../shared/services/OneSignalEvent';
21
import SdkEnvironment from '../../shared/managers/SdkEnvironment';
2+
import OneSignalEvent from '../../shared/services/OneSignalEvent';
3+
import { bowserCastle } from '../../shared/utils/bowserCastle';
34
import {
45
addDomElement,
56
clearDomElementChildren,
67
getPlatformNotificationIcon,
78
} from '../../shared/utils/utils';
9+
import type { NotificationIcons } from '../types';
810
import AnimatedElement from './AnimatedElement';
911
import Bell from './Bell';
10-
import { bowserCastle } from '../../shared/utils/bowserCastle';
1112

1213
export default class Dialog extends AnimatedElement {
1314
public bell: Bell;

src/page/slidedown/Slidedown.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
1-
import OneSignalEvent from '../../shared/services/OneSignalEvent';
1+
import { SERVER_CONFIG_DEFAULTS_SLIDEDOWN } from '../../shared/config/constants';
2+
import { Utils } from '../../shared/context/Utils';
23
import MainHelper from '../../shared/helpers/MainHelper';
4+
import PromptsHelper from '../../shared/helpers/PromptsHelper';
5+
import {
6+
DelayedPromptType,
7+
SlidedownPromptOptions,
8+
} from '../../shared/models/Prompts';
9+
import OneSignalEvent from '../../shared/services/OneSignalEvent';
10+
import {
11+
COLORS,
12+
SLIDEDOWN_CSS_CLASSES,
13+
SLIDEDOWN_CSS_IDS,
14+
} from '../../shared/slidedown/constants';
15+
import { bowserCastle } from '../../shared/utils/bowserCastle';
316
import {
417
addCssClass,
518
addDomElement,
19+
getDomElementOrStub,
620
getPlatformNotificationIcon,
721
once,
8-
removeDomElement,
922
removeCssClass,
10-
getDomElementOrStub,
23+
removeDomElement,
1124
} from '../../shared/utils/utils';
12-
import { SERVER_CONFIG_DEFAULTS_SLIDEDOWN } from '../../shared/config/constants';
25+
import { InvalidChannelInputField } from '../errors/ChannelCaptureError';
26+
import { TagCategory } from '../models/Tags';
27+
import type { NotificationIcons } from '../types';
28+
import ChannelCaptureContainer from './ChannelCaptureContainer';
1329
import { getLoadingIndicatorWithColor } from './LoadingIndicator';
1430
import { getRetryIndicator } from './RetryIndicator';
15-
import {
16-
SLIDEDOWN_CSS_CLASSES,
17-
SLIDEDOWN_CSS_IDS,
18-
COLORS,
19-
} from '../../shared/slidedown/constants';
20-
import { TagCategory } from '../models/Tags';
2131
import { getSlidedownElement } from './SlidedownElement';
22-
import { Utils } from '../../shared/context/Utils';
23-
import ChannelCaptureContainer from './ChannelCaptureContainer';
24-
import PromptsHelper from '../../shared/helpers/PromptsHelper';
25-
import {
26-
SlidedownPromptOptions,
27-
DelayedPromptType,
28-
} from '../../shared/models/Prompts';
29-
import { InvalidChannelInputField } from '../errors/ChannelCaptureError';
30-
import { bowserCastle } from '../../shared/utils/bowserCastle';
3132

3233
export default class Slidedown {
3334
public options: SlidedownPromptOptions;

src/page/models/NotificationIcons.ts renamed to src/page/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
interface NotificationIcons {
1+
export interface NotificationIcons {
22
chrome?: string;
33
firefox?: string;
44
safari?: string;

src/page/userModel/FuturePushSubscriptionRecord.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ export default class FuturePushSubscriptionRecord implements Serializable {
7070
if (Environment.useSafariVapidPush()) {
7171
return SubscriptionType.SafariPush;
7272
}
73-
if (Environment.useSafariLegacyPush()) {
74-
return SubscriptionType.SafariLegacyPush;
75-
}
7673
// Other browsers, like Edge, are Chromium based so we consider them "Chrome".
7774
return SubscriptionType.ChromePush;
7875
}
@@ -85,8 +82,6 @@ export default class FuturePushSubscriptionRecord implements Serializable {
8582
switch (this.getSubscriptionType()) {
8683
case SubscriptionType.FirefoxPush:
8784
return DeliveryPlatformKind.Firefox;
88-
case SubscriptionType.SafariLegacyPush:
89-
return DeliveryPlatformKind.SafariLegacy;
9085
case SubscriptionType.SafariPush:
9186
return DeliveryPlatformKind.SafariVapid;
9287
}

src/page/utils/BrowserSupportsPush.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,7 @@
66
// Checks if the browser supports push notifications by checking if specific
77
// classes and properties on them exist
88
export function isPushNotificationsSupported() {
9-
return supportsVapidPush() || supportsSafariLegacyPush();
10-
}
11-
12-
// Does the browser support legacy Safari push? (only available on macOS)
13-
export function supportsSafariLegacyPush(): boolean {
14-
return (
15-
typeof window.safari !== 'undefined' &&
16-
typeof window.safari.pushNotification !== 'undefined'
17-
);
9+
return supportsVapidPush();
1810
}
1911

2012
// Does the browser support the standard Push API

src/shared/helpers/Environment.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,8 @@ export default class Environment {
1212
return typeof window !== 'undefined';
1313
}
1414

15-
// Prefer Legacy Safari if API is available over VAPID until Safari
16-
// fixes issues with it.
17-
public static useSafariLegacyPush(): boolean {
18-
return this.isBrowser() && window.safari?.pushNotification != undefined;
19-
}
20-
21-
// This is the counter part to useSafariLegacyPush(); as it notes only use
22-
// Safari VAPID if it doesn't have legacy Safari push.
2315
public static useSafariVapidPush(): boolean {
24-
return (
25-
bowserCastle().name == 'safari' &&
26-
supportsVapidPush() &&
27-
!this.useSafariLegacyPush()
28-
);
16+
return bowserCastle().name == 'safari' && supportsVapidPush();
2917
}
3018

3119
public static version() {

src/shared/helpers/MainHelper.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
import Database from '../services/Database';
2222
import { PermissionUtils } from '../utils/PermissionUtils';
2323
import { getPlatformNotificationIcon, logMethodCall } from '../utils/utils';
24-
import Environment from './Environment';
2524

2625
export default class MainHelper {
2726
static async showLocalNotification(
@@ -234,13 +233,6 @@ export default class MainHelper {
234233

235234
// TO DO: unit test
236235
static async getCurrentPushToken(): Promise<string | undefined> {
237-
if (Environment.useSafariLegacyPush()) {
238-
const safariToken = window.safari?.pushNotification?.permission(
239-
OneSignal.config.safariWebId,
240-
).deviceToken;
241-
return safariToken?.toLowerCase() || undefined;
242-
}
243-
244236
const registration =
245237
await OneSignal.context.serviceWorkerManager.getRegistration();
246238
if (!registration) {

src/shared/helpers/SubscriptionHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default class SubscriptionHelper {
3131
const rawSubscription = await context.subscriptionManager.subscribe(
3232
SubscriptionStrategyKind.ResubscribeExisting,
3333
);
34+
console.warn('rawSubscription', rawSubscription);
3435
subscription =
3536
await context.subscriptionManager.registerSubscription(
3637
rawSubscription,
@@ -56,7 +57,6 @@ export default class SubscriptionHelper {
5657
switch (type) {
5758
case SubscriptionType.ChromePush:
5859
case SubscriptionType.SafariPush:
59-
case SubscriptionType.SafariLegacyPush:
6060
case SubscriptionType.FirefoxPush:
6161
return true;
6262
default:

0 commit comments

Comments
 (0)