Skip to content

The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.

1.7 KB
Raw Blame
// The bridge the web app sees as `window.linedeskDesktop` (apps/web/src/native/desktop/bridge.ts), only on the app's own
// server: a provider sign-in or Stripe page in this window gets nothing. The main process checks the sender's origin
// again for every message.
import { contextBridge, ipcRenderer } from 'electron'
import { CHANNEL, type CallNotice, type Labels } from './bridge.ts'

const arg = (name: string) => process.argv.find(a => a.startsWith(`--${name}=`))?.slice(name.length + 3) ?? ''
const server = arg('linedesk-server')
const platform = arg('linedesk-platform')
const version = arg('linedesk-version')

if (server && window.location.origin === server) {
  contextBridge.exposeInMainWorld('linedeskDesktop', {
    platform,
    version,
    /** Opens the server's sign-in page in the system browser; resolves with the loopback address it came back on. */
    signIn: (url: string): Promise<{ url: string }> => ipcRenderer.invoke(CHANNEL.signIn, url),
    notify: (notice: CallNotice) => ipcRenderer.send(CHANNEL.notify, notice),
    setLabels: (labels: Labels) => ipcRenderer.send(CHANNEL.labels, labels),
    setBadge: (count: number) => ipcRenderer.send(CHANNEL.badge, count),
    /** Whether the app opens when the person signs in to the computer (null where it cannot: development). */
    getOpenAtLogin: (): Promise<boolean | null> => ipcRenderer.invoke(CHANNEL.getOpenAtLogin),
    setOpenAtLogin: (on: boolean): Promise<void> => ipcRenderer.invoke(CHANNEL.setOpenAtLogin, on),
    onOpenCall: (fn: (id: string) => void) => {
      const listener = (_: unknown, id: unknown) => typeof id === 'string' && fn(id)
      ipcRenderer.on(CHANNEL.openCall, listener)
      return () => ipcRenderer.off(CHANNEL.openCall, listener)
    },
  })
}