Skip to content

Commit

Permalink
electron: Isolate main and renderer processes
Browse files Browse the repository at this point in the history
Turn on security and isolation features and add a preload script.
  • Loading branch information
rafaellehmkuhl committed Nov 28, 2024
1 parent dd058da commit 2492138
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
7 changes: 3 additions & 4 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ function createWindow(): void {
mainWindow = new BrowserWindow({
icon: join(ROOT_PATH.dist, 'pwa-512x512.png'),
webPreferences: {
webSecurity: false,
contextIsolation: false,
nodeIntegration: true,
allowRunningInsecureContent: true,
preload: join(ROOT_PATH.dist, 'electron/preload.js'),
contextIsolation: true,
nodeIntegration: false,
},
width,
height,
Expand Down
Empty file added electron/preload.ts
Empty file.
36 changes: 23 additions & 13 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,32 @@ const isBuilding = process.argv.includes('build')
export default defineConfig({
plugins: [
(isElectron || isBuilding) &&
electron({
entry: 'electron/main.ts',
vite: {
build: {
outDir: 'dist/electron',
electron([
{
entry: 'electron/main.ts',
vite: {
build: {
outDir: 'dist/electron',
},
},
onstart: () => {
// @ts-ignore: process.electronApp exists in vite-plugin-electron but not in the types
if (process.electronApp) {
// @ts-ignore: process.electronApp.pid exists in vite-plugin-electron but not in the types
treeKillSync(process.electronApp.pid)
}
startup()
},
},
onstart: () => {
// @ts-ignore: process.electronApp exists in vite-plugin-electron but not in the types
if (process.electronApp) {
// @ts-ignore: process.electronApp.pid exists in vite-plugin-electron but not in the types
treeKillSync(process.electronApp.pid)
}
startup()
{
entry: 'electron/preload.ts',
vite: {
build: {
outDir: 'dist/electron',
},
},
},
}),
]),
vue(),
vuetify({
autoImport: true,
Expand Down

0 comments on commit 2492138

Please sign in to comment.