-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (38 loc) · 1.55 KB
/
index.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
const ws = require('windows-shortcuts');
const asar = require("@electron/asar");
const fs = require("fs");
const path = require("path");
const os = require('os');
function patchTestwe(p) {
let skip = false;
let patched = [];
fs.mkdtemp(path.join(os.tmpdir(), 'testwe'), (err, folder) => {
if (err) throw err;
asar.extractAll(path.join(p, "resources", "app.asar"), path.join(folder, "app"));
const code = fs.readFileSync(path.join(folder, "app", "dist", "electron", "main.js"), { encoding: 'utf8' }).split(/\r?\n/);
for (line of code) {
if (!skip) {
patched.push(line);
}
if (line.startsWith("async function detectVirtualEnvironemnt")) {
skip = true;
}
if (skip && line == "}") {
patched.push("}");
skip = false;
}
}
fs.writeFileSync(path.join(folder, "app", "dist", "electron", "main.js"), patched.join("\n"));
asar.createPackage(path.join(folder, "app"), path.join(p, "resources", "app.asar")).then(() => console.log("Patching is done !"));
})
}
if (require.main == module) {
ws.query(path.join(process.env.USERPROFILE, "Desktop", "Testwe.lnk"), function (err, opts) {
if (err !== null || opts.workingDir === null) {
console.log("Couldn't find shortcut on Desktop named `TestWe`");
console.log("The easiest way to fix this: Reinstall TestWe")
process.exit(1);
}
patchTestwe(opts.workingDir);
});
}