Permalink
Browse files

Use uppercase env vars but support old lowercase usage

  • Loading branch information...
pfrazee committed May 21, 2018
1 parent aeef5ea commit 4992d6fa1aab3323226878d7859fc255a7a64674
@@ -119,9 +119,9 @@ Looking to work on Beaker? [Watch this video](https://www.youtube.com/watch?v=Yu
### Env Vars
- `DEBUG`: which log systems to output? A comma-separated string. Can be `beaker`, `dat`, `bittorrent-dht`, `dns-discovery`, `hypercore-protocol`. Specify `*` for all.
- `beaker_open_url`: open the given URL on load, rather than the previous session or default tab.
- `beaker_user_data_path`: override the user-data path, therefore changing where data is read/written. Useful for testing. For default value see `userData` in the [electron docs](https://electron.atom.io/docs/api/app/#appgetpathname).
- `beaker_dat_quota_default_bytes_allowed`: override the default max-quota for bytes allowed to be written by a dat site. Useful for testing. Default value is `'500mb'`. This can be a Number or a String. Check [bytes.parse](https://github.com/visionmedia/bytes.js/tree/a4b9af2bf289175f12b3538eb172f2489844b1ec#bytesparsestringnumber-value-numbernull) for supported units and abbreviations.
- `BEAKER_OPEN_URL`: open the given URL on load, rather than the previous session or default tab.
- `BEAKER_USER_DATA_PATH`: override the user-data path, therefore changing where data is read/written. Useful for testing. For default value see `userData` in the [electron docs](https://electron.atom.io/docs/api/app/#appgetpathname).
- `BEAKER_DAT_QUOTA_DEFAULT_BYTES_ALLOWED`: override the default max-quota for bytes allowed to be written by a dat site. Useful for testing. Default value is `'500mb'`. This can be a Number or a String. Check [bytes.parse](https://github.com/visionmedia/bytes.js/tree/a4b9af2bf289175f12b3538eb172f2489844b1ec#bytesparsestringnumber-value-numbernull) for supported units and abbreviations.
## Known issues
@@ -6,7 +6,8 @@ import setupDebugLogger from './background-process/debug-logger'
// It doesn't have any windows which you can see on screen, but we can open
// window from here.
import { app, protocol } from 'electron'
import {app, protocol} from 'electron'
import {getEnvVar} from './lib/electron'
import * as beakerBrowser from './background-process/browser'
import * as webAPIs from './background-process/web-apis'
@@ -38,12 +39,12 @@ import * as openURL from './background-process/open-url'
// read config from env vars
setupDebugLogger()
if (process.env.beaker_user_data_path) {
if (getEnvVar('BEAKER_USER_DATA_PATH')) {
console.log('User data path set by environment variables')
console.log('userData:', process.env.beaker_user_data_path)
app.setPath('userData', process.env.beaker_user_data_path)
console.log('userData:', getEnvVar('BEAKER_USER_DATA_PATH'))
app.setPath('userData', getEnvVar('BEAKER_USER_DATA_PATH'))
}
if (process.env.BEAKER_TEST_DRIVER) {
if (getEnvVar('BEAKER_TEST_DRIVER')) {
testDriver.setup()
}
@@ -15,6 +15,7 @@ import {showModal, showShellModal, closeModal} from './ui/modals'
import {
INVALID_SAVE_FOLDER_CHAR_REGEX
} from '../lib/const'
import {getEnvVar} from '../lib/electron'
// constants
// =
@@ -346,7 +347,7 @@ function showContextMenu (menuDefinition) {
}
// add 'inspect element' in development
if (process.env.NODE_ENV === 'develop' || process.env.NODE_ENV === 'test') {
if (getEnvVar('NODE_ENV') === 'develop' || getEnvVar('NODE_ENV') === 'test') {
menuDefinition.push({type: 'separator'})
menuDefinition.push({
label: 'Inspect Element',
@@ -1,8 +1,9 @@
import { app } from 'electron'
import {app} from 'electron'
import sqlite3 from 'sqlite3'
import path from 'path'
import { cbPromise } from '../../lib/functions'
import { setupSqliteDB } from '../../lib/bg/db'
import {cbPromise} from '../../lib/functions'
import {setupSqliteDB} from '../../lib/bg/db'
import {getEnvVar} from '../../lib/electron'
// globals
// =
@@ -42,7 +43,7 @@ export function set (key, value) {
export function get (key) {
// env variables
if (key === 'no_welcome_tab') {
return (process.env.beaker_no_welcome_tab == 1)
return (getEnvVar('BEAKER_NO_WELCOME_TAB') == 1)
}
// stored values
return setupPromise.then(v => cbPromise(cb => {
@@ -62,7 +63,7 @@ export function getAll () {
var obj = {}
rows.forEach(row => { obj[row.key] = row.value })
obj = Object.assign({}, DEFAULT_SETTINGS, obj)
obj.no_welcome_tab = (process.env.beaker_no_welcome_tab == 1)
obj.no_welcome_tab = (getEnvVar('BEAKER_NO_WELCOME_TAB') == 1)
cb(null, obj)
})
}))
@@ -4,16 +4,17 @@ import fs from 'fs'
import concat from 'concat-stream'
import {join as joinPath} from 'path'
import {format} from 'util'
import {getEnvVar} from '../lib/electron'
var logFilePath
var logFileWriteStream
export default function setup () {
if (process.env.DEBUG) {
if (getEnvVar('DEBUG')) {
return // abort, user is capturing debug to the console
}
let folderPath = process.env.beaker_user_data_path || app.getPath('userData')
let folderPath = getEnvVar('BEAKER_USER_DATA_PATH') || app.getPath('userData')
logFilePath = joinPath(folderPath, 'debug.log')
console.log('Logfile:', logFilePath)
debug.enable('dat,datgc,dat-dns,dat-serve,dns-discovery,discovery-channel,discovery-swarm,beaker,beaker-sqlite,beaker-analytics')
@@ -9,6 +9,7 @@ import * as openURL from '../open-url'
import * as downloads from './downloads'
import * as permissions from './permissions'
import * as settingsDb from '../dbs/settings'
import {getEnvVar} from '../../lib/electron'
const IS_WIN = process.platform === 'win32'
@@ -89,8 +90,8 @@ export async function setup () {
let previousSessionState = getPreviousBrowsingSession()
sessionWatcher = new SessionWatcher(userDataDir)
let customStartPage = await settingsDb.get('custom_start_page')
let isTestDriverActive = !!process.env.BEAKER_TEST_DRIVER
let isOpenUrlEnvVar = !!process.env.beaker_open_url
let isTestDriverActive = !!getEnvVar('BEAKER_TEST_DRIVER')
let isOpenUrlEnvVar = !!getEnvVar('BEAKER_OPEN_URL')
if (!isTestDriverActive && !isOpenUrlEnvVar && (customStartPage === 'previous' || !previousSessionState.cleanExit && userWantsToRestoreSession())) {
// restore old window
@@ -107,7 +108,7 @@ export async function setup () {
}
if (isOpenUrlEnvVar) {
// use the env var if specified
opts.pages = [process.env.beaker_open_url]
opts.pages = [getEnvVar('BEAKER_OPEN_URL')]
}
// create new window
createShellWindow(opts)
@@ -17,7 +17,8 @@ export const INVALID_SAVE_FOLDER_CHAR_REGEX = /[^0-9a-zA-Z-_ ]/g
// dat settings
export const DAT_SWARM_PORT = 3282
export const DAT_MANIFEST_FILENAME = 'dat.json'
export const DAT_QUOTA_DEFAULT_BYTES_ALLOWED = bytes.parse(process.env.beaker_dat_quota_default_bytes_allowed || '500mb')
let quotaEnvVar = process.env.BEAKER_DAT_QUOTA_DEFAULT_BYTES_ALLOWED || process.env.beaker_dat_quota_default_bytes_allowed
export const DAT_QUOTA_DEFAULT_BYTES_ALLOWED = bytes.parse(quotaEnvVar || '500mb')
export const DEFAULT_DAT_DNS_TTL = ms('1h')
export const MAX_DAT_DNS_TTL = ms('7d')
export const DEFAULT_DAT_API_TIMEOUT = ms('5s')
@@ -6,3 +6,15 @@ export function getWebContentsWindow (wc) {
}
return BrowserWindow.fromWebContents(wc)
}
export function getEnvVar (name) {
var ucv = process.env[name.toUpperCase()]
if (typeof ucv !== 'undefined') {
return ucv
}
var lcv = process.env[name.toLowerCase()]
if (typeof lcv !== 'undefined') {
return lcv
}
return undefined
}

0 comments on commit 4992d6f

Please sign in to comment.