# leadin/11.0.54/scripts/utils/backgroundAppUtils.ts

HubSpot All-In-One Marketing – Forms, Popups, Live Chat, version 11.0.54. 45 lines.

- Page: https://pluginprobe.com/plugins/leadin/11.0.54/code/scripts/utils/backgroundAppUtils.ts
- Raw: https://pluginprobe.com/plugins/leadin/11.0.54/raw/scripts/utils/backgroundAppUtils.ts
- Modified: 2024-04-12T13:24:50+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/leadin/11.0.54/code/scripts/utils/backgroundAppUtils.ts#L10-L20`.

```typescript
import {
  deviceId,
  hubspotBaseUrl,
  locale,
  portalId,
} from '../constants/leadinConfig';
import { initApp } from './appUtils';

type CallbackFn = (...args: any[]) => void;

export function initBackgroundApp(initFn: CallbackFn | CallbackFn[]) {
  function main() {
    if (Array.isArray(initFn)) {
      initFn.forEach(callback => callback());
    } else {
      initFn();
    }
  }
  initApp(main);
}

export const getOrCreateBackgroundApp = (refreshToken: string) => {
  if ((window as any).LeadinBackgroundApp) {
    return (window as any).LeadinBackgroundApp;
  }
  const { IntegratedAppEmbedder, IntegratedAppOptions }: any = window;
  const options = new IntegratedAppOptions()
    .setLocale(locale)
    .setDeviceId(deviceId)
    .setRefreshToken(refreshToken);

  const embedder = new IntegratedAppEmbedder(
    'integrated-plugin-proxy',
    portalId,
    hubspotBaseUrl,
    () => {}
  ).setOptions(options);

  embedder.attachTo(document.body, false);
  embedder.postStartAppMessage(); // lets the app know all all data has been passed to it

  (window as any).LeadinBackgroundApp = embedder;
  return (window as any).LeadinBackgroundApp;
};

```
