Closed lynxionxs closed 6 months ago
app
cannot be used in preload/renderer. You should use ipc to handle.
@alex8088 How to use ipc to handle ? All i want is to get the app.getPath('appData')
Can you give example using IPC ?
@alex8088 Thanks. Is it okay to use the ipcRenderer from electron in the preload script, or must i use the ipcRenderer from electronAPI
in preload script ?
../preload/index.ts
import { contextBridge, ipcRenderer } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
// Custom APIs for renderer
const api = {
getAppDataPath: () => ipcRenderer.invoke('get-appData-path')
}
if (process.contextIsolated) {
try {
contextBridge.exposeInMainWorld('electron', electronAPI)
contextBridge.exposeInMainWorld('api', api)
} catch (error) {
console.error(error)
}
} else {
// @ts-ignore (define in dts)
window.electron = electronAPI
// @ts-ignore (define in dts)
window.api = api
}
Describe the bug
Why is there only 3 electron api's available with
import { electronAPI } from '@electron-toolkit/preload'
?process, ipcRenderer, webFrame
. Example : I want to use the api forapp
to get the data pathapp.getPath('appData')
. Importingapp
in../preload/index.ts
import { app, contextBridge } from 'electron'
showsapp
asundefined
. Now how am i supposed to get access to those other electron api's ?Electron-Toolkit Version
3.0.0
Electron Version
28.2.0
Validations