import { contextBridge, ipcRenderer, shell } from 'electron' import { electronAPI } from '@electron-toolkit/preload' import api from './api' const applicationLoader = `
`; const applicationError = `

Application Error

The application failed to load properly. Please wait for application repairing or reinstall application.

${applicationLoader}

rosetta - powering freedom. visit about rosetta-im.com. error: boot_process_failed

`; const exposeContext = async () => { let version = await ipcRenderer.invoke("get-core-version"); let appPath = await ipcRenderer.invoke("get-app-path"); let arch = await ipcRenderer.invoke("get-arch"); let deviceName = await ipcRenderer.invoke("device:name"); let deviceId = await ipcRenderer.invoke("device:id"); setTimeout(() => { if(document.body.innerHTML.length < 100){ document.body.innerHTML = applicationError; ipcRenderer.invoke("report-boot-process-failed"); } }, 3000); let downloadsPath = await ipcRenderer.invoke("get-downloads-path"); if (process.contextIsolated) { try { contextBridge.exposeInMainWorld('electron', electronAPI) contextBridge.exposeInMainWorld('api', api) contextBridge.exposeInMainWorld('version', version); contextBridge.exposeInMainWorld('platform', process.platform); contextBridge.exposeInMainWorld('appPath', appPath); contextBridge.exposeInMainWorld('arch', arch); contextBridge.exposeInMainWorld('deviceName', deviceName); contextBridge.exposeInMainWorld('deviceId', deviceId); contextBridge.exposeInMainWorld('shell', { openExternal: (url: string) => { ipcRenderer.invoke('openExternal', url); }, showItemInFolder: (fullPath: string) => { ipcRenderer.invoke('showItemInFolder', fullPath); } }); contextBridge.exposeInMainWorld('downloadsPath', downloadsPath) } catch (error) { console.error(error) } } else { window.electron = electronAPI window.api = api window.version = version; window.platform = process.platform; window.appPath = appPath; window.arch = arch; window.shell = shell; window.downloadsPath = downloadsPath; window.deviceName = deviceName; window.deviceId = deviceId; } } exposeContext();