The package.json name and productName field doesn't get read and the app name is always _Electron_ even if the property is set, because the npm run dev script calls this: node .electron-vue/dev-runner.js which spawn electron on this line and probably (but I'm not sure since I'm still a noob) doesn't set the root folder where package.json lives..
This is what I came up after some searches.. is this correct?
I was reading something about this and I found this comment which explains something similar: https://github.com/electron/electron/issues/3391#issuecomment-155606143
Temporary i'm using this to set the correct userData path:
path.join(app.getPath('userData'), `../${pkg.name}`)
When in dev mode, name and version fallback to electron information
When running production app, name and version are set correctly according your package.json definition
is this the preferred way?
If it is I can stick with this method but I've some concerns, If you are developing many apps it's not problematic? since it will always save in the same %APPDATA%/Electron folder and probably some configuration files (in my case config.json) will have the same relative path and name %APPDATA%/Electron/config.json, it can cause problems while developing if you switch projects I guess
is this the preferred way?
I don't really know
I would suggest you to define userData path into src/main/index.dev.js
const {productName} = require('../package.json')
const originalUserData = app.getPath('userData')
app.setPath('userData', path.join(originalUserData, productName))
that is clever, I will do that. Thanks.
btw I still think is kind of a bug.
Sorry, I realized that my previous code isn't working (didn't tried befeore submiting).
Try this one:
import {app} from 'electron'
import path from 'path'
const {build} = require('../../package.json')
const originalUserData = app.getPath('userData')
app.setPath('userData', path.join(originalUserData, build.productName))
Same issue here, and I also think it's a bug.
@p418, shouldn't the workaround be this instead?
import {app} from 'electron'
import path from 'path'
const {build} = require('../../package.json')
const appData = app.getPath('appData')
app.setPath('userData', path.join(appData, build.productName))
Most helpful comment
Same issue here, and I also think it's a bug.
@p418, shouldn't the workaround be this instead?