diff --git a/CHANGELOG.md b/CHANGELOG.md index 1daf8779..68d3b1d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/client/widgets/frames/image.js b/src/client/widgets/frames/image.js index 1edab754..9f81610c 100644 --- a/src/client/widgets/frames/image.js +++ b/src/client/widgets/frames/image.js @@ -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: { diff --git a/src/server/server.js b/src/server/server.js index d964416c..acb6c8cc 100644 --- a/src/server/server.js +++ b/src/server/server.js @@ -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)