This repository has been archived by the owner on Jul 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BottomNav.vue
144 lines (115 loc) · 3.11 KB
/
BottomNav.vue
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<template>
<div class="bottom-nav">
<div class="group">
<p>{{ this.activeMem }} MB ({{ this.percent }}%)</p>
<div class="separator"></div>
<p>{{ this.cpu }}% CPU</p>
</div>
<div class="group">
<p>{{ this.uptime }}</p>
</div>
</div>
</template>
<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';
import system, { Systeminformation } from 'systeminformation';
import os from 'os';
import { formatUptime } from '@/utils/utils';
@Component
export default class BottomNav extends Vue {
private activeMem: number = 0;
private totalMem: number = 0;
private cpu: number = 0;
private uptime: string = '';
/**
* Fetch the informations every 1s
*
* @return void
*/
private mounted(): void {
setInterval(() => this.fetchInformations(), 1000);
}
/**
* Fetch the informations
*
* @return void
*/
private fetchInformations(): void {
this.fetchMemory();
this.fetchCpu();
this.fetchUptime();
}
/**
* Fetch the memory
*
* @return void
*/
private fetchMemory(): void {
system.mem().then((result: Systeminformation.MemData) => {
this.activeMem = this.toMb(result.active);
this.totalMem = this.toMb(result.total);
});
}
/**
* Fetch the cpu
*
* @return void
*/
private fetchCpu(): void {
system.currentLoad().then((result: Systeminformation.CurrentLoadData) => {
this.cpu = parseInt(result.currentload.toFixed(0));
});
}
/**
* Fetch the uptime
*
* @return void
*/
private fetchUptime(): void {
this.uptime = formatUptime(os.uptime());
}
/**
* Get a percentage of the memory used
*
* @return string
*/
private get percent(): string {
return (this.activeMem * 100 / this.totalMem).toFixed(0).toString();
}
/**
* Convert bytes to MB
*
* @param bytes
* @return number
*/
private toMb(bytes: number): number {
return parseInt((bytes / 1048576).toFixed(0));
}
}
</script>
<style lang="scss">
.bottom-nav {
width: 100vw;
height: 20px;
background-color: #0F0F0F;
display: flex;
flex-direction: row;
justify-content: space-between;
.group {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
.separator {
border: 1px solid #212121;
height: 10px;
}
}
p {
color: #646464;
margin: 0 10px;
font-size: 12px;
font-weight: 100;
}
}
</style>