Skip to content

Commit

Permalink
Merge branch 'master' into dorianscholz/electron-fslibre
Browse files Browse the repository at this point in the history
  • Loading branch information
gniezen authored Oct 19, 2017
2 parents ba7afc4 + c85cd04 commit 5b8b770
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 136 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@ For ease of development we have several debug features that developers can turn

The environment variable `DEBUG_ERROR` (boolean) controls whether or not errors sourced in device drivers are caught and an error message displayed in the UI (the production setting) or whether they are thrown in the console (much more useful for local development because then the file name and line number of the error are easily accessible, along with a stack trace). `DEBUG_ERROR` mode is turned on by default in `config/device-debug.sh`.

#### `REDUX_LOG`

The environment variable `REDUX_LOG` (boolean) controls whether or not the [redux logger middleware](https://github.com/fcomb/redux-logger/blob/master/README.md) is included. This middleware logs all redux actions in the Chrome developer console, including the (entire) previous and following app state trees. It is primarily useful when working on the UI of the app, and in fact can be quite performance-expensive (especially when uploading a device, due to the fact that every update to the progress bar constitutes an action), so it is not recommended to turn it on while working on device code.


`REDUX_LOG` is turned on by default in `config/ui-debug.sh`.

As an alternative to using `REDUX_LOG`, the Electron uploader now includes the Redux DevTools. See [DevTools](#devtools) below for more details.
This can also be toggled internally in the running Electron app via a right-click context menu available on the login screen, much like the menu for switching environments.

### Local Development w/o Debug Mode(s)

Expand Down
7 changes: 3 additions & 4 deletions app/components/Upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* == BSD2 LICENSE ==
*/

/* global __DEBUG__ */

import _ from 'lodash';
import cx from 'classnames';
import React, { Component, PropTypes } from 'react';
Expand All @@ -26,6 +24,7 @@ import keytar from 'keytar';

import LoadingBar from './LoadingBar';
import ProgressBar from './ProgressBar';
import debugMode from '../utils/debugMode';

import styles from '../../styles/components/Upload.module.less';

Expand Down Expand Up @@ -562,15 +561,15 @@ export default class Upload extends Component {

if (upload.successful) {
let dataDownloadLink = null;
if (__DEBUG__ && !_.isEmpty(this.props.upload.data)) {
if (debugMode.isDebug && !_.isEmpty(this.props.upload.data)) {
dataDownloadLink = this.getDebugLinks(this.props.upload.data);
}
return <div className={styles.status}>{this.props.text.UPLOAD_COMPLETE}&nbsp;{dataDownloadLink}</div>;
}

if(upload.failed) {
let dataDownloadLink = null;
if (__DEBUG__ && this.props.upload.error.data) {
if (debugMode.isDebug && this.props.upload.error.data) {
dataDownloadLink = this.getDebugLinks(this.props.upload.error.data);
}
return <div className={styles.status}>{dataDownloadLink}</div>;
Expand Down
104 changes: 64 additions & 40 deletions app/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { bindActionCreators } from 'redux';
import { remote } from 'electron';
import * as metrics from '../constants/metrics';

const {Menu} = remote;
const { Menu } = remote;

import bows from 'bows';

Expand All @@ -39,6 +39,7 @@ const syncActions = actions.sync;
import * as actionSources from '../constants/actionSources';
import { pages, urls, pagesMap } from '../constants/otherConstants';
import { checkVersion } from '../utils/drivers';
import debugMode from '../utils/debugMode';

import UpdatePlease from '../components/UpdatePlease';
import VersionCheckError from '../components/VersionCheckError';
Expand All @@ -49,6 +50,39 @@ import UpdateDriverModal from '../components/UpdateDriverModal';

import styles from '../../styles/components/App.module.less';

const serverdata = {
Local: {
API_URL: 'http://localhost:8009',
UPLOAD_URL: 'http://localhost:9122',
DATA_URL: 'http://localhost:8077',
BLIP_URL: 'http://localhost:3000'
},
Development: {
API_URL: 'https://dev-api.tidepool.org',
UPLOAD_URL: 'https://dev-uploads.tidepool.org',
DATA_URL: 'https://dev-api.tidepool.org/dataservices',
BLIP_URL: 'https://dev-blip.tidepool.org'
},
Staging: {
API_URL: 'https://stg-api.tidepool.org',
UPLOAD_URL: 'https://stg-uploads.tidepool.org',
DATA_URL: 'https://stg-api.tidepool.org/dataservices',
BLIP_URL: 'https://stg-blip.tidepool.org'
},
Integration: {
API_URL: 'https://int-api.tidepool.org',
UPLOAD_URL: 'https://int-uploads.tidepool.org',
DATA_URL: 'https://int-api.tidepool.org/dataservices',
BLIP_URL: 'https://int-blip.tidepool.org'
},
Production: {
API_URL: 'https://api.tidepool.org',
UPLOAD_URL: 'https://uploads.tidepool.org',
DATA_URL: 'https://api.tidepool.org/dataservices',
BLIP_URL: 'https://blip.tidepool.org'
}
};

export class App extends Component {
static propTypes = {
route: PropTypes.shape({
Expand All @@ -62,6 +96,10 @@ export class App extends Component {
this.handleDismissDropdown = this.handleDismissDropdown.bind(this);
this.handleContextMenu = this.handleContextMenu.bind(this);
this.setServer = this.setServer.bind(this);
const initial_server = _.findKey(serverdata, (key) => key.API_URL === config.API_URL);
this.state = {
server: initial_server
};
}

componentWillMount(){
Expand All @@ -79,42 +117,10 @@ export class App extends Component {
}

setServer(info) {
var serverdata = {
Local: {
API_URL: 'http://localhost:8009',
UPLOAD_URL: 'http://localhost:9122',
DATA_URL: 'http://localhost:8077',
BLIP_URL: 'http://localhost:3000'
},
Development: {
API_URL: 'https://dev-api.tidepool.org',
UPLOAD_URL: 'https://dev-uploads.tidepool.org',
DATA_URL: 'https://dev-api.tidepool.org/dataservices',
BLIP_URL: 'https://dev-blip.tidepool.org'
},
Staging: {
API_URL: 'https://stg-api.tidepool.org',
UPLOAD_URL: 'https://stg-uploads.tidepool.org',
DATA_URL: 'https://stg-api.tidepool.org/dataservices',
BLIP_URL: 'https://stg-blip.tidepool.org'
},
Integration: {
API_URL: 'https://int-api.tidepool.org',
UPLOAD_URL: 'https://int-uploads.tidepool.org',
DATA_URL: 'https://int-api.tidepool.org/dataservices',
BLIP_URL: 'https://int-blip.tidepool.org'
},
Production: {
API_URL: 'https://api.tidepool.org',
UPLOAD_URL: 'https://uploads.tidepool.org',
DATA_URL: 'https://api.tidepool.org/dataservices',
BLIP_URL: 'https://blip.tidepool.org'
}
};

console.log('will use', info.label, 'server');
var serverinfo = serverdata[info.label];
this.props.route.api.setHosts(serverinfo);
this.setState({server: info.label});
}

render() {
Expand All @@ -135,7 +141,7 @@ export class App extends Component {
e.preventDefault();
const { clientX, clientY } = e;
let template = [];
if (process.env.NODE_ENV === 'development' || process.env.BUILD === 'dev' ) {
if (process.env.NODE_ENV === 'development') {
template.push({
label: 'Inspect element',
click() {
Expand All @@ -152,26 +158,44 @@ export class App extends Component {
submenu: [
{
label: 'Local',
click: this.setServer
click: this.setServer,
type: 'radio',
checked: this.state.server === 'Local'
},
{
label: 'Development',
click: this.setServer
click: this.setServer,
type: 'radio',
checked: this.state.server === 'Development'
},
{
label: 'Staging',
click: this.setServer
click: this.setServer,
type: 'radio',
checked: this.state.server === 'Staging'
},
{
label: 'Integration',
click: this.setServer
click: this.setServer,
type: 'radio',
checked: this.state.server === 'Integration'
},
{
label: 'Production',
click: this.setServer
click: this.setServer,
type: 'radio',
checked: this.state.server === 'Production'
}
]
});
template.push({
label: 'Toggle Debug Mode',
type: 'checkbox',
checked: debugMode.isDebug,
click() {
debugMode.setDebug(!debugMode.isDebug);
}
});
}
const menu = Menu.buildFromTemplate(template);
menu.popup(remote.getCurrentWindow());
Expand Down
14 changes: 7 additions & 7 deletions app/main.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import open from 'open';
import { autoUpdater } from 'electron-updater';
import * as chromeFinder from 'chrome-launcher/chrome-finder';
import { sync as syncActions } from './actions';
import debugMode from '../app/utils/debugMode';

let menu;
let template;
Expand Down Expand Up @@ -47,7 +48,7 @@ const installExtensions = async () => {

app.on('ready', async () => {
await installExtensions();
const resizable = (process.env.NODE_ENV === 'development' || process.env.BUILD === 'dev');
const resizable = (process.env.NODE_ENV === 'development');

mainWindow = new BrowserWindow({
show: false,
Expand Down Expand Up @@ -88,7 +89,7 @@ app.on('ready', async () => {
mainWindow = null;
});

if (process.env.NODE_ENV === 'development' || process.env.BUILD === 'dev') {
if (process.env.NODE_ENV === 'development') {
mainWindow.openDevTools();
mainWindow.webContents.on('context-menu', (e, props) => {
const { x, y } = props;
Expand Down Expand Up @@ -167,7 +168,7 @@ app.on('ready', async () => {
}]
}, {
label: 'View',
submenu: (process.env.NODE_ENV === 'development' || process.env.BUILD === 'dev') ?
submenu: (process.env.NODE_ENV === 'development') ?
[
{
label: 'Reload',
Expand Down Expand Up @@ -256,7 +257,7 @@ app.on('ready', async () => {
}]
}, {
label: '&View',
submenu: (process.env.NODE_ENV === 'development' || process.env.BUILD === 'dev') ? [{
submenu: (process.env.NODE_ENV === 'development') ? [{
label: '&Reload',
accelerator: 'Ctrl+R',
click() {
Expand Down Expand Up @@ -318,10 +319,9 @@ app.on('ready', async () => {
});

function checkUpdates(){
// in production NODE_ENV or *any* type of BUILD (including BUILD === 'dev')
// we check for updates, but not if NODE_ENV is 'development' and BUILD is unset
// in production NODE_ENV we check for updates, but not if NODE_ENV is 'development'
// this prevents a Webpack build error that masks other build errors during local development
if (process.env.NODE_ENV === 'production' || process.env.BUILD) {
if (process.env.NODE_ENV === 'production') {
autoUpdater.checkForUpdates();
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tidepool-uploader",
"productName": "tidepool-uploader",
"version": "2.0.2",
"version": "2.0.3",
"description": "Tidepool Project Universal Uploader",
"main": "./main.js",
"author": {
Expand Down
18 changes: 0 additions & 18 deletions app/store/configureStore.development.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,27 @@
/* global __REDUX_LOG__ */

import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import { hashHistory } from 'react-router';
import { routerMiddleware, push } from 'react-router-redux';
import { createLogger } from 'redux-logger';
import rootReducer from '../reducers';
import { async, sync } from '../actions';
import api from '../../lib/core/api';
import config from '../../lib/config';
import { createErrorLogger } from '../utils/errors';
import { createMetricsTracker } from '../utils/metrics';


api.create({
apiUrl: config.API_URL,
uploadUrl: config.UPLOAD_URL,
dataUrl: config.DATA_URL,
version: config.version
});

const noop = function(middlewareAPI){
return function(next){
return function(action){
return next(action);
};
};
};

const actionCreators = {
...async,
...sync,
push,
};

const logger = __REDUX_LOG__ ? createLogger({
level: 'info',
collapsed: true
}) : noop;

const router = routerMiddleware(hashHistory);

// If Redux DevTools Extension is installed use it, otherwise use Redux compose
Expand All @@ -54,7 +37,6 @@ const enhancer = composeEnhancers(
applyMiddleware(
thunk,
router,
logger,
createErrorLogger(api),
createMetricsTracker(api)
)
Expand Down
49 changes: 49 additions & 0 deletions app/utils/debugMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* == BSD2 LICENSE ==
* Copyright (c) 2017, Tidepool Project
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the associated License, which is identical to the BSD 2-Clause
* License as published by the Open Source Initiative at opensource.org.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the License for more details.
*
* You should have received a copy of the License along with this program; if
* not, you can obtain one from Tidepool Project at tidepool.org.
* == BSD2 LICENSE ==
*/

import { ipcRenderer, ipcMain } from 'electron';
let isRenderer = (process && process.type === 'renderer');

if (isRenderer) {
let isDebug = process.env.DEBUG_ERROR ||
JSON.parse(localStorage.getItem('isDebug')) ||
false;

const debugMode = module.exports = {
isDebug,
setDebug: function(isDebug) {
ipcRenderer.send('setDebug', isDebug);
localStorage.setItem('isDebug', JSON.stringify(isDebug));
debugMode.isDebug = isDebug;
return debugMode.isDebug;
}
};
} else {
let isDebug = process.env.DEBUG_ERROR || false;

ipcMain.on('setDebug', (event, arg) => {
debugMode.isDebug = arg;
});

const debugMode = module.exports = {
isDebug,
setDebug: function(isDebug) {
debugMode.isDebug = isDebug;
return debugMode.isDebug;
}
};
}
Loading

0 comments on commit 5b8b770

Please sign in to comment.