Skip to content

Commit

Permalink
Merge branch 'release/3.0.0-rc.3'
Browse files Browse the repository at this point in the history
* release/3.0.0-rc.3:
  Bump version number
  Put the anomalous results first in the list
  Fixup seconds suffix in translations
  Cast the input value to int
  Add copy-paste support
  Unify logging and add logging to several places
  Remove unused dialog code
  Use async/await for better readability
  Add validation when setting website_url_limit config
  Add minimal website test count box
  Add support for displaying the ETA estimate
  Bump probe-cli version
  • Loading branch information
hellais committed Nov 15, 2019
2 parents 815df2b + dc93859 commit e4f8747
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 75 deletions.
4 changes: 2 additions & 2 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"Dashboard.Overview.ChooseWebsites": "Choose websites",
"Dashboard.Running.Running": "Running:",
"Dashboard.Running.EstimatedTimeLeft": "Estimated time left:",
"Dashboard.Running.Seconds": "{seconds} seconds",
"Dashboard.Running.Seconds": "{seconds}",
"Dashboard.Running.PreparingTest": "Preparing test",
"Dashboard.Running.ShowLog": "Show Log",
"Dashboard.Running.CloseLog": "Close Log",
Expand Down Expand Up @@ -385,4 +385,4 @@
"CategoryCode.CTRL.Description": "Benign or innocuous content used for control",
"CategoryCode.IGO.Description": "Intergovernmental organizations including The United Nations",
"CategoryCode.MISC.Description": "Sites that haven't been categorized yet"
}
}
7 changes: 5 additions & 2 deletions main/actions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* global require, module */
const { Ooniprobe } = require('./utils/ooni/ooniprobe')

const log = require('electron-log')
const debug = require('debug')('ooniprobe-desktop.main.actions')

const hardReset = () => {
const ooni = new Ooniprobe()
log.info('hardReset: performing a hard reset of the installation')
return ooni.call(['reset', '--force'])
}

Expand All @@ -17,8 +19,8 @@ const listMeasurements = (resultID) => {
return new Promise((resolve, reject) => {
ooni.on('data', (data) => {
if (data.level === 'error') {
log.error('listMeasurements: error in row', data.message)
errors.push(data.message)
debug('error in row', data.message)
return
}
switch(data.fields.type) {
Expand Down Expand Up @@ -56,7 +58,7 @@ const listResults = () => {
return new Promise((resolve, reject) => {
ooni.on('data', (data) => {
if (data.level === 'error') {
debug('error: ', data.message)
log.error('listResults: error in row', data.message)
reject(data.message)
return
}
Expand Down Expand Up @@ -108,6 +110,7 @@ const showMeasurement = (msmtID) => {
measurement = data.fields.measurement_json
break
default:
log.error('showMeasurement: extra data.fields', data.fields)
debug('extra data.fields', data.fields)
}
})
Expand Down
33 changes: 0 additions & 33 deletions main/dialogs.js

This file was deleted.

16 changes: 14 additions & 2 deletions main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,26 @@ if (!isDev && firstRun()) {
}
*/

const editMenu = {
label: 'Edit',
submenu: [
{ label: 'Undo', accelerator: 'CmdOrCtrl+Z', selector: 'undo:' },
{ label: 'Redo', accelerator: 'Shift+CmdOrCtrl+Z', selector: 'redo:' },
{ type: 'separator' },
{ label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'cut:' },
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
{ label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:' },
{ label: 'Select All', accelerator: 'CmdOrCtrl+A', selector: 'selectAll:' }
]
}

let menuTemplate = [
{
label: 'About',
submenu: [
{ label: 'About OONI Probe', click: () => openAboutWindow() },
]
}
}, editMenu
]
if (is.macos) {
menuTemplate = [
Expand All @@ -82,7 +94,7 @@ if (is.macos) {
{ type: 'separator' },
{ role: 'quit' }
]
}
}, editMenu
]
}

Expand Down
3 changes: 3 additions & 0 deletions main/utils/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global require, module */
const path = require('path')
const fs = require('fs-extra')
const log = require('electron-log')

const { getHomeDir } = require('./paths')

Expand All @@ -26,6 +27,8 @@ const setConfig = async (optionKey, currentValue, newValue) => {
// via probe-cli.
const currentOldValue = optionKey.split('.').reduce((o,i) => o[i], config)
if (currentOldValue !== currentValue) {
log.info('setConfig: config file path', OONI_CONFIG_PATH)
log.error('setConfig: inconsistent config file', currentOldValue, currentValue)
throw Error('inconsistent config file')
}
setIndex(config, optionKey, newValue)
Expand Down
2 changes: 1 addition & 1 deletion main/utils/ooni/onboard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global windows */
/* global module, require */
const { Ooniprobe } = require('./ooniprobe')

module.exports = async () => {
Expand Down
19 changes: 9 additions & 10 deletions main/utils/ooni/ooniprobe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { EventEmitter } = require('events')
const childProcess = require('child_process')
const os = require('os')
const path = require('path')

const log = require('electron-log')
const { is } = require('electron-util')

const split2 = require('split2')
Expand All @@ -12,8 +12,6 @@ const Sentry = require('@sentry/electron')

const { getBinaryPath, getHomeDir } = require('../paths')

const debug = require('debug')('ooniprobe-desktop.utils.ooni.ooniprobe')

const GetHomeShortPath = () => {
// This is taken from: https://github.com/sindresorhus/untildify/pull/13/files
const homeDir = os.homedir()
Expand All @@ -22,6 +20,7 @@ const GetHomeShortPath = () => {
// depending on the language of the OS.
const userDir = homeDir.replace(/([^\\])+$/g, '')
if (!tmpDir.startsWith(userDir)) {
log.error('GetHomeShortPath: cannot fixup', userDir, homeDir)
throw Error('cannot fixup the shortpath')
}
const user83 = tmpDir.slice(userDir.length).replace(/\\.*$/, '')
Expand Down Expand Up @@ -66,7 +65,7 @@ class Ooniprobe extends EventEmitter {
// For more context see: https://github.com/nodejs/node/issues/17586
if (!isAscii.test(homeDir)) {
// eslint-disable-next-line no-console
console.log('detected non-ascii characters in homeDir', homeDir)
log.info('detected non-ascii characters in homeDir', homeDir)
const shortHomeDir = GetHomeShortPath()
options.env['OONI_HOME'] = path.join(shortHomeDir, path.relative(homeDir, options.env.OONI_HOME))
}
Expand All @@ -78,29 +77,29 @@ class Ooniprobe extends EventEmitter {

argv = ['--batch'].concat(argv)

debug('running', binPath, argv, options)
log.info('running', binPath, argv, options)
self.ooni = childProcess.spawn(binPath, argv, options)
} catch (err) {
reject(err)
return
}

self.ooni.on('error', function(err) {
debug('cp.spawn.error:', err)
log.error('cp.spawn.error:', err)
reject(err)
})

self.ooni.stdout.on('data', data => {
debug('stderr: ', data.toString())
log.error('stderr: ', data.toString())
})

self.ooni.stderr.pipe(split2()).on('data', line => {
debug('stdout: ', line.toString())
log.debug('stdout: ', line.toString())
try {
const msg = JSON.parse(line.toString('utf8'))
self.emit('data', msg)
} catch (err) {
debug('failed to call JSON.parse', line.toString('utf8'), err)
log.error('failed to call JSON.parse', line.toString('utf8'), err)
Sentry.addBreadcrumb({
message: 'got unparseable line from ooni cli',
category: 'internal',
Expand All @@ -112,7 +111,7 @@ class Ooniprobe extends EventEmitter {
})

self.ooni.on('exit', code => {
debug('exited with code', code)
log.info('exited with code', code)
// code === null means the process was killed
if (code === 0 || code === null) {
resolve()
Expand Down
5 changes: 5 additions & 0 deletions main/utils/ooni/run.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global windows, require, module */
const { Ooniprobe } = require('./ooniprobe')
const log = require('electron-log')

class Runner {
constructor({testGroupName}) {
Expand All @@ -8,6 +9,7 @@ class Runner {
}

kill() {
log.info('Runner: terminating the ooniprobe process')
return this.ooni.kill()
}

Expand All @@ -16,6 +18,7 @@ class Runner {
windows.main.send('starting', testGroupName)
this.ooni.on('data', (data) => {
if (data.level == 'error') {
log.error('Runner: error', data.message)
windows.main.send('ooni', {
key: 'error',
message: data.message
Expand All @@ -28,6 +31,7 @@ class Runner {
windows.main.send('ooni', {
key: 'ooni.run.progress',
percentage: data.fields.percentage,
eta: data.fields.eta,
message: data.message,
testKey: data.fields.key,
})
Expand All @@ -39,6 +43,7 @@ class Runner {
})
}
})
log.info('Runner: calling run', testGroupName)
return this.ooni.call(['run', testGroupName])
}
}
Expand Down
4 changes: 3 additions & 1 deletion main/utils/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { is } = require('electron-util')
const electron = require('electron')

const debug = require('debug')('ooniprobe-desktop.utils.binary')
const log = require('electron-log')

const getBinarySuffix = () => (process.platform === 'win32' ? '.exe' : '')

Expand Down Expand Up @@ -67,7 +68,8 @@ const debugGetAllPaths = () => ({
'binaryPath': getBinaryPath(),
'binaryDirectory': getBinaryDirectory(),
'binarySuffix': getBinarySuffix(),
'homeDir': getHomeDir()
'homeDir': getHomeDir(),
'logFile': log.transports.file.findLogPath(),
})

module.exports = {
Expand Down
2 changes: 2 additions & 0 deletions main/utils/sentry.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global module */

const getSentryConfig = () => {
return {
dsn: 'https://[email protected]/1210892',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "OONI Probe Desktop app",
"author": "Open Observatory of Network Interference (OONI) <[email protected]>",
"productName": "OONI Probe",
"version": "3.0.0-rc.2",
"probeVersion": "3.0.0-rc.2",
"version": "3.0.0-rc.3",
"probeVersion": "3.0.0-rc.3",
"main": "main/index.js",
"license": "MIT",
"repository": "ooni/probe-desktop",
Expand Down
28 changes: 16 additions & 12 deletions renderer/components/home/running.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { MdKeyboardArrowUp, MdKeyboardArrowDown} from 'react-icons/md'

import Lottie from 'react-lottie'

import moment from 'moment'

const debug = require('debug')('ooniprobe-desktop.renderer.components.home.running')

const StyledRunningTest = styled.div`
Expand Down Expand Up @@ -113,11 +115,7 @@ const CloseButtonContainer = styled.div`
`

//name, icon, color, description, longDescription, onClickClose, active
const RunningTest = ({testGroup, logOpen, onToggleLog, progressLine, percent, logLines, runningTestName, error, totalRuntime, onKill}) => {
let eta = totalRuntime
if (percent > 0) {
eta = Math.round(totalRuntime - percent * totalRuntime)
}
const RunningTest = ({testGroup, logOpen, onToggleLog, progressLine, percent, logLines, runningTestName, error, eta, onKill}) => {
const lottieOptions = {
loop: true,
autoplay: true,
Expand Down Expand Up @@ -158,10 +156,16 @@ const RunningTest = ({testGroup, logOpen, onToggleLog, progressLine, percent, lo
trailColor='rgba(255,255,255,0.4)'
trailWidth='2'
/>
<Text>
<FormattedMessage id='Dashboard.Running.EstimatedTimeLeft' />
<FormattedMessage id='Dashboard.Running.Seconds' values={{ seconds: eta }}/>
</Text>
{eta > 0 &&
<Flex justifyContent='center'>
<Box pr={1}>
<FormattedMessage id='Dashboard.Running.EstimatedTimeLeft' />
</Box>
<Box>
<FormattedMessage id='Dashboard.Running.Seconds' values={{ seconds: moment.duration(eta*1000).humanize() }}/>
</Box>
</Flex>
}
<Text>{progressLine}</Text>
</Container>

Expand Down Expand Up @@ -217,7 +221,7 @@ class Running extends React.Component {
percent,
runningTestName,
logLines,
totalRuntime,
eta,
error,
onKill
} = this.props
Expand All @@ -241,7 +245,7 @@ class Running extends React.Component {
logOpen={logOpen}
onKill={onKill}
onToggleLog={this.onToggleLog}
totalRuntime={totalRuntime}
eta={eta}
/>
</ContentContainer>
</WindowContainer>
Expand All @@ -251,7 +255,7 @@ class Running extends React.Component {
Running.defaultProps = {
progressLine: '',
percent: 0,
totalRuntime: 60,
eta: -1,
logLines: [],
error: null,
runningTestName: ''
Expand Down
Loading

0 comments on commit e4f8747

Please sign in to comment.