Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
registerEvents([
'showPreviousTab',
'closeInAppBrowser',
// TODO The iOS apps don't emit the event to the webviews without registration till Lib 15.2.
// This needs to be removed, when IOS-1886 is done and the the iOS apps are updated.
'httpResponse',
]);
// Add event callbacks
event.addCallback('pageContext', pageContext);
event.addCallback('showPreviousTab', showPreviousTab);
/**
* This event is triggered form the desktop shop in the inAppBrowser.
* We have to close the inAppBrowser and redirect the user to the given url.
*/
event.addCallback('closeInAppBrowser', (data = {}) => {
if (data.redirectTo) {
new ParsedLink(data.redirectTo).open();
}
closeInAppBrowser(isAndroid(getState()));
});
/**
* The following events are sometimes sent by the app, but don't need to be handled right now.
* To avoid console warnings from the event system, empty handlers are registered here.
*/
event.addCallback('viewDidAppear', () => {});
event.addCallback('viewDidDisappear', () => {});
event.addCallback('pageInsetsChanged', () => {});
});
}
}
/**
* Handler for the app event.
*/
const handler = async () => {
event.removeCallback(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND, handler);
[{ status }] = await getAppPermissions([permissionId]);
resolve(status === STATUS_GRANTED);
};
/**
* Register an event handler, so that we can perform the permissions check again,
* when the user comes back from the settings.
*/
event.addCallback(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND, handler);
// Open the settings (protected by a timeout, so that the modal closes before the app is left).
setTimeout(() => {
openAppSettings();
}, 0);
}
});
subscribe(appDidStart$, ({ getState }) => {
// Register for custom events
registerEvents([
'showPreviousTab',
'closeInAppBrowser',
// TODO The iOS apps don't emit the event to the webviews without registration till Lib 15.2.
// This needs to be removed, when IOS-1886 is done and the the iOS apps are updated.
'httpResponse',
]);
// Add event callbacks
event.addCallback('pageContext', pageContext);
event.addCallback('showPreviousTab', showPreviousTab);
/**
* This event is triggered form the desktop shop in the inAppBrowser.
* We have to close the inAppBrowser and redirect the user to the given url.
*/
event.addCallback('closeInAppBrowser', (data = {}) => {
if (data.redirectTo) {
new ParsedLink(data.redirectTo).open();
}
closeInAppBrowser(isAndroid(getState()));
});
/**
* The following events are sometimes sent by the app, but don't need to be handled right now.
* To avoid console warnings from the event system, empty handlers are registered here.
const registerLinkEvents = location => (dispatch) => {
dispatch(willRegisterLinkEvents());
registerEvents([
'openPushNotification',
'openDeepLink',
]);
event.addCallback('openLink', handler =>
dispatch(openLink(handler.action, handler.options))
);
event.addCallback('openPushNotification', payload =>
dispatch(handlePushNotification(payload))
);
event.addCallback('openDeepLink', payload =>
dispatch(handleDeepLink(payload))
);
window.push = (payload) => dispatch(handlePushNotification(payload));
window.deeplink = (payload) => dispatch(handleDeepLink(payload));
dispatch(didRegisterLinkEvents());
// ??
dispatch(openLink('reactRouter', {
url: location.pathname,
// Push (deeplink) with coupon concurrent to get cart on app start
pipelineDependencies.set(pipelines.SHOPGATE_CART_ADD_COUPONS, [
pipelines.SHOPGATE_CART_ADD_PRODUCTS,
pipelines.SHOPGATE_CART_GET_CART,
]);
pipelineDependencies.set(pipelines.SHOPGATE_CART_DELETE_COUPONS, [
pipelines.SHOPGATE_CART_ADD_PRODUCTS,
pipelines.SHOPGATE_CART_GET_CART,
]);
/**
* Reload the cart whenever the WebView becomes visible.
* This is needed, for example, when the cart is modified from another inAppBrowser tab like a
* web-checkout and the user closes the said tab before reaching the success page.
*/
event.addCallback('viewWillAppear', () => {
dispatch(fetchCart());
});
// Reset the productPendingCount on app start to avoid a wrong value in the cart badge.
dispatch(setCartProductPendingCount(0));
});
const registerLinkEvents = location => (dispatch) => {
dispatch(willRegisterLinkEvents());
registerEvents([
'openPushNotification',
'openDeepLink',
]);
event.addCallback('openLink', handler =>
dispatch(openLink(handler.action, handler.options))
);
event.addCallback('openPushNotification', payload =>
dispatch(handlePushNotification(payload))
);
event.addCallback('openDeepLink', payload =>
dispatch(handleDeepLink(payload))
);
window.push = (payload) => dispatch(handlePushNotification(payload));
window.deeplink = (payload) => dispatch(handleDeepLink(payload));
dispatch(didRegisterLinkEvents());
// ??
*/
event.addCallback('closeInAppBrowser', (data = {}) => {
if (data.redirectTo) {
new ParsedLink(data.redirectTo).open();
}
closeInAppBrowser(isAndroid(getState()));
});
/**
* The following events are sometimes sent by the app, but don't need to be handled right now.
* To avoid console warnings from the event system, empty handlers are registered here.
*/
event.addCallback('viewDidAppear', () => {});
event.addCallback('viewDidDisappear', () => {});
event.addCallback('pageInsetsChanged', () => {});
});
}
constructor(props) {
super(props);
this.state = {
isVisible: true,
};
event.addCallback(APP_EVENT_VIEW_WILL_APPEAR, this.setVisible);
event.addCallback(APP_EVENT_VIEW_WILL_DISAPPEAR, this.setHidden);
}
const attachLinkEvents = () => {
registerEvents(['openPushNotification', 'openDeepLink']);
event.addCallback('openPushNotification', handleOpenPushNotification);
event.addCallback('openDeepLink', handleOpenDeepLink);
};
componentDidMount() {
event.addCallback(EVENT_ADD_TO_CART_MISSING_VARIANT, this.handleMissingVariant);
}