Skip to content

Commit

Permalink
Merge pull request #2932 from balena-io/electron6
Browse files Browse the repository at this point in the history
Electron6
  • Loading branch information
zvin authored Dec 3, 2019
2 parents 3dd6895 + 220b7f6 commit 082025f
Show file tree
Hide file tree
Showing 28 changed files with 3,379 additions and 3,957 deletions.
74 changes: 17 additions & 57 deletions .resinci.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,69 +17,29 @@
"copyright": "Copyright 2016-2019 Balena Ltd",
"productName": "balenaEtcher",
"nodeGypRebuild": true,
"afterPack": "./afterPack.js",
"files": [
"!node_modules/**/*.js.map",
"!node_modules/**/*.h",
"!node_modules/**/*.hpp",
"!node_modules/**/*.cpp",
"!node_modules/**/*.md",
"!node_modules/**/*.ts",
"!node_modules/**/*.coffee",
"!node_modules/**/*.scss",
"!node_modules/**/*.less",
"!node_modules/**/*.hbs",
"!node_modules/**/*.mkd",
"!node_modules/**/LICENSE",
"!node_modules/**/LICENCE",
"!node_modules/**/license",
"!node_modules/**/License",
"!node_modules/**/LICENSE.txt",
"!node_modules/**/Makefile",
"!node_modules/**/.editorconfig",
"!node_modules/**/.babelrc",
"!node_modules/**/.prettierrc",
"!node_modules/**/.prettierrc-*",
"!node_modules/**/.eslintrc.yml",
"!node_modules/**/.eslintignore",
"!node_modules/**/.publishrc",
"assets/icon.png",
"build/**/*.node",
"lib",
"!lib/gui/app",
"lib/gui/app/index.html",
"build/Release/elevator.node",
"generated",
"!node_modules/chart.js/dist/docs",
"!node_modules/ext2fs/config",
"!node_modules/ext2fs/deps",
"!node_modules/ext2fs/LICENSE",
"!node_modules/ext2fs/src",
"!node_modules/winusb-driver-generator/src",
"!node_modules/winusb-driver-generator/deps",
"!node_modules/winusb-driver-generator/ci",
"!node_modules/rendition/__screenshots__",
"!node_modules/polished/docs",
"!node_modules/mermaid/src",
"!node_modules/mermaid/dist",
"node_modules/mermaid/dist/mermaid.core.js",
"!node_modules/raven-js/src",
"!node_modules/raven-js/dist",
"node_modules/raven-js/dist/raven.js",
"!node_modules/raven-js/plugins",
"!node_modules/react-jsonschema-form/dist",
"!node_modules/xxhash/deps",
"!node_modules/xxhash/src",
"!node_modules/unzip-stream/testData*",
"!node_modules/usb",
"node_modules/usb/usb.js",
"node_modules/usb/package.json",
"node_modules/usb/build",
"node_modules/usb/src/binding",
"!node_modules/roboto-fontface/fonts",
"lib/shared/catalina-sudo/sudo-askpass.osascript.js",
"lib/gui/app/index.html",
"lib/gui/css/*.css",
"lib/gui/css/fonts/*.woff2",
"lib/gui/assets/*.svg",
"assets/icon.png",
"!node_modules/**/**",
"node_modules/**/*.js",
"node_modules/**/*.json",
"node_modules/**/*.node",
"node_modules/**/*.dll",
"node_modules/node-raspberrypi-usbboot/blobs/**",
"node_modules/flexboxgrid/dist/flexboxgrid.css",
"node_modules/roboto-fontface/fonts/roboto/Roboto-Thin.woff",
"node_modules/roboto-fontface/fonts/roboto/Roboto-Light.woff",
"node_modules/roboto-fontface/fonts/roboto/Roboto-Regular.woff",
"node_modules/roboto-fontface/fonts/roboto/Roboto-Medium.woff",
"node_modules/roboto-fontface/fonts/roboto/Roboto-Bold.woff"
"node_modules/roboto-fontface/fonts/roboto/Roboto-Bold.woff",
"node_modules/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2"
],
"afterSign": "./afterSignHook.js",
"mac": {
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,10 @@ test-spectron:
ETCHER_SPECTRON_ENTRYPOINT="$(ETCHER_SPECTRON_ENTRYPOINT)" mocha $(MOCHA_OPTIONS) tests/spectron

test-gui:
electron-mocha $(MOCHA_OPTIONS) --renderer tests/gui
electron-mocha $(MOCHA_OPTIONS) --full-trace --no-sandbox --renderer tests/gui

test-sdk:
electron-mocha $(MOCHA_OPTIONS) \
tests/shared
electron-mocha $(MOCHA_OPTIONS) --full-trace --no-sandbox tests/shared

test: test-gui test-sdk test-spectron

Expand Down
27 changes: 27 additions & 0 deletions afterPack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

const cp = require('child_process')
const fs = require('fs')
const outdent = require('outdent')
const path = require('path')

exports.default = function(context) {
if (context.packager.platform.name !== 'linux') {
return
}
const scriptPath = path.join(context.appOutDir, context.packager.executableName)
const binPath = scriptPath + '.bin'
cp.execFileSync('mv', [scriptPath, binPath])
fs.writeFileSync(
scriptPath,
outdent`
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
"\${BASH_SOURCE%/*}"/${context.packager.executableName}.bin "$@"
else
"\${BASH_SOURCE%/*}"/${context.packager.executableName}.bin "$@" --no-sandbox
fi
`
)
cp.execFileSync('chmod', ['+x', scriptPath])
}
24 changes: 20 additions & 4 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@ productName: balenaEtcher
npmRebuild: true
nodeGypRebuild: true
publish: null
afterPack: "./afterPack.js"
files:
- lib
- lib/gui/app/index.html
- build/Release/elevator.node
- generated
- build/**/*.node
- lib/shared/catalina-sudo/sudo-askpass.osascript.js
- lib/gui/app/index.html
- lib/gui/css/*.css
- lib/gui/css/fonts/*.woff2
- lib/gui/assets/*.svg
- assets/icon.png
- node_modules/**/*
- "!node_modules/**/**"
- "node_modules/**/*.js"
- "node_modules/**/*.json"
- "node_modules/**/*.node"
- "node_modules/**/*.dll"
- node_modules/node-raspberrypi-usbboot/blobs/**
- node_modules/flexboxgrid/dist/flexboxgrid.css
- node_modules/roboto-fontface/fonts/roboto/Roboto-Thin.woff
- node_modules/roboto-fontface/fonts/roboto/Roboto-Light.woff
- node_modules/roboto-fontface/fonts/roboto/Roboto-Regular.woff
- node_modules/roboto-fontface/fonts/roboto/Roboto-Medium.woff
- node_modules/roboto-fontface/fonts/roboto/Roboto-Bold.woff
- node_modules/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2
mac:
asar: false
icon: assets/icon.icns
Expand Down
21 changes: 0 additions & 21 deletions lib/gui/app/components/safe-webview/safe-webview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,6 @@ class SafeWebview extends react.PureComponent {
this.session.webRequest.onCompleted(null)
}

/**
* @summary Refresh the webview if we are navigating away from the success page
* @param {Object} nextProps - upcoming properties
*/
componentWillReceiveProps (nextProps) {
if (nextProps.refreshNow && !this.props.refreshNow) {
// Reload the page if it hasn't changed, otherwise reset the source URL,
// because reload interferes with 'src' setting, resetting the 'src' attribute
// to what it was was just prior.
if (this.refs.webview.src === this.entryHref) {
this.refs.webview.reload()
} else {
this.refs.webview.src = this.entryHref
}

this.setState({
shouldShow: true
})
}
}

/**
* @summary Set the element state to hidden
*/
Expand Down
10 changes: 9 additions & 1 deletion lib/gui/app/components/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,16 @@ interface SettingsModalProps {
toggleModal: (value: boolean) => void;
}

interface Dictionary<T> {
[key: string]: T;
}

export const SettingsModal: any = styled(
({ toggleModal }: SettingsModalProps) => {
const [currentSettings, setCurrentSettings] = useState(settings.getAll());
const [currentSettings, setCurrentSettings]: [
Dictionary<any>,
React.Dispatch<React.SetStateAction<Dictionary<any>>>,
] = useState(settings.getAll());
const [warning, setWarning]: [
any,
React.Dispatch<React.SetStateAction<any>>,
Expand All @@ -155,6 +162,7 @@ export const SettingsModal: any = styled(
setting,
value,
dangerous,
// @ts-ignore
applicationSessionUuid: store.getState().toJS().applicationSessionUuid,
});

Expand Down
9 changes: 0 additions & 9 deletions lib/gui/app/components/svg-icon/svg-icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,6 @@ class SVGIcon extends react.Component {
disabled: this.props.disabled
})
}

/**
* @summary Cause a re-render due to changed element properties
* @param {Object} nextProps - the new properties
*/
componentWillReceiveProps (nextProps) {
// This will update the element if the properties change
this.setState(nextProps)
}
}

SVGIcon.propTypes = {
Expand Down
5 changes: 2 additions & 3 deletions lib/gui/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
ng-class="{
isFinish: state.currentName === 'success'
}">
<safe-webview
src="'https://www.balena.io/etcher/success-banner/'"
refresh-now="state.previousName === 'success'"></safe-webview>
<safe-webview src="'https://www.balena.io/etcher/success-banner/'">
</safe-webview>
</div>
</body>
</html>
4 changes: 2 additions & 2 deletions lib/gui/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/
/*!
* Bootstrap v3.4.0 (https://getbootstrap.com/)
* Copyright 2011-2018 Twitter, Inc.
* Bootstrap v3.4.1 (https://getbootstrap.com/)
* Copyright 2011-2019 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */
Expand Down
4 changes: 3 additions & 1 deletion lib/gui/etcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ const createMainWindow = () => {
icon: path.join(__dirname, '..', '..', 'assets', 'icon.png'),
darkTheme: true,
webPreferences: {
backgroundThrottling: false
backgroundThrottling: false,
nodeIntegration: true,
webviewTag: true
}
})

Expand Down
4 changes: 2 additions & 2 deletions lib/shared/catalina-sudo/sudo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { execFile } = require('child_process')
const { env } = require('process')
const { env, resourcesPath } = require('process')
const { join } = require('path')
const { promisify } = require('util')

Expand All @@ -19,7 +19,7 @@ exports.sudo = async (command) => {
encoding: 'utf8',
env: {
PATH: env.PATH,
SUDO_ASKPASS: join(__dirname, 'sudo-askpass.osascript.js')
SUDO_ASKPASS: join(resourcesPath, 'app', __dirname, 'sudo-askpass.osascript.js')
}
}
)
Expand Down
41 changes: 0 additions & 41 deletions lib/shared/native-module.js

This file was deleted.

6 changes: 3 additions & 3 deletions lib/shared/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

'use strict'

const bindings = require('bindings')
const Bluebird = require('bluebird')
const childProcess = Bluebird.promisifyAll(require('child_process'))
const fs = require('fs')
Expand Down Expand Up @@ -136,10 +137,9 @@ exports.createLaunchScript = (command, argv, environment) => {
}

const elevateScriptWindows = async (path) => {
// './nativeModule' imported here as it only exists on windows
// 'elevator' imported here as it only exists on windows
// TODO: replace this with sudo-prompt once https://github.com/jorangreef/sudo-prompt/issues/96 is fixed
const nativeModule = require('./native-module')
const elevateAsync = promisify(nativeModule.load('elevator').elevate)
const elevateAsync = promisify(bindings({ bindings: 'elevator' }).elevate)

// '&' needs to be escaped here (but not when written to a .cmd file)
const cmd = [ 'cmd', '/c', escapeParamCmd(path).replace(/&/g, '^&') ]
Expand Down
9 changes: 3 additions & 6 deletions lib/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
// *won't* attempt to load the `app.asar` application by default, therefore
// if passing `ELECTRON_RUN_AS_NODE`, you have to pass the path to the asar
// or the entry point file (this file) manually as an argument.
//
// We also consider `ATOM_SHELL_INTERNAL_RUN_AS_NODE`, which is basically
// an older equivalent of `ELECTRON_RUN_AS_NODE` that still gets set when
// using `child_process.fork()`.
if (process.env.ELECTRON_RUN_AS_NODE || process.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE) {

if (process.env.ELECTRON_RUN_AS_NODE) {
require('./gui/modules/child-writer')
} else {
require('../generated/etcher')
require('./gui/etcher')
}
Loading

0 comments on commit 082025f

Please sign in to comment.