git ssb

1+

mixmix / scuttle-shell



Tree: 6994c2171b937fc5df05405a75e38b91142f6664

Files: 6994c2171b937fc5df05405a75e38b91142f6664 / scripts / setup-win.js

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

Built with git-ssb-web