image: add support for special value "qrcode"

This commit is contained in:
jean-emmanuel 2022-12-25 17:33:18 +01:00
parent cebca61e30
commit 3fd9c694ce
3 changed files with 19 additions and 4 deletions

View file

@ -5,11 +5,14 @@
- launcher
- add menu options to show the qr code again
- widgets
- image: add support for special value "qrcode"
- misc
- add german locales (@ Magnus Reichel)
- package file names changed to follow debian's convention
- add a cli option to disable the qr code (`--no-qrcode`)
## 1.21.0
- bug fixes

View file

@ -29,7 +29,8 @@ module.exports = class Image extends StaticProperties(Widget, {bypass: true}) {
value: {
value: {type: 'string', value: '', help: [
'- File `url` or `path` (relative to the session or theme file location by default, falling back to absolute path)',
'- Base64 encoded image : `data:image/...`'
'- Base64 encoded image : `data:image/...`',
'- Enter "qrcode" to display the server\'s address QR code'
]}
},
osc: {

View file

@ -2,7 +2,8 @@ var settings = require('./settings'),
http = require('http'),
EventEmitter = require('events').EventEmitter,
eventEmitter = new EventEmitter()
QRCode = require('qrcode'),
qrcode = ''
function createServer(route) {
if (settings.read('use-ssl')) {
@ -87,7 +88,14 @@ function httpRoute(req, res) {
var url = req.url
if (url === '/' || url.indexOf('/?') === 0) {
if (url === '/qrcode'){
res.setHeader('Content-Type', 'image/svg+xml')
var str = qrcode,
buf = Buffer.from && Buffer.from !== Uint8Array.from ? Buffer.from(str) : new Buffer(str)
res.write(buf)
res.end()
} else if (url === '/' || url.indexOf('/?') === 0) {
var ip = req.connection.remoteAddress.replace('::ffff:', '')
@ -195,6 +203,9 @@ function httpCheck(ok, error){
if (ok) {
console.log('(INFO) Server started, app available at \n ' + settings.appAddresses().join('\n '))
eventEmitter.emit('serverStarted')
QRCode.toString(settings.appAddresses().pop(),{type:'svg', small: true, margin: 1}, (err, qr)=>{
qrcode = qr
})
} else {
if (error) {
console.error('(ERROR, HTTP) Server setup error: ' + error.message)