qrcode pr: refactor for terminal compatibility

This commit is contained in:
jean-emmanuel 2022-11-26 18:34:36 +01:00
parent 924b3c924e
commit 738df79708
3 changed files with 45 additions and 17 deletions

View file

@ -220,6 +220,18 @@ osc-settings-checkbox, osc-settings-reset, osc-settings-file {
user-select: none;
}
.qrcode svg {
width: 120rem;
margin-top: 5rem;
margin-left: 15rem;
path[fill="#ffffff"] {
fill: var(--color-text)!important;
}
path[stroke="#000000"] {
stroke: var(--color-background)!important;
}
}
a {
text-decoration: underline;
cursor: pointer;

View file

@ -84,6 +84,22 @@ function openClient() {
}
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>')
})
} else {
QRCode.toString(settings.appAddresses().pop(),{type:'terminal', small: true}, (err, qr)=>{
console.log('\n' + qr.replace(/^/gm, ' '))
})
}
}
function startServerProcess() {
var args = [ '--no-gui']
@ -102,15 +118,16 @@ function startServerProcess() {
serverProcess = fork(app.getAppPath(), args, {stdio: 'pipe', env: {...process.env, OSC_SERVER_PROCESS: 1}})
if (!settings.read('no-gui')) {
var cb = (data)=>{
if (data.indexOf('Server started') > -1) {
openClient()
serverProcess.stdout.off('data', cb)
}
var cb = (data)=>{
if (data.indexOf('(INFO) Server started') > -1) {
if (!settings.read('no-gui')) openClient()
setTimeout(()=>{
showQRCode()
})
serverProcess.stdout.off('data', cb)
}
serverProcess.stdout.on('data', cb)
}
serverProcess.stdout.on('data', cb)
serverProcess.stdout.on('data', (data) => {
console.log(String(data).trim())
@ -257,6 +274,9 @@ if (settings.read('docs')) {
zeroconf.unpublishAll()
})
if (!process.env.OSC_SERVER_PROCESS) server.eventEmitter.on('serverStarted', ()=>{
showQRCode()
})
} else {

View file

@ -1,6 +1,7 @@
var settings = require('./settings'),
http = require('http'),
QRCode = require('qrcode')
EventEmitter = require('events').EventEmitter,
eventEmitter = new EventEmitter()
function createServer(route) {
@ -192,14 +193,8 @@ function httpCheck(ok, error){
clearTimeout(httpCheckTimeout)
httpCheckTimeout = null
if (ok) {
console.log('(INFO) Server started, app available at')
for (let i = 0; i < settings.appAddresses().length; i++) {
const ipAddress = settings.appAddresses()[i];
console.log('\n'+ipAddress+' : ')
QRCode.toString(ipAddress,{type:'svg',width:230,color:{dark:'#6db5fd',light:'#21252b'}}, function (err, url) {
console.log(url)
})
}
console.log('(INFO) Server started, app available at \n ' + settings.appAddresses().join('\n '))
eventEmitter.emit('serverStarted')
} else {
if (error) {
console.error('(ERROR, HTTP) Server setup error: ' + error.message)
@ -241,7 +236,8 @@ module.exports = {
ipc:ipc,
bindCallbacks:bindCallbacks,
clients:clients,
resolvePath:resolvePath
resolvePath:resolvePath,
eventEmitter:eventEmitter
}
osc = require('./osc').server