Browse Source

Merge branch 'develop' of github.com:ledgerhq/ledger-live-desktop into migration

master
Gaëtan Renaudeau 7 years ago
parent
commit
7debf62677
  1. 47
      src/components/KeyboardContent.js
  2. 57
      src/components/PerfIndicator.js
  3. 5
      src/components/layout/Default.js
  4. 13
      src/helpers/db/db-storybook.js
  5. 0
      src/helpers/db/db.js
  6. 3
      src/helpers/db/index.js
  7. 1
      src/helpers/resolveLogsDirectory.js
  8. 3
      src/logger/index.js
  9. 23
      src/logger/logger-storybook.js
  10. 0
      src/logger/logger.js

47
src/components/KeyboardContent.js

@ -0,0 +1,47 @@
// @flow
// Toggle something after a sequence of keyboard
import { Component } from 'react'
class KeyboardContent extends Component<
{
sequence: string,
children?: *,
},
{ enabled: boolean },
> {
state = {
enabled: false,
}
componentDidMount() {
window.addEventListener('keypress', this.onKeyPress)
}
componentWillUnmount() {
window.removeEventListener('keypress', this.onKeyPress)
}
seqIndex = -1
onKeyPress = (e: *) => {
const { sequence } = this.props
const next = sequence[this.seqIndex + 1]
if (next && next === e.key) {
this.seqIndex++
} else {
this.seqIndex = -1
}
if (this.seqIndex === sequence.length - 1) {
this.seqIndex = -1
this.setState(({ enabled }) => ({ enabled: !enabled }))
}
}
render() {
const { children } = this.props
const { enabled } = this.state
return enabled ? children : null
}
}
export default KeyboardContent

57
src/components/PerfIndicator.js

@ -0,0 +1,57 @@
// @flow
import React, { PureComponent } from 'react'
import styled from 'styled-components'
import ping from 'commands/ping'
const Indicator = styled.div`
opacity: 0.8;
border-radius: 3px;
background-color: white;
position: fixed;
font-size: 10px;
padding: 3px 6px;
bottom: 0;
left: 0;
z-index: 999;
pointer-events: none;
`
class PerfIndicator extends PureComponent<{}, { opsPerSecond: number }> {
state = {
opsPerSecond: 0,
}
componentDidMount() {
let count = 0
const loop = () => {
++count
if (this.finished) return
this.sub = ping.send().subscribe({
complete: loop,
})
}
loop()
setInterval(() => {
this.setState({ opsPerSecond: count })
count = 0
}, 1000)
}
componentWillUnmount() {
if (this.sub) {
this.sub.unsubscribe()
this.finished = true
}
}
sub: *
interval: *
finished = false
render() {
return (
<Indicator>
{this.state.opsPerSecond}
{' ops/s'}
</Indicator>
)
}
}
export default PerfIndicator

5
src/components/layout/Default.js

@ -18,6 +18,8 @@ import DashboardPage from 'components/DashboardPage'
import ManagerPage from 'components/ManagerPage'
import ExchangePage from 'components/ExchangePage'
import SettingsPage from 'components/SettingsPage'
import KeyboardContent from 'components/KeyboardContent'
import PerfIndicator from 'components/PerfIndicator'
import LibcoreBusyIndicator from 'components/LibcoreBusyIndicator'
import DeviceBusyIndicator from 'components/DeviceBusyIndicator'
import TriggerAppReady from 'components/TriggerAppReady'
@ -106,6 +108,9 @@ class Default extends Component<Props> {
<LibcoreBusyIndicator />
<DeviceBusyIndicator />
<KeyboardContent sequence="BJBJBJ">
<PerfIndicator />
</KeyboardContent>
</IsUnlocked>
</Fragment>
)

13
src/helpers/db/db-storybook.js

@ -0,0 +1,13 @@
// @flow
const noop = () => {}
module.exports = {
init: noop,
get: noop,
set: noop,
getIn: noop,
setIn: noop,
cleanCache: noop,
resetAll: noop,
}

0
src/helpers/db.js → src/helpers/db/db.js

3
src/helpers/db/index.js

@ -0,0 +1,3 @@
const db = process.env.STORYBOOK_ENV ? require('./db-storybook') : require('./db')
module.exports = db

1
src/helpers/resolveLogsDirectory.js

@ -15,7 +15,6 @@ export default resolveLogsDirectory
export const RotatingLogFileParameters = {
filename: 'application-%DATE%.log',
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '20m',
maxFiles: '14d',
}

3
src/logger/index.js

@ -0,0 +1,3 @@
const logger = process.env.STORYBOOK_ENV ? require('./logger-storybook') : require('./logger')
module.exports = logger

23
src/logger/logger-storybook.js

@ -0,0 +1,23 @@
const noop = () => {}
module.exports = {
setProcessShortName: noop,
onCmd: noop,
onDB: noop,
onReduxAction: noop,
onTabKey: noop,
websocket: noop,
libcore: noop,
network: noop,
networkSucceed: noop,
networkError: noop,
networkDown: noop,
analyticsStart: noop,
analyticsStop: noop,
analyticsTrack: noop,
analyticsPage: noop,
log: noop,
warn: noop,
error: noop,
critical: noop,
}

0
src/logger.js → src/logger/logger.js

Loading…
Cancel
Save