Electron 7.1.2对话框显示应用名为‘Electron’而非package.json实际名称
I’ve run into this exact quirk with Electron 7.x before—this happens because by default, Electron uses its own name ("Electron") in system dialogs unless you explicitly set your app’s identity, either in the main process or via your packaging configuration. Here’s how to fix it:
1. Set Your App Name in the Main Process
First, explicitly set your app’s name right after the app finishes initializing. This overrides the default "Electron" label for all system dialogs, including the save dialog you’re using.
Update your main.js to include app.setName():
const { app, BrowserWindow, dialog } = require('electron'); let mainWindow; app.whenReady().then(() => { // Replace with your actual app name from package.json app.setName('Your App Name'); mainWindow = new BrowserWindow({ // Your existing window configuration (width, height, webPreferences, etc.) }); // Rest of your app initialization code... }); // Your existing pdfMaxSave function const pdfMaxSave = exports.pdfMaxSave = () => { let options = { title: 'Save to pdf', buttonLabel: 'save pdf', filters: [ { name: 'pdf', extensions: ['pdf'] }, ] } dialog.showSaveDialog(mainWindow, options).then(response => { console.log(response.filePath); }); }
2. Configure Packaging for Production Builds
If you’re building a production version of your app, you’ll also need to set the product name in your packaging tool’s config (like electron-builder or electron-packager) to ensure the name persists after bundling:
For electron-builder, add this to your package.json:
"build": { "productName": "Your App Name", "appId": "com.yourdomain.yourapp" }
Why This Works
In Electron 7.1.2, the default app name is hardcoded to "Electron" in development mode. Calling app.setName() overwrites this value at runtime, and system dialogs will immediately use your custom name. For production builds, the packaging tool uses productName to set the app’s core metadata, which also affects dialog labels and system-level app identification.
内容的提问来源于stack exchange,提问作者xaander1




