-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
101 lines (87 loc) · 2.44 KB
/
Copy pathpreload.js
File metadata and controls
101 lines (87 loc) · 2.44 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
const { contextBridge } = require('electron');
const si = require("systeminformation");
const { fib, dist } = require('cpu-benchmark');
const NetworkSpeed = require('network-speed');
const testNetworkSpeed = new NetworkSpeed();
const drives = async () => {
return si.diskLayout().then((drives) => {
return drives
})
}
const cpus = async () => {
return si.cpu().then((cpus) => {
//console.log(cpus)
return cpus
})
}
const system = async () => {
return si.osInfo().then((system) => {
//console.log(cpus)
return system
})
}
const graphics = async () => {
return si.graphics().then((graphics) => {
//console.log(cpus)
return graphics
})
}
const battery = async () => {
return si.battery().then((battery) => {
//console.log(cpus)
return battery
})
}
const ram = async () => {
return si.memLayout().then((ram) => {
//console.log(cpus)
return ram
})
}
const networks = async () => {
return si.networkInterfaces().then((networks) => {
//console.log(cpus)
return networks
})
}
const cpuScore = async () => {
const duration = fib(41) // Returns time required (ms)
// to calculate the 41. fibonacci number recursively.
const ops = dist(10000) // Returns the amount of operations
// (distance matrix calculations) in 1000ms
return Math.round((duration * ops) / 1000000)
}
async function getNetworkDownloadSpeed() {
const baseUrl = 'https://eu.httpbin.org/stream-bytes/500000';
const fileSizeInBytes = 500000;
const speed = await testNetworkSpeed.checkDownloadSpeed(baseUrl, fileSizeInBytes);
console.log(speed);
return speed;
}
async function getNetworkUploadSpeed() {
const options = {
hostname: 'www.google.com',
port: 80,
path: '/catchers/544b09b4599c1d0200000289',
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
};
const fileSizeInBytes = 2000000
const speed = await testNetworkSpeed.checkUploadSpeed(options, fileSizeInBytes);
console.log(speed);
return speed;
}
contextBridge.exposeInMainWorld('systeminfos', {
disks: async () => drives(),
cpus: async () => cpus(),
system: async () => system(),
graphics: async () => graphics(),
battery: async () => battery(),
ram: async () => ram(),
networks: async () => networks(),
cpuScore: async () => cpuScore(),
downloadScore: async () => getNetworkDownloadSpeed(),
uploadScore: async () => getNetworkUploadSpeed(),
})