Files: 05758207d7227e06350b4212f502124c6b062e63 / scripts / setup-win.js
1954 bytesRaw
1 | |
2 | var path = require('path') |
3 | var regedit = require('regedit') |
4 | var fs = require("fs") |
5 | var appPath = path.resolve(".\\app.bat") |
6 | var appManifestTemplateFile = path.resolve(".\\scuttleshell.template.json") |
7 | var appManifestFile = path.resolve(".\\scuttleshell.json") |
8 | |
9 | |
10 | function setup() { |
11 | |
12 | if (process.platform !== "win32") { |
13 | console.log("This script works only on windows, try npm run setup") |
14 | return 1 |
15 | } |
16 | |
17 | if (!fs.existsSync(appPath)) { |
18 | console.log("[ERROR] Application not found at: ", appPath) |
19 | return 1 |
20 | } |
21 | |
22 | if (!fs.existsSync(appManifestTemplateFile)) { |
23 | console.log("[ERROR] App manifest not found at: ", appManifestTemplateFile) |
24 | return 1 |
25 | } |
26 | |
27 | let manifest = JSON.parse(fs.readFileSync(appManifestTemplateFile)) |
28 | |
29 | let applicationLauncherPath = manifest.path |
30 | |
31 | if (!fs.existsSync(applicationLauncherPath)) { |
32 | console.log("[ERROR] App not found at declared location", applicationLauncherPath) |
33 | console.log("FIXING...") |
34 | manifest.path = appPath |
35 | fs.writeFileSync(appManifestFile, JSON.stringify(manifest)) |
36 | } else { |
37 | console.log("[OK] Application found at the correct location", applicationLauncherPath) |
38 | } |
39 | |
40 | // This now involves writing to the registry, I am a bit scared of that... |
41 | |
42 | var valuesToPut = { |
43 | 'HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell': { |
44 | 'scuttleshell': { |
45 | value: appManifestTemplateFile, |
46 | type: 'REG_DEFAULT' |
47 | } |
48 | } |
49 | } |
50 | |
51 | regedit.createKey('HKCU\\Software\\Mozilla\\NativeMessagingHosts\\scuttleshell', function (a, b) { |
52 | regedit.putValue(valuesToPut, function (err) { |
53 | if (err) { |
54 | console.log("[ERROR] Problem writing to registry.", err) |
55 | return 1 |
56 | } else { |
57 | console.log("[OK] Wrote manifest path to registry.\n[INFO] Try: npm run check-win") |
58 | return 0 |
59 | } |
60 | }) |
61 | }) |
62 | return 0 |
63 | } |
64 | |
65 | module.exports = setup |
66 | |
67 | if (require.main === module) { |
68 | var errorLevel = setup() |
69 | process.exit(errorLevel) |
70 | } |
71 | |
72 |
Built with git-ssb-web