import { contextBridge, ipcRenderer, shell } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
import api from './api'


const exposeContext = async () => {
	if (process.contextIsolated) {
		try {
			contextBridge.exposeInMainWorld('electron', electronAPI)
			contextBridge.exposeInMainWorld('api', api)
			contextBridge.exposeInMainWorld('shell', {
				openExternal: (url: string) => {
					ipcRenderer.invoke('ipcCore:openExternal', url);
				},
				showItemInFolder: (fullPath: string) => {
					ipcRenderer.invoke('ipcCore:showItemInFolder', fullPath);
				}
			});
		} catch (error) {
			console.error(error)
		}
	} else {
		window.electron = electronAPI
		window.api = api;
		window.shell = shell;
	}
}

exposeContext();