1 import { hasInboxDesktopFeature, invokeInboxDesktopIPC } from '@proton/shared/lib/desktop/ipcHelpers';
3 import type createApi from '../api/createApi';
4 import { getApiError } from '../api/helpers/apiErrorHelper';
5 import type { AuthenticationStore } from '../authentication/createAuthenticationStore';
6 import { handleLogout } from '../authentication/logout';
7 import type { APP_NAMES } from '../constants';
8 import { API_CUSTOM_ERROR_CODES } from '../errors';
10 export const endOfTrialIPCCall = () => {
11 if (hasInboxDesktopFeature('MultiAccount')) {
12 invokeInboxDesktopIPC({
16 invokeInboxDesktopIPC({
18 payload: 'trialEnded',
23 export const resetEndOfTrialIPCCall = () => {
24 if (!hasInboxDesktopFeature('MultiAccount')) {
25 invokeInboxDesktopIPC({
27 payload: 'resetTrialEnded',
32 export const listenFreeTrialSessionExpiration = (
34 authentication: AuthenticationStore,
35 api: ReturnType<typeof createApi>
37 const runEffect = async () => {
39 await handleLogout({ appName, authentication, clearDeviceRecoveryData: true, type: 'full' });
45 api.addEventListener((event) => {
46 if (event.type === 'logout' && event.payload.error) {
47 const { code } = getApiError(event.payload.error?.originalError);
49 if (code === API_CUSTOM_ERROR_CODES.INBOX_DESKTOP_TRIAL_END) {