qrcode: optional (cli) and on demand (launcher)

This commit is contained in:
jean-emmanuel 2022-12-25 17:17:08 +01:00
parent a12593224d
commit cebca61e30
6 changed files with 42 additions and 4 deletions

View file

@ -89,7 +89,6 @@ function showQRCode(){
var QRCode = require('qrcode')
if (launcher) {
launcher.webContents.send('server-started')
QRCode.toString(settings.appAddresses().pop(),{type:'svg', small: true, margin: 1}, (err, qr)=>{
launcher.webContents.send('stdout', '<div class="qrcode">' + qr + '</div>')
})
@ -121,7 +120,7 @@ function startServerProcess() {
var cb = (data)=>{
if (data.indexOf('(INFO) Server started') > -1) {
if (!settings.read('no-gui')) openClient()
setTimeout(()=>{
if (!settings.read('no-qrcode')) setTimeout(()=>{
showQRCode()
})
serverProcess.stdout.off('data', cb)
@ -250,6 +249,11 @@ function startLauncher() {
})
ipcMain.on('showQRCode',function(e, options){
showQRCode()
})
}
@ -275,7 +279,7 @@ if (settings.read('docs')) {
})
if (!process.env.OSC_SERVER_PROCESS) server.eventEmitter.on('serverStarted', ()=>{
showQRCode()
if (!settings.read('no-qrcode')) showQRCode()
})
} else {

View file

@ -106,4 +106,5 @@ module.exports = {
'Size must a x,y pair of integers' : true
}
},
'no-qrcode': {type: 'boolean', describe: 'disable qrcode when the server starts', launcher: false}
}

View file

@ -75,6 +75,12 @@ var settings = {
checkForUpdates: true
}
// store cli-only options (read-only)
for (let k in argv) {
if (options[k] && options[k].launcher === false) {
settings[k] = argv[k]
}
}
@ -150,6 +156,14 @@ module.exports = {
process.send(['settings.write', [key, value]])
} else {
config[key] = value
if (config.options) {
// don't save cli-only options
for (var k in config.options) {
if (options[k] && options[k].launcher === false) {
delete config.options[k]
}
}
}
if (sync) {
fs.writeFileSync(configPath, JSON.stringify(config, null, 4))
} else {