加入初次安裝畫面

1.設定藍芽啟用與否
2.設定印表機連接埠與切紙間格
3.設定結束自動重新啟動服務
This commit is contained in:
Jay
2017-09-05 23:32:52 +08:00
parent 1941ab0c52
commit 3c06bf5d8b
7 changed files with 131 additions and 26 deletions
+26 -7
View File
@@ -11,9 +11,11 @@ router.use(async (c, n) => {
c.data = {
title: 'Printer System Setup'
}
let status = 1
try {
await n()
} catch (err) {
status = 0
if (typeof err === 'string') {
c.body = err
} else {
@@ -23,7 +25,7 @@ router.use(async (c, n) => {
if (c.async) {
c.body = {
status: 0,
status,
msg: c.body
}
}
@@ -40,7 +42,7 @@ router
if (err) return resolve([])
let arr = []
for (let it of list) {
if (it.startsWith('tty')) {
if (/^tty[A-z]/.test(it)) {
arr.push(path.resolve('/dev', it))
}
}
@@ -63,7 +65,7 @@ router
Printer.feed = feed
let status = await Printer.printTestPage()
if (!status) c.body = '測試失敗'
else c.body = '測試成功'
})
@@ -83,11 +85,11 @@ router
main: '',
service: '',
characteristic: ''
},
printer: {
serial: '',
feed: 8
}
},
printer: {
serial: '',
feed: 8
}
}
@@ -95,6 +97,23 @@ router
json.ble.uuid.main = uuid.v4()
json.ble.uuid.service = uuid.v4()
json.ble.uuid.characteristic = uuid.v4()
json.printer.serial = arr.tty
json.printer.feed = feed
let wconfig = await new Promise((resolve, reject) => {
fs.writeFile(path.resolve(process.env.PROJECT_ROOT, 'config.json'), JSON.stringify(json, null, 2), {
mode: 0664,
encoding: 'utf8',
flag: 'w'
}, err => {
if (err) return resolve(false)
return resolve(true)
})
})
if (!wconfig) throw '設定檔寫入失敗'
c.body = '設定檔寫入成功'
})
module.exports = router