apache / cordova-electron

Apache Cordova Electron
Apache License 2.0
126 stars 58 forks source link

cdv-electron-settings.json ignored #46

Closed tiptronic closed 5 years ago

tiptronic commented 5 years ago

Bug Report

Maybe I misunderstood something, but no matter what I change in :

platform_www/cdv-electron-settings.json

e.g.:

{
    "browserWindow": {
        "height": 600,
        "webPreferences":{
            "devTools": false,
            "nodeIntegration": false
        },
        "width": 1000
    }
}

the command

cordova run electron

always uses it's default values (and thus shows devtools). I can only avoid that, if I comment the line mainWindow.webContents.openDevTools(); in index.js

Am I missing something, or is this a bug?

Version information

Cordova 9.0.0 MacOS 10.14.4 node v11.7.0

Checklist

GedasGa commented 5 years ago

We do not recommend modifying any files in the platform/ directory. Normally, the platform directory should never be committed to any versioning control service. Modifying will make platform upgrades impossible.

If you want to change the Electron's browserWindow settings, we expect you to create a JSON file anywhere in a folder that is safe to be versioned, for example, res/electron, and then define the ElectronSettingsFilePath preference option to the config.xml file.

    <platform name="electron">
        <preference name="ElectronSettingsFilePath" value="res/electron/settings.json" />
    </platform>

However, with regards to the devTools option, we do not accept the user define value. This option is overridden by the Cordova CLI flag --debug (default) or --release.

If you do not want the Dev Tools visible, build or run with the --release flag.

tiptronic commented 5 years ago

thx @GedasGa for the explanation. I am using privat settings, but was wondering why the devTools option wasn't respected. So my conclusion was, they don't (or only partially) load. Although it is mentioned in the docs, it is somehow confusing, since my preferences should have priority, no? Having the devTools closed in a debug build is common practice (at least for me 😉 ), so it would be great to have this behaviour swapped.

I hope it is ok to ask one more question here: In the docs it is mentioned that cordova run electron --no-build will allow for a quick build. But for me it doesn't work. It always builds and signs, like so:

andy$ cordova run electron --no-build
  • electron-builder version=20.39.0
  • writing effective config file=platforms/electron/build/builder-effective-config.yaml
  • installing production dependencies platform=darwin arch=x64 appDir=/Users/andy/dev-git/ElectroKC/platforms/electron/www
  • packaging       platform=darwin arch=x64 electron=4.0.1 appOutDir=platforms/electron/build/mac
  • signing         file=platforms/electron/build/mac/ZoneMaster.app identityName=Developer ID Application: Andy Fuchs (XXXX) identityHash=XXXX provisioningProfile=none
  • building        target=DMG arch=x64 file=platforms/electron/build/TestApp-1.0.0.dmg
  • building        target=macOS zip arch=x64 file=platforms/electron/build/TestApp-1.0.0-mac.zip
  • building block map blockMapFile=platforms/electron/build/TestApp-1.0.0.dmg.blockmap
  • building embedded block map file=platforms/electron/build/TestApp-1.0.0-mac.zip

Is this expected, or is there anything I am missing? tia

GedasGa commented 5 years ago

I don't think it's gonna be swapped. The debug build is typically meant for debugging and it's expected that users are probably going to use the Dev Tools. Plus, we use the same flags across other platforms in Cordova too.

You might be looking at the old documentation. To disable the build process you should use --nobuild flag.

cordova run electron --nobuild

Please, refer to the Cordova documentation.

tiptronic commented 5 years ago

thx! I had indeed some outdated docs... sorry for the spam

tiptronic commented 5 years ago

Here's one more thing: You recommend not to modify the platform_www directory. So what do you recommend if I need core functionality to run in the main process (no UI/DOM, just backend code). I haven't found any other way in the docs how to attach something to the main process. Any hint?

GedasGa commented 5 years ago

If it's not the settings file, that I've described above, then you may need to you either a hook script or manually modify files. As I said previously, generally, we don't recommend manually editing the files, but there are cases that can't be helped. Just remember, if you ever update the platform you would have to manually reapply your changes.