-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathmemory.js
More file actions
104 lines (89 loc) · 2.63 KB
/
memory.js
File metadata and controls
104 lines (89 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React, { Component } from 'react'
import { mem as memoryData } from 'systeminformation'
import leftPad from 'left-pad'
import SvgIcon from '../utils/svg-icon'
class PluginIcon extends Component {
render() {
return (
<SvgIcon>
<g fill="none" fillRule="evenodd">
<g className='memory-icon'>
<g id="memory" transform="translate(1.000000, 1.000000)">
<path d="M3,0 L11,0 L11,14 L3,14 L3,0 Z M4,1 L10,1 L10,13 L4,13 L4,1 Z" />
<rect x="5" y="2" width="4" height="10" />
<rect x="12" y="1" width="2" height="1" />
<rect x="12" y="3" width="2" height="1" />
<rect x="12" y="5" width="2" height="1" />
<rect x="12" y="9" width="2" height="1" />
<rect x="12" y="7" width="2" height="1" />
<rect x="12" y="11" width="2" height="1" />
<rect x="0" y="1" width="2" height="1" />
<rect x="0" y="3" width="2" height="1" />
<rect x="0" y="5" width="2" height="1" />
<rect x="0" y="9" width="2" height="1" />
<rect x="0" y="7" width="2" height="1" />
<rect x="0" y="11" width="2" height="1" />
</g>
</g>
</g>
<style jsx>{`
.memory-icon {
fill: #fff;
}
`}</style>
</SvgIcon>
)
}
}
export default class Memory extends Component {
static displayName() {
return 'memory'
}
constructor(props) {
super(props)
this.state = {
activeMemory: 0,
totalMemory: 0
}
this.getMemory = this.getMemory.bind(this)
this.setMemory = this.setMemory.bind(this)
}
componentDidMount() {
this.setMemory()
this.interval = setInterval(() => this.setMemory(), 2500)
}
componentWillUnmount() {
clearInterval(this.interval)
}
getMemory() {
return memoryData().then(memory => {
const totalMemory = this.getMb(memory.total)
const activeMemory = this.getMb(memory.active)
const totalWidth = totalMemory.toString().length
return {
activeMemory: leftPad(activeMemory, totalWidth, 0),
totalMemory
}
})
}
setMemory() {
return this.getMemory().then(data => this.setState(data))
}
getMb(bytes) {
// 1024 * 1024 = 1048576
return (bytes / 1048576).toFixed(0)
}
render() {
return (
<div className='wrapper'>
<PluginIcon /> {this.state.activeMemory}MB / {this.state.totalMemory}MB
<style jsx>{`
.wrapper {
display: flex;
align-items: center;
}
`}</style>
</div>
)
}
}