Browse Source
- Properly disable service workers in electron builds - Add CSP headers for electron security - Fix path resolution in electron context - Improve preload script error handling and IPC setup - Update build scripts for better electron/capacitor compatibility - Fix router path handling in electron context - Remove electron-builder dependency - Streamline build process and output structure This change improves the stability and security of electron builds while maintaining PWA functionality in web builds. Service workers are now properly disabled in electron context, and path resolution issues are fixed.pull/126/head
10 changed files with 372 additions and 2797 deletions
File diff suppressed because it is too large
@ -1,5 +1,55 @@ |
|||
const { contextBridge } = require("electron"); |
|||
const { contextBridge, ipcRenderer } = require('electron'); |
|||
|
|||
contextBridge.exposeInMainWorld("api", { |
|||
logMessage: (message) => console.log(`[Electron]: ${message}`), |
|||
}); |
|||
// Use a more direct path resolution approach
|
|||
const getPath = (pathType) => { |
|||
switch(pathType) { |
|||
case 'userData': |
|||
return process.env.APPDATA || ( |
|||
process.platform === 'darwin' |
|||
? `${process.env.HOME}/Library/Application Support` |
|||
: `${process.env.HOME}/.local/share` |
|||
); |
|||
case 'home': |
|||
return process.env.HOME; |
|||
case 'appPath': |
|||
return process.resourcesPath; |
|||
default: |
|||
return ''; |
|||
} |
|||
}; |
|||
|
|||
console.log('Preload script starting...'); |
|||
|
|||
try { |
|||
contextBridge.exposeInMainWorld('electronAPI', { |
|||
// Path utilities
|
|||
getPath, |
|||
|
|||
// IPC functions
|
|||
send: (channel, data) => { |
|||
const validChannels = ['toMain']; |
|||
if (validChannels.includes(channel)) { |
|||
ipcRenderer.send(channel, data); |
|||
} |
|||
}, |
|||
receive: (channel, func) => { |
|||
const validChannels = ['fromMain']; |
|||
if (validChannels.includes(channel)) { |
|||
ipcRenderer.on(channel, (event, ...args) => func(...args)); |
|||
} |
|||
}, |
|||
// Environment info
|
|||
env: { |
|||
isElectron: true, |
|||
isDev: process.env.NODE_ENV === 'development' |
|||
}, |
|||
// Path utilities
|
|||
getBasePath: () => { |
|||
return process.env.NODE_ENV === 'development' ? '/' : './'; |
|||
} |
|||
}); |
|||
|
|||
console.log('Preload script completed successfully'); |
|||
} catch (error) { |
|||
console.error('Error in preload script:', error); |
|||
} |
Loading…
Reference in new issue