As in title, here is the idea:
// preload.ts
import {contextBridge, ipcRenderer, shell} from "electron"
import {LocalStorage} from "./LocalStorage.ts";
contextBridge.exposeInMainWorld("electron", {
settings: {
getSettings: () => {
const foo = new LocalStorage() // defined in electron/main dir
return foo.getSettings()
},
},
...
})
mind you, I receive other objects without issues should I comment out new LocalStorage()
The error that drops in browser's dev tools
TypeError: Cannot read properties of undefined (reading 'isPackaged') which originates in attached image.
Am I missing something obvious
?
Part of vite's/rollup's config
export default defineConfig({command{) => {
// ...
return {
// ...
plugins: [
// ...
electron([
// ...
{
entry: "electron/preload/index.ts",
onstart(options) {
// Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
// instead of restarting the entire Electron App.
options.reload()
},
vite: {
build: {
sourcemap: sourcemap ? "inline" : undefined, // #332
minify: isBuild,
outDir: "dist-electron/preload",
rollupOptions: {
external: Object.keys("dependencies" in pkg ? pkg.dependencies : {}),
},
},
},
]),
]
}
}
