chore(app): Use settings instead of env vars

Change-Type: patch
This commit is contained in:
Jonas Hermsmeier 2018-05-25 23:00:47 +02:00
parent 6728382141
commit c08cf61d0c
No known key found for this signature in database
GPG Key ID: 1B870F801A0CEE9F
14 changed files with 47 additions and 25 deletions

View File

@ -64,9 +64,7 @@ window.localStorage.debug = process.env.DEBUG
* @constant
* @private
*/
const BLACKLISTED_DRIVES = process.env.ETCHER_BLACKLISTED_DRIVES
? process.env.ETCHER_BLACKLISTED_DRIVES.split(',')
: []
const BLACKLISTED_DRIVES = settings.get('driveBlacklist')
const app = angular.module('Etcher', [
require('angular-ui-router'),
@ -362,7 +360,7 @@ app.controller('HeaderController', function (OSOpenExternalService) {
* HeaderController.shouldShowHelp()
*/
this.shouldShowHelp = () => {
return !process.env.ETCHER_DISABLE_EXTERNAL_LINKS
return !settings.get('disableExternalLinks')
}
})

View File

@ -16,6 +16,8 @@
'use strict'
const settings = require('../../../models/settings')
module.exports = function (
$uibModalInstance
) {
@ -43,6 +45,7 @@ module.exports = function (
*/
this.getFolderConstraint = () => {
// TODO(Shou): get this dynamically from the mountpoint of a specific port in Etcher Pro
return process.env.ETCHER_FILE_BROWSER_CONSTRAIN_FOLDER
// TODO: Make this handle multiple constraints
return settings.get('fileBrowserConstraintPath')
}
}

View File

@ -25,6 +25,7 @@ const react = require('react')
const propTypes = require('prop-types')
const { react2angular } = require('react2angular')
const analytics = require('../modules/analytics')
const settings = require('../models/settings')
const packageJSON = require('../../../../package.json')
const MODULE_NAME = 'Etcher.Components.SafeWebview'
@ -217,7 +218,7 @@ class SafeWebview extends react.PureComponent {
event.disposition === 'foreground-tab',
// Don't open links if they're disabled by the env var
!process.env.ETCHER_DISABLE_EXTERNAL_LINKS
!settings.get('disableExternalLinks')
])) {
electron.shell.openExternal(url.href)
}

View File

@ -62,7 +62,7 @@ const currentWindow = electron.remote.getCurrentWindow()
* }
*/
exports.shouldCheckForUpdates = (options) => {
if (process.env.ELECTRON_RESIN_UPDATE_LOCK) {
if (settings.get('resinUpdateLock')) {
return false
}

View File

@ -79,8 +79,8 @@ const readConfigFile = (filename) => {
} else {
try {
data = JSON.parse(contents)
} catch(e) {
// ignore (?)
} catch (parseError) {
// Ignore (?)
}
resolve(data)
}

View File

@ -184,6 +184,22 @@ exports.get = (key) => {
return _.cloneDeep(_.get(settings, [ key ]))
}
/**
* @summary Check if setting value exists
* @function
* @public
*
* @param {String} key - setting key
* @returns {Boolean} exists
*
* @example
* const hasValue = settings.has('unmountOnSuccess');
*/
exports.has = (key) => {
/* eslint-disable no-eq-null */
return settings[key] != null
}
/**
* @summary Get all setting values
* @function

View File

@ -25,6 +25,7 @@ const supportedFormats = require('../../../shared/supported-formats')
const errors = require('../../../shared/errors')
const fileExtensions = require('../../../shared/file-extensions')
const utils = require('../../../shared/utils')
const settings = require('./settings')
/**
* @summary Verify and throw if any state fields are nil
@ -184,7 +185,7 @@ const storeReducer = (state = DEFAULT_STATE, action) => {
return accState
}, newState)
const shouldAutoselectAll = Boolean(process.env.ETCHER_DISABLE_EXPLICIT_DRIVE_SELECTION)
const shouldAutoselectAll = Boolean(settings.get('disableExplicitDriveSelection'))
const AUTOSELECT_DRIVE_COUNT = 1
const nonStaleSelectedDevices = nonStaleNewState.getIn([ 'selection', 'devices' ]).toJS()
const hasSelectedDevices = nonStaleSelectedDevices.length >= AUTOSELECT_DRIVE_COUNT

View File

@ -23,9 +23,9 @@ const settings = require('../models/settings')
resinCorvus.install({
services: {
sentry: process.env.ANALYTICS_SENTRY_TOKEN ||
sentry: settings.get('analyticsSentryToken') ||
_.get(packageJSON, [ 'analytics', 'sentry', 'token' ]),
mixpanel: process.env.ANALYTICS_MIXPANEL_TOKEN ||
mixpanel: settings.get('analyticsMixpanelToken') ||
_.get(packageJSON, [ 'analytics', 'mixpanel', 'token' ])
},
options: {

View File

@ -23,7 +23,7 @@ const permissions = require('../../../shared/permissions')
const scanner = SDK.createScanner({
blockdevice: {
get includeSystemDrives () {
return settings.get('unsafeMode') && !process.env.ETCHER_HIDE_UNSAFE_MODE
return settings.get('unsafeMode') && !settings.get('disableUnsafeMode')
}
},
usbboot: {}

View File

@ -21,6 +21,7 @@ const EventEmitter = require('events')
const createInactivityTimer = require('inactivity-timer')
const debug = require('debug')('etcher:update-lock')
const analytics = require('./analytics')
const settings = require('../models/settings')
/* eslint-disable no-magic-numbers, callback-return */
@ -29,8 +30,8 @@ const analytics = require('./analytics')
* @type {Number}
* @constant
*/
const INTERACTION_TIMEOUT_MS = process.env.ETCHER_INTERACTION_TIMEOUT_MS
? parseInt(process.env.ETCHER_INTERACTION_TIMEOUT_MS, 10)
const INTERACTION_TIMEOUT_MS = settings.has('interactionTimeout')
? parseInt(settings.get('interactionTimeout'), 10)
: 5 * 60 * 1000
/**
@ -60,7 +61,7 @@ class UpdateLock extends EventEmitter {
* this.on('inactive', onInactive)
*/
static onInactive () {
if (process.env.ELECTRON_RESIN_UPDATE_LOCK) {
if (settings.get('resinUpdateLock')) {
UpdateLock.check((checkError, isLocked) => {
debug('inactive-check', Boolean(checkError))
if (checkError) {
@ -89,7 +90,7 @@ class UpdateLock extends EventEmitter {
*/
static acquire (callback) {
debug('lock')
if (process.env.ELECTRON_RESIN_UPDATE_LOCK) {
if (settings.get('resinUpdateLock')) {
electron.ipcRenderer.once('resin-update-lock', (event, error) => {
callback(error)
})
@ -110,7 +111,7 @@ class UpdateLock extends EventEmitter {
*/
static release (callback) {
debug('unlock')
if (process.env.ELECTRON_RESIN_UPDATE_LOCK) {
if (settings.get('resinUpdateLock')) {
electron.ipcRenderer.once('resin-update-lock', (event, error) => {
callback(error)
})
@ -133,7 +134,7 @@ class UpdateLock extends EventEmitter {
*/
static check (callback) {
debug('check')
if (process.env.ELECTRON_RESIN_UPDATE_LOCK) {
if (settings.get('resinUpdateLock')) {
electron.ipcRenderer.once('resin-update-lock', (event, error, isLocked) => {
callback(error, isLocked)
})
@ -160,7 +161,7 @@ class UpdateLock extends EventEmitter {
// When extending, check that we have the lock,
// and acquire it, if not
if (process.env.ELECTRON_RESIN_UPDATE_LOCK) {
if (settings.get('resinUpdateLock')) {
UpdateLock.check((checkError, isLocked) => {
if (checkError) {
analytics.logException(checkError)

View File

@ -18,6 +18,7 @@
const electron = require('electron')
const analytics = require('../../../modules/analytics')
const settings = require('../../../models/settings')
module.exports = function () {
/**
@ -32,7 +33,7 @@ module.exports = function () {
*/
this.open = (url) => {
// Don't open links if they're disabled by the env var
if (process.env.ETCHER_DISABLE_EXTERNAL_LINKS) {
if (settings.get('disableExternalLinks')) {
return
}

View File

@ -109,7 +109,7 @@ module.exports = function (DriveSelectorService) {
analytics.logEvent('Select drive', {
device: drive.device,
unsafeMode: settings.get('unsafeMode') && !process.env.ETCHER_HIDE_UNSAFE_MODE
unsafeMode: settings.get('unsafeMode') && !settings.get('disableUnsafeMode')
})
}).catch(exceptionReporter.report)
}
@ -148,6 +148,6 @@ module.exports = function (DriveSelectorService) {
* DriveSelectionController.shouldShowDrivesButton()
*/
this.shouldShowDrivesButton = () => {
return !process.env.ETCHER_DISABLE_EXPLICIT_DRIVE_SELECTION
return !settings.get('disableExplicitDriveSelection')
}
}

View File

@ -24,6 +24,7 @@ const errors = require('../../../../../shared/errors')
const imageStream = require('../../../../../sdk/image-stream')
const supportedFormats = require('../../../../../shared/supported-formats')
const analytics = require('../../../modules/analytics')
const settings = require('../../../models/settings')
const selectionState = require('../../../models/selection-state')
const osDialog = require('../../../os/dialog')
const exceptionReporter = require('../../../modules/exception-reporter')
@ -156,7 +157,7 @@ module.exports = function (
this.openImageSelector = () => {
analytics.logEvent('Open image selector')
if (process.env.ETCHER_EXPERIMENTAL_FILE_PICKER) {
if (settings.get('experimentalFilePicker')) {
FileSelectorService.open()
} else {
osDialog.selectImage().then((imagePath) => {

View File

@ -116,6 +116,6 @@ module.exports = function (WarningModalService) {
* SettingsController.shouldShowUnsafeMode()
*/
this.shouldShowUnsafeMode = () => {
return !process.env.ETCHER_HIDE_UNSAFE_MODE
return !settings.get('disableUnsafeMode')
}
}