Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support User Defined Electron Settings #38

Merged
merged 4 commits into from
Mar 12, 2019

Conversation

erisu
Copy link
Member

@erisu erisu commented Mar 8, 2019

Platforms affected

electron

Motivation and Context

Provide a way to allow users to modify the Cordova Electron Settings file.

Description

This PR allows users to create a file that will be merged with the defaults and and written to the staging area.

The user can create and place the file anywhere from within the project directory and then provides the link within config.xml

Example:

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

This file does not have any filename restrictions.
It will be fetched and merged on top of the Cordova defaults.

Example:
Cordova Defaults are:

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

If the user would like to support Node.JS and Electron APIs, the developer can create a new file with

{
    "browserWindow": {
        "webPreferences": {
            "nodeIntegration": true
         }
    }
}

Testing

  • npm t
  • Travis CI
  • Below Use Cases

Test Case Nightly

npx cordova@nightly create e9x com.foobar.e9x e9x && $_
npx cordova@nightly platform add github:erisu/cordova-electron\#support-user-defined-electron-settings

npx cordova@nightly run electron --nobuild
npx cordova@nightly run electron --nobuild --release
npx cordova@nightly run electron --nobuild --debug

CDVEletronSettings Override Test Case 1

Created res/electron/settings.json with content:

{
    "browserWindow": {
        "width": 1024,
        "height": 768
    }
}

Updated config.xml with content:

<platform name="electron">
    <preference name="ElectronSettingsFilePath" value="res/electron/settings.json" />
</platform>
$ npx cordova@nightly run electron --nobuild

Expected: Larger Size and Open devTools
Result: Pass

CDVEletronSettings Override Test Case 2

Created res/electron/settings.json with content:

{
  "browserWindow": {
    "height": 768,
    "webPreferences": {
      "devTools": false,
      "nodeIntegration": null
    },
    "width": 1024
  }
}

Updated config.xml with content:

<platform name="electron">
    <preference name="ElectronSettingsFilePath" value="res/electron/settings.json" />
</platform>
$ npx cordova@nightly run electron --nobuild

Expected: Large Size, nodeIntegration Warning, devTools open as command overrides this setting.
Result: Pass

npx cordova@nightly build electron
npx cordova@nightly build electron --release
npx cordova@nightly build electron --debug
npx cordova@nightly platform rm electron

Test Case Latest (8.x)

npx cordova@latest create e8x com.foobar.e8x e8x && $_
npx cordova@latest platform add github:erisu/cordova-electron\#support-user-defined-electron-settings

npx cordova@latest run cordova-electron --nobuild
npx cordova@latest run cordova-electron --nobuild --release
npx cordova@latest run cordova-electron --nobuild --debug

CDVEletronSettings Override Test Case 1

Created res/electron/settings.json with content:

{
    "browserWindow": {
        "width": 1024,
        "height": 768
    }
}

Updated config.xml with content:

<platform name="electron">
    <preference name="ElectronSettingsFilePath" value="res/electron/settings.json" />
</platform>
$ npx cordova@latest run cordova-electron --nobuild

Expected: Larger Size and Open devTools
Result: Pass

CDVEletronSettings Override Test Case 2

Created res/electron/settings.json with content:

{
  "browserWindow": {
    "height": 768,
    "webPreferences": {
      "devTools": false,
      "nodeIntegration": null
    },
    "width": 1024
  }
}

Updated config.xml with content:

<platform name="electron">
    <preference name="ElectronSettingsFilePath" value="res/electron/settings.json" />
</platform>
$ npx cordova@latest run cordova-electron --nobuild

Expected: Large Size, nodeIntegration Warning, devTools open as command overrides this setting.
Result: Pass

npx cordova@latest build cordova-electron
npx cordova@latest build cordova-electron --release
npx cordova@latest build cordova-electron --debug
npx cordova@latest platform rm cordova-electron

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@erisu erisu force-pushed the support-user-defined-electron-settings branch 2 times, most recently from 049cb4c to 6c6b132 Compare March 11, 2019 03:48
@erisu erisu force-pushed the support-user-defined-electron-settings branch from 6c6b132 to 4f0e0c9 Compare March 11, 2019 03:53
@erisu erisu marked this pull request as ready for review March 11, 2019 08:02
@erisu erisu requested a review from dpogue March 11, 2019 08:02
@codecov-io
Copy link

codecov-io commented Mar 11, 2019

Codecov Report

Merging #38 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #38   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          13     14    +1     
  Lines         560    568    +8     
=====================================
+ Hits          560    568    +8
Impacted Files Coverage Δ
bin/templates/cordova/lib/prepare.js 100% <100%> (ø) ⬆️
bin/templates/cordova/lib/SettingJsonParser.js 100% <100%> (ø) ⬆️
bin/templates/cordova/lib/build.js 100% <100%> (ø) ⬆️
bin/templates/cordova/lib/util.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a23a0a2...d9e7ef8. Read the comment docs.

@erisu erisu merged commit 4007c3b into apache:master Mar 12, 2019
@erisu erisu deleted the support-user-defined-electron-settings branch April 4, 2019 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants