This repository has been archived by the owner on Apr 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diagnostics.js
195 lines (172 loc) · 6.76 KB
/
diagnostics.js
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
const {
ipcRenderer,
remote
} = require('electron')
const OS = require('os')
const path = require('path')
const fs = require('fs')
.promises
const cproc = require('child_process')
const glob = require("glob")
const getNetworkInterfaceInfo = () => {
let netint = OS.networkInterfaces();
for (i = 0; i < Object.keys(netint)
.length; i++) {
let k1 = document.createElement("p");
let c1 = document.createTextNode('#' + (i + 1) + ": " + Object.keys(netint)[i]);
k1.className = "bold-item";
k1.appendChild(c1);
document.getElementById("network-info-content")
.appendChild(k1);
let k2 = document.createElement("p");
let c2 = document.createTextNode(JSON.stringify(Object.values(netint)[i], null, 2));
k2.appendChild(c2);
document.getElementById("network-info-content")
.appendChild(k2);
}
}
const getDisplayInfo = () => {
let disp = require('electron')
.remote.getGlobal('displays')
for (i = 0; i < Object.keys(disp)
.length; i++) {
let k1 = document.createElement("p");
let c1 = document.createTextNode('#' + (i + 1) + ": " + Object.keys(disp)[i]);
k1.className = "bold-item";
k1.appendChild(c1);
document.getElementById("display-content")
.appendChild(k1);
let k2 = document.createElement("p");
let c2 = document.createTextNode(JSON.stringify(Object.values(disp)[i], null, 2));
k2.appendChild(c2);
document.getElementById("display-content")
.appendChild(k2);
}
}
const getDependencies = () => {
// AHK
// Use `/` instead of `\\` in filepath, even in Windows!
// `\\` is reserved for escape character in glob.
ifFileExists("C:/Program Files/AutoHotkey/AutoHotkey.exe", "ahk-installation-status", "AHK", "https://www.autohotkey.com/")
ifFileExists("C:/Program Files/ImageMagick-*/magick.exe", "imagemagick-installation-status", "imagemagick", "https://imagemagick.org/script/download.php#windows")
ifFileExists("C:/Python27/python.exe", "python27-installation-status", "python 2.7", "https://www.python.org/downloads/")
ifFileExists("C:/Program Files/VCG/Meshlab/bin/meshlabserver.exe", "meshlab-installation-status", "meshlab", "http://www.meshlab.net/")
}
require('electron')
.remote.getCurrentWindow()
.webContents.once('dom-ready', () => {
getNetworkInterfaceInfo();
getDisplayInfo();
getDependencies();
getPlatform();
getGlobalVariablesCount();
getGlobalVariables();
checkLocalJSONFiles();
if (require('electron').remote.getGlobal("isLowRes")) {
require('electron').webFrame.setZoomFactor(0.8)
}
});
// Use `/` instead of `\\` in filepath, even in Windows!
// `\\` is reserved for escape character in glob.
const ifFileExists = (filepath, elementId, appName, appUrl, errorMsg = null) => {
glob(filepath, function(err, files) {
if (files.length < 1) {
if (errorMsg != null) {
document.getElementById(elementId)
.innerHTML = "Not installed." + "<p class=\"msg italic-item\">search path: " + filepath + "<br />" + appName + " can be downloaded from <a href=\"" + appUrl + "\">" + appUrl + "</a>." + "<br />" + errorMsg + "</p>"
} else {
document.getElementById(elementId)
.innerHTML = "Not installed." + "<p class=\"msg italic-item\">search path: " + filepath + "<br />" + appName + " can be downloaded from <a href=\"" + appUrl + "\">" + appUrl + "</a>.</p>"
}
} else if (err) {
if (errorMsg != null) {
document.getElementById(elementId)
.innerHTML = "Not installed." + "<p class=\"msg italic-item\">search path: " + filepath + "<br />error message: " + err + "<br />" + appName + " can be downloaded from <a href=\"" + appUrl + "\">" + appUrl + "</a>." + "<br />" + errorMsg + "</p>"
} else {
document.getElementById(elementId)
.innerHTML = "Not installed." + "<p class=\"msg italic-item\">search path: " + filepath + "<br />error message: " + err + "<br />" + appName + " can be downloaded from <a href=\"" + appUrl + "\">" + appUrl + "</a>.</p>"
}
} else {
document.getElementById(elementId)
.innerHTML = "Installed (found at " + concatWith(files, ", ") + ")"
}
})
}
const getGlobalVariables = async () => {
let ret = ""
let gvWarning = "Electron's remote module caches remote objects, which this section depends on. It's generally accurate most of the time but take it with a grain of salt."
let isDbg = "\"isInDebugEnv\": " + remote.getGlobal("isInDebugEnv")
let isFDbg = "\"isInFullscreenDebugEnv\": " + remote.getGlobal("isInFullscreenDebugEnv")
ret = "<p>" + gvWarning + "</p><p>" + isDbg + "<br />" + isFDbg + "<br />"
let gvPath = "../configs/globalvariables.json"
let gvObj = JSON.parse(await fs.readFile(path.resolve(__dirname, gvPath)));
for (let e in gvObj) {
ret += JSON.stringify(e) + ": " + JSON.stringify(gvObj[e]) + "<br />"
}
ret += "</p>"
document.getElementById('global-variables-content')
.innerHTML = ret
}
const getGlobalVariablesCount = async () => {
const gvPath = "../configs/globalvariables.json"
let gvObj = JSON.parse(await fs.readFile(path.resolve(__dirname, gvPath)));
document.getElementById('global-variables-label')
.innerHTML = "Total tracked global variables: " + (Object.keys(gvObj)
.length + 2)
}
const getPlatform = () => {
let lp = ""
let lpret = cproc.spawn('reg', ['query', 'HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\FileSystem', '/v', 'LongPathsEnabled'])
lpret.stdout.on('data', (data) => {
// logDebug(data)
lp = data.toString()
.trim()
if (parseInt(lp
.substring(lp.length - 1, lp.length - 0)) == 1) {
lp = ", long path enabled"
logDebug("NEW " + lp)
} else {
lp = ", long path NOT enabled"
}
document.getElementById('misc-platform-info')
.innerHTML = OS.type() + " " + OS.release() + " (" + OS.arch() + ", uptime " + OS.uptime() + lp + ")"
})
}
const checkJSONHealth = async (path, id) => {
let jsonObj = await fs.readFile(path)
let statObj = await fs.stat(path)
try {
JSON.parse(jsonObj)
} catch (err) {
if (err) {
document.getElementById(id)
.innerHTML = "Corrupted: " + err + "<br />Size: " + getHumanReadableFileSize(statObj.size, true)
}
}
document.getElementById(id)
.innerHTML = "Healthy." + "<br />Size: " + getHumanReadableFileSize(statObj.size, true)
}
const checkLocalJSONFiles = () => {
let wd = process.cwd()
// Carousel
checkJSONHealth(path.resolve(wd, "./carousel/content.json"), "carousel-json-status")
// Config
checkJSONHealth(path.resolve(wd, "./configs/globalvariables.json"), "globalvariables-json-status")
}
const getHumanReadableFileSize = (size, usesSIUnit) => {
let baseSize = 1000
let units = ["B", "KB", "MB", "GB", "TB", "PB"]
let fsize = size
let i = 0
if (!usesSIUnit) {
baseSize = 1024
units = ["B", "KiB", "MiB", "GiB", "TiB", "PiB"]
}
// logDebug(baseSize + " " + units)
while (Math.abs(fsize) > baseSize && i < units.length) {
fsize /= baseSize
i++
}
// logDebug(fsize.toFixed(2) + " " + units[i])
return fsize.toFixed(1) + units[i]
}