加入初次安裝畫面
1.設定藍芽啟用與否 2.設定印表機連接埠與切紙間格 3.設定結束自動重新啟動服務
This commit is contained in:
+26
-7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user