settings: refactor settings store
read-only: pass flag with index.html response theme: clean & remove old themes
This commit is contained in:
parent
a6b82a4c93
commit
a588fb2b4a
23 changed files with 203 additions and 418 deletions
|
|
@ -72,7 +72,7 @@
|
|||
"yargs": "15.1.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"electron": "7.1.14",
|
||||
"electron": "7.1.11",
|
||||
"electron-installer-debian": "3.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ window.PACKAGE = require('../../package.json')
|
|||
|
||||
window.LOADING = null
|
||||
|
||||
window.READ_ONLY = false
|
||||
window.READ_ONLY = window.READ_ONLY || false
|
||||
window.GRIDWIDTH = 10
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -94,11 +94,6 @@ module.exports = {
|
|||
|
||||
},
|
||||
|
||||
readOnly: function(){
|
||||
READ_ONLY = true
|
||||
if (editor.enabled) editor.disable()
|
||||
},
|
||||
|
||||
reload: function(){
|
||||
|
||||
var id = Math.random(),
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class Vm {
|
|||
this.registerGlobals()
|
||||
|
||||
// detach sandbox
|
||||
document.documentElement.appendChild(this.sandbox)
|
||||
document.documentElement.removeChild(this.sandbox)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ var {remote, ipcRenderer, shell} = eval('require(\'electron\')'),
|
|||
html = require('nanohtml'),
|
||||
raw = require('nanohtml/raw'),
|
||||
terminal = require('./terminal'),
|
||||
argv_remote = settings.read('argv')
|
||||
options_remote = settings.read('options')
|
||||
|
||||
class Settings {
|
||||
|
||||
|
|
@ -15,10 +15,10 @@ class Settings {
|
|||
this.remote = settings
|
||||
this.container = DOM.get('#osc-container')[0].appendChild(html`<osc-settings></osc-settings>`)
|
||||
this.names = []
|
||||
this.argv = {}
|
||||
this.options = {}
|
||||
this.configPath = null
|
||||
for (var i in argv_remote) {
|
||||
this.argv[i] = argv_remote[i]
|
||||
for (var i in options_remote) {
|
||||
this.options[i] = options_remote[i]
|
||||
}
|
||||
|
||||
this.create()
|
||||
|
|
@ -29,7 +29,7 @@ class Settings {
|
|||
save() {
|
||||
|
||||
if (!this.configPath) return this.saveAs()
|
||||
fs.writeFile(this.configPath, JSON.stringify(this.argv), (err, fdata)=>{
|
||||
fs.writeFile(this.configPath, JSON.stringify(this.options), (err, fdata)=>{
|
||||
|
||||
if (err) console.error(err)
|
||||
else terminal.log('(INFO) Config saved in ' + this.configPath)
|
||||
|
|
@ -60,7 +60,7 @@ class Settings {
|
|||
properties: ['openFile']
|
||||
}).then((file)=>{
|
||||
if (file.canceled || !file.filePaths.length) return
|
||||
this.argv = JSON.parse(fs.readFileSync(file.filePaths[0], 'utf-8'))
|
||||
this.options = JSON.parse(fs.readFileSync(file.filePaths[0], 'utf-8'))
|
||||
this.create()
|
||||
this.write()
|
||||
terminal.log('(INFO) Config loaded from ' + file.filePaths[0])
|
||||
|
|
@ -72,17 +72,13 @@ class Settings {
|
|||
|
||||
write(tmp) {
|
||||
|
||||
for (var i in this.argv) {
|
||||
if (this.argv[i] === '' || !this.names.includes(i)) {
|
||||
delete this.argv[i]
|
||||
for (var i in this.options) {
|
||||
if (this.options[i] === '') {
|
||||
delete this.options[i]
|
||||
}
|
||||
}
|
||||
|
||||
delete this.argv._
|
||||
delete this.argv.$0
|
||||
|
||||
settings.makeDefaultConfig(this.argv)
|
||||
settings.write('argv', this.argv, tmp)
|
||||
settings.write('options', this.options, tmp)
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +100,7 @@ class Settings {
|
|||
|
||||
this.names.push(name)
|
||||
|
||||
let value = this.argv[name] === undefined ? '' : this.argv[name],
|
||||
let value = this.options[name] === undefined ? '' : this.options[name],
|
||||
strValue = Array.isArray(value) ? value.map(x=>x.includes(' ') ? '"'+x+'"' : x).join(' ') : value
|
||||
|
||||
|
||||
|
|
@ -178,14 +174,14 @@ class Settings {
|
|||
fail = err
|
||||
}
|
||||
|
||||
if (fail || v !== '' && data.check && data.check(v, this.argv) !== true) {
|
||||
if (fail || v !== '' && data.check && data.check(v, this.options) !== true) {
|
||||
if (!field.classList.contains('error')) {
|
||||
field.classList.add('error')
|
||||
terminal.log(`(ERROR) --${name}: ${fail || data.check(v, this.argv)}`, 'error')
|
||||
terminal.log(`(ERROR) --${name}: ${fail || data.check(v, this.options)}`, 'error')
|
||||
}
|
||||
} else {
|
||||
field.classList.remove('error')
|
||||
this.argv[name] = v
|
||||
this.options[name] = v
|
||||
}
|
||||
|
||||
if (data.restart && !field.classList.contains('restart') && v != value) {
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
.widget.push-container.on .toggle:before,
|
||||
.widget.modal-container.on > .toggle:before,
|
||||
.widget.switch-container .value.on:before,
|
||||
.widget.switcher-container .value.on:before,
|
||||
.widget.crossfader-container .value.on:before,
|
||||
.widget.toggle-container.on:not(.led) .toggle:before {
|
||||
z-index: 1;
|
||||
opacity: .5;
|
||||
}
|
||||
|
||||
.widget.push-container.on,
|
||||
.widget.modal-container.on,
|
||||
.widget.switch-container .value.on,
|
||||
.widget.switcher-container .value.on,
|
||||
.widget.crossfader-container .value.on,
|
||||
.widget.toggle-container.on:not(.led) {
|
||||
background : var(--color-custom);
|
||||
color: var(--color-bg);
|
||||
font-weight: 900;
|
||||
}
|
||||
.widget.modal-container.on > .label,
|
||||
.widget.toggle-container.on:not(.led) > .label {
|
||||
color: var(--color-bg);
|
||||
}
|
||||
|
||||
.widget.push-container.active:not(.on) > .label {
|
||||
color: var(--color-custom);
|
||||
}
|
||||
|
||||
|
||||
|
||||
.widget.modal-container.on .popup {
|
||||
color: var(--color-text);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
$base: #0e1215;
|
||||
$accent: #1585f6;
|
||||
$tone: #799;
|
||||
$text: white;
|
||||
|
||||
:root {
|
||||
|
||||
////////////////////// COLOR SCHEME
|
||||
|
||||
--color-text: #{transparentize($text, .4)};
|
||||
--color-text-fade: #{transparentize($text, .6)};
|
||||
|
||||
--color-accent: #{$accent};
|
||||
--color-grid: #{transparentize($accent, 0.95)};
|
||||
|
||||
--color-bg: #{$base};
|
||||
--color-track: #{desaturate(mix($base, $tone, 95), 2)};
|
||||
--color-fg: #161a1d;
|
||||
--color-raised: #171c20;
|
||||
--color-light: #{desaturate(transparentize($tone, 0.95), 50)};
|
||||
|
||||
--color-white: white;
|
||||
|
||||
////////////////////// AUTO
|
||||
|
||||
--color-custom: var(--color-accent);
|
||||
|
||||
|
||||
////////////////////// GLASS EFFET
|
||||
|
||||
--color-glass: var(--color-accent);
|
||||
--glass-opacity: 0.03;
|
||||
|
||||
|
||||
////////////////////// MISC
|
||||
|
||||
--nav-height:40rem;
|
||||
--sidepanel-size:300rem;
|
||||
--scrollbar-size:20rem;
|
||||
|
||||
--grid-width:10;
|
||||
}
|
||||
|
||||
.keyboard-container {
|
||||
--color-black: #555;
|
||||
}
|
||||
|
|
@ -1,31 +1,15 @@
|
|||
|
||||
$base: rgb(25, 31, 42);
|
||||
$accent: rgb(82, 168, 255);
|
||||
$tone: rgb(104, 174, 245);
|
||||
$text: white;
|
||||
|
||||
:root {
|
||||
|
||||
////////////////////// old colors
|
||||
|
||||
--color-text-fade: pink;
|
||||
--color-bg: pink;
|
||||
--color-track: pink;
|
||||
--color-fg: pink;
|
||||
--color-raised: pink;
|
||||
--color-light: pink;
|
||||
--color-custom: pink;
|
||||
--color-white: white;
|
||||
|
||||
////////////////////// MISC
|
||||
|
||||
--nav-height: 40rem;
|
||||
--grid-width: 10;
|
||||
|
||||
|
||||
--color-text: #{transparentize($text, .4)};
|
||||
|
||||
--color-accent: #{$accent};
|
||||
|
||||
--color-background: #{$base};
|
||||
--color-ui-background: #{mix($base, black, 85)};
|
||||
|
|
@ -38,14 +22,13 @@ $text: white;
|
|||
|
||||
--alpha-scrollbar: 0.25;
|
||||
--alpha-scrollbar-on: 0.5;
|
||||
--scrollbar-size:12rem;
|
||||
--scrollbar-size: 12rem;
|
||||
|
||||
--color-text-solid: #{$text};
|
||||
--color-text: #{transparentize($text, .4)};
|
||||
|
||||
|
||||
--color-accent: #{$accent};
|
||||
--color-widget: var(--color-accent);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
.toggle-container,
|
||||
.push-container,
|
||||
.modal-container {
|
||||
> .toggle:not(.on):before {
|
||||
box-shadow: 0 0 0 1rem var(--color-light) inset!important;
|
||||
}
|
||||
}
|
||||
|
||||
.switch-container .switch .value,
|
||||
.switcher-container .switch .value,
|
||||
.dropdown-container .select select {
|
||||
box-shadow: 0 0 0 1rem var(--color-light) inset!important;
|
||||
}
|
||||
|
||||
.toggle-container .toggle.on:after,
|
||||
.modal-container > .toggle.on:after,
|
||||
.push-container .toggle.active:after,
|
||||
.switch-container .switch .value.on:after {
|
||||
background: var(--color-bg)
|
||||
}
|
||||
|
||||
.navigation .tablink.on a:before {
|
||||
background: var(--color-bg);
|
||||
}
|
||||
|
||||
.widget {
|
||||
--color-glass-1: var(--color-custom);
|
||||
--color-glass-2: var(--color-custom);
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
$base: rgb(200, 200, 200);
|
||||
$accent: rgb(0, 200, 200);
|
||||
$tone: white;
|
||||
$text: black;
|
||||
|
||||
|
||||
:root {
|
||||
|
||||
////////////////////// COLOR SCHEME
|
||||
|
||||
--color-text: #{transparentize($text, .4)};
|
||||
--color-text-fade: #{transparentize($text, .6)};
|
||||
|
||||
--color-accent: #{$accent};
|
||||
--color-grid: #{transparentize($accent, 0.95)};
|
||||
|
||||
--color-bg: #{$base};
|
||||
--color-track: #{desaturate(mix($base, $tone, 40), 2)};
|
||||
--color-fg: #{desaturate(mix($base, $tone, 30), 5)};
|
||||
--color-raised: #{desaturate(mix($base, $tone, 20), 5)};
|
||||
--color-light: #{desaturate(transparentize($tone, 0.90), 50)};
|
||||
|
||||
--color-white: white;
|
||||
|
||||
////////////////////// AUTO
|
||||
|
||||
--color-custom: var(--color-accent);
|
||||
|
||||
|
||||
////////////////////// GLASS EFFET
|
||||
|
||||
--glass-opacity: 0.05;
|
||||
|
||||
|
||||
////////////////////// MISC
|
||||
|
||||
--nav-height:40rem;
|
||||
--sidepanel-size:300rem;
|
||||
--scrollbar-size:20rem;
|
||||
|
||||
--grid-width:10;
|
||||
}
|
||||
|
||||
.widget {
|
||||
--color-glass: white;
|
||||
}
|
||||
|
||||
.keyboard-container {
|
||||
--color-black-key: #333;
|
||||
--color-white-key: #fff;
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
|
||||
$base: #181818;
|
||||
$accent: #d98533;
|
||||
$tone: rgb(200, 200, 200);
|
||||
$text: white;
|
||||
|
||||
:root {
|
||||
|
||||
////////////////////// COLOR SCHEME
|
||||
|
||||
--color-text: #{transparentize($text, .4)};
|
||||
--color-text-fade: #{transparentize($text, .6)};
|
||||
|
||||
--color-accent: #{$accent};
|
||||
--color-grid: #{transparentize($accent, 0.95)};
|
||||
|
||||
--color-bg: #{$base};
|
||||
--color-track: #{desaturate(mix($base, $tone, 95), 2)};
|
||||
--color-fg: #{desaturate(mix($base, $tone, 88), 5)};
|
||||
--color-raised: #{desaturate(mix($base, $tone, 75), 5)};
|
||||
--color-light: #{desaturate(transparentize($tone, 0.90), 50)};
|
||||
|
||||
--color-white: white;
|
||||
|
||||
////////////////////// AUTO
|
||||
|
||||
--color-custom: var(--color-accent);
|
||||
|
||||
////////////////////// MISC
|
||||
|
||||
--nav-height:40rem;
|
||||
--sidepanel-size:300rem;
|
||||
--scrollbar-size:20rem;
|
||||
|
||||
--grid-width:10;
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
@media screen and (min-width:768px) {
|
||||
body > * {
|
||||
font-size: 120%
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width:1024px) {
|
||||
body > * {
|
||||
font-size: 140%
|
||||
}
|
||||
}
|
||||
|
|
@ -21,21 +21,12 @@ module.exports = {
|
|||
ipc.send('sessionList', recentSessions, clientId)
|
||||
ipc.send('clipboard', clipboard, clientId)
|
||||
|
||||
if (settings.read('readOnly')) {
|
||||
ipc.send('readOnly')
|
||||
}
|
||||
|
||||
if (data.backupId && sessionBackups[data.backupId]) {
|
||||
ipc.send('loadBackup', sessionBackups[data.backupId])
|
||||
return
|
||||
}
|
||||
|
||||
if (settings.read('newSession')) {
|
||||
ipc.send('sessionNew')
|
||||
return
|
||||
}
|
||||
|
||||
if (settings.read('sessionFile')) return this.sessionOpen({path:settings.read('sessionFile')},clientId)
|
||||
if (settings.read('load')) return this.sessionOpen({path:settings.read('load')},clientId)
|
||||
|
||||
|
||||
if (settings.read('examples')) {
|
||||
|
|
@ -44,7 +35,7 @@ module.exports = {
|
|||
recentSessions = recentSessions.map(function(file){return dir + '/' + file})
|
||||
}
|
||||
|
||||
ipc.send('serverTargets', settings.read('targets'), clientId)
|
||||
ipc.send('serverTargets', settings.read('send'), clientId)
|
||||
|
||||
},
|
||||
|
||||
|
|
@ -64,12 +55,12 @@ module.exports = {
|
|||
return index == self.indexOf(elem)
|
||||
})
|
||||
recentSessions = recentSessions.reverse()
|
||||
|
||||
|
||||
// history size limit
|
||||
if (recentSessions.length > 10) recentSessions = recentSessions.slice(0, 10)
|
||||
|
||||
// save history
|
||||
settings.write('recentSessions',recentSessions)
|
||||
settings.write('recentSessions', recentSessions)
|
||||
|
||||
ipc.send('sessionList', recentSessions)
|
||||
|
||||
|
|
@ -91,7 +82,7 @@ module.exports = {
|
|||
|
||||
if (Array.isArray(data.path)) data.path = path.resolve(...data.path)
|
||||
|
||||
if (!settings.read('readOnly')) {
|
||||
if (!settings.read('read-only')) {
|
||||
module.exports.sessionAddToHistory(data.path)
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +109,7 @@ module.exports = {
|
|||
|
||||
if (Array.isArray(data.path)) data.path = path.resolve(...data.path)
|
||||
|
||||
if (settings.read('stateFile')) {
|
||||
if (settings.read('state')) {
|
||||
var send = true
|
||||
for (var id in ipc.clients) {
|
||||
// only make the client send its osc state if there are no other active clients
|
||||
|
|
@ -127,7 +118,7 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
var state = {
|
||||
state: settings.read('stateFile'),
|
||||
state: settings.read('state'),
|
||||
send: send
|
||||
}
|
||||
ipc.send('stateLoad', state, clientId)
|
||||
|
|
@ -170,7 +161,7 @@ module.exports = {
|
|||
|
||||
if (!ok) return
|
||||
|
||||
if (!data.path || settings.read('remoteSaving') && !settings.read('remoteSaving').test(ipc.clients[clientId].address)) {
|
||||
if (!data.path || settings.read('remote-saving') && !settings.read('remote-saving').test(ipc.clients[clientId].address)) {
|
||||
|
||||
return ipc.send('notify', {
|
||||
icon: 'save',
|
||||
|
|
@ -184,7 +175,7 @@ module.exports = {
|
|||
|
||||
if (Array.isArray(data.path)) data.path = path.resolve(...data.path)
|
||||
|
||||
var root = settings.read('remoteRoot')
|
||||
var root = settings.read('remote-root')
|
||||
if (root && !data.path.includes(root)) {
|
||||
console.error('(ERROR) Could not save: path outside of remote-root')
|
||||
return ipc.send('notify', {
|
||||
|
|
@ -312,7 +303,7 @@ module.exports = {
|
|||
|
||||
var targets = []
|
||||
|
||||
if (data.target.indexOf(null) === -1 && settings.read('targets') && !shortdata.target) Array.prototype.push.apply(targets, settings.read('targets'))
|
||||
if (data.target.indexOf(null) === -1 && settings.read('send') && !shortdata.target) Array.prototype.push.apply(targets, settings.read('send'))
|
||||
if (data.target) Array.prototype.push.apply(targets, data.target)
|
||||
|
||||
data.args = data.preArgs ? data.preArgs.concat(value) : [value]
|
||||
|
|
@ -436,7 +427,7 @@ module.exports = {
|
|||
|
||||
if (data.path) p = path.resolve(...data.path)
|
||||
|
||||
var root = settings.read('remoteRoot')
|
||||
var root = settings.read('remote-root')
|
||||
if (root && !p.includes(root)) p = root
|
||||
|
||||
fs.readdir(p, (err, files)=>{
|
||||
|
|
|
|||
|
|
@ -6,16 +6,16 @@ app.setPath('userData', settings.configPath)
|
|||
|
||||
app.commandLine.appendSwitch('--touch-events')
|
||||
|
||||
if (settings.read('noVsync') || (!settings.cli && settings.read('argv')['disable-vsync'])) {
|
||||
if (settings.read('disable-vsync')) {
|
||||
app.commandLine.appendSwitch('--disable-gpu-vsync')
|
||||
}
|
||||
|
||||
if (settings.read('noGpu') || (!settings.cli && settings.read('argv')['disable-gpu'])) {
|
||||
if (settings.read('disable-gpu')) {
|
||||
app.disableHardwareAcceleration()
|
||||
app._noGpu = true
|
||||
}
|
||||
|
||||
if (settings.read('forceGpu') || (!settings.cli && settings.read('argv')['force-gpu'])) {
|
||||
if (settings.read('force-gpu')) {
|
||||
app.commandLine.appendSwitch('--ignore-gpu-blacklist')
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ var template = [{
|
|||
if (process.platform === 'darwin') {
|
||||
// Add app menu (macOs)
|
||||
template.unshift({
|
||||
label: settings.read('appName'),
|
||||
label: settings.infos.appName,
|
||||
submenu: [
|
||||
{
|
||||
label: 'Hide ' + infos.productName,
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ module.exports = function(options={}) {
|
|||
window = new BrowserWindow({
|
||||
width: options.width || screenSize.width,
|
||||
height: options.height || screenSize.height,
|
||||
title: options.title || settings.read('appName'),
|
||||
title: options.title || settings.infos.appName,
|
||||
icon: path.resolve(__dirname + '/../assets/logo.png'),
|
||||
backgroundColor: options.color || theme.backgroundColor,
|
||||
type: options.type,
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ function nodeMode() {
|
|||
|
||||
console.warn('(INFO) Running with node')
|
||||
|
||||
if (!settings.read('noGui')) {
|
||||
if (!settings.read('no-gui')) {
|
||||
settings.cli = true
|
||||
settings.write('noGui', true, true)
|
||||
settings.write('no-gui', true, true)
|
||||
console.warn('(INFO) Headless mode (--no-gui) enabled automatically')
|
||||
}
|
||||
|
||||
|
|
@ -66,10 +66,10 @@ function start() {
|
|||
function openClient() {
|
||||
|
||||
var app = require('./electron-app')
|
||||
var address = settings.read('appAddresses')[0]
|
||||
var address = settings.appAddresses()[0]
|
||||
|
||||
var launch = ()=>{
|
||||
var win = require('./electron-window')({address:address, shortcuts:true, fullscreen: settings.read('fullScreen')})
|
||||
var win = require('./electron-window')({address:address, shortcuts:true, fullscreen: settings.read('fullscreen')})
|
||||
win.on('error', ()=>{
|
||||
console.log('ERR')
|
||||
})
|
||||
|
|
@ -89,7 +89,7 @@ function openClient() {
|
|||
if (settings.cli) {
|
||||
|
||||
start()
|
||||
if (!settings.read('noGui')) openClient()
|
||||
if (!settings.read('no-gui')) openClient()
|
||||
|
||||
|
||||
} else {
|
||||
|
|
@ -142,18 +142,19 @@ if (settings.cli) {
|
|||
ipcMain.on('start',function(e, options){
|
||||
|
||||
var args = ['--no-gui']
|
||||
for (var k in settings.read('argv')) {
|
||||
for (var k in settings.read('options')) {
|
||||
args.push('--' + k)
|
||||
var val = settings.read('argv')[k]
|
||||
var val = settings.read(k)
|
||||
if (typeof val === 'object') {
|
||||
args = args.concat(val)
|
||||
} else if (typeof val !== 'boolean') {
|
||||
args.push(val)
|
||||
}
|
||||
}
|
||||
|
||||
global.serverProcess = spawn(process.argv[0], process.argv.slice(1).concat(args), {stdio: 'pipe'/*, env: {"ELECTRON_RUN_AS_NODE":"1"}*/})
|
||||
|
||||
if (!settings.read('noGui')) {
|
||||
if (!settings.read('no-gui')) {
|
||||
global.serverProcess.stdout.once('data', (data) => {
|
||||
global.clientWindows.push(openClient())
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,54 +1,83 @@
|
|||
var fs = require('fs')
|
||||
|
||||
module.exports = {
|
||||
's':{alias:'send',type:'array',describe:'default targets for all widgets (ip:port / domain:port / midi:port_name pairs)',
|
||||
's': {alias: 'send', type: 'array', describe: 'default targets for all widgets (ip: port / domain: port / midi: port_name pairs)',
|
||||
check: (s)=>{
|
||||
return s.some(item=>!item.match(/^[^:]*:[0-9]{4,5}$/) && !item.match(/^midi:.*$/)) ?
|
||||
'Targets must be ip:port or domain:port pairs (udp / tcp port must be >= 1024) or midi:port_name pairs' : true
|
||||
return s.some(item=>!item.match(/^[^: ]*: [0-9]{4, 5}$/) && !item.match(/^midi: .*$/)) ?
|
||||
'Targets must be ip: port or domain: port pairs (udp / tcp port must be >= 1024) or midi: port_name pairs' : true
|
||||
}
|
||||
},
|
||||
'l':{alias:'load',type:'string',file:{name:'OSC Session (.json)', extensions: ['json', 'js']},describe:'session file to load'},
|
||||
'state':{type:'string',file:{name:'OSC State (.state)', extensions: ['state']},describe:'state file to load'},
|
||||
'c':{alias:'custom-module',type:'array',file:{name:'OSC Custom module (.js)', extensions: ['js']},describe:'custom module file to load (custom options can be passed after the filename)'},
|
||||
'p':{alias:'port',type:'number',describe:'http port of the server (default to 8080)',
|
||||
'l': {alias: 'load', type: 'string', file: {name: 'OSC Session (.json)', extensions: ['json', 'js']}, describe: 'session file to load',
|
||||
check: (arg)=>{
|
||||
return fs.lstatSync(arg) ? true : 'Session file not found: ' + arg
|
||||
},
|
||||
coerce: (arg)=>{
|
||||
return JSON.parse(fs.readFileSync(arg, 'utf8'))
|
||||
}
|
||||
},
|
||||
'state': {type: 'string', file: {name: 'OSC State (.state)', extensions: ['state']}, describe: 'state file to load',
|
||||
check: (arg)=>{
|
||||
return fs.lstatSync(arg) ? true : 'State file not found: ' + arg
|
||||
},
|
||||
coerce: (arg)=>{
|
||||
return JSON.parse(fs.readFileSync(arg, 'utf8'))
|
||||
}
|
||||
},
|
||||
'c': {alias: 'custom-module', type: 'array', file: {name: 'OSC Custom module (.js)', extensions: ['js']}, describe: 'custom module file to load (custom options can be passed after the filename)',
|
||||
check: (arg)=>{
|
||||
return fs.lstatSync(arg) ? true : 'Custom module file not found: ' + arg
|
||||
},
|
||||
},
|
||||
'p': {alias: 'port', type: 'number', describe: 'http port of the server (default to 8080)',
|
||||
check: (p)=>{
|
||||
return (!isNaN(p) && p > 1023 && parseInt(p)===p) ?
|
||||
true : 'Port must be an integer >= 1024'
|
||||
}
|
||||
},
|
||||
'o':{alias:'osc-port',type:'number',describe:'osc input port (default to --port)',
|
||||
'o': {alias: 'osc-port', type: 'number', describe: 'osc input port (default to --port)',
|
||||
check: (o)=>{
|
||||
return (!isNaN(o) && o > 1023 && parseInt(o)===o) ?
|
||||
true : 'Port must be an integer >= 1024'
|
||||
}
|
||||
},
|
||||
'tcp-port':{type:'number', describe:'tcp server input port',
|
||||
'tcp-port': {type: 'number', describe: 'tcp server input port',
|
||||
check: (t, argv)=>{
|
||||
var h = argv['port'] || 8080
|
||||
if (t===h) return 'tcp input port must different from --port'
|
||||
var h = argv['port']
|
||||
if (t === h) return 'Tcp input port must different from --port'
|
||||
return (!isNaN(t) && t > 1023 && parseInt(t)===t) ?
|
||||
true : 'Port must be an integer >= 1024'
|
||||
}
|
||||
},
|
||||
'tcp-targets':{type:'array',describe:'tcp servers to connect to (ip:port pairs), does not susbtitute for --send',
|
||||
'tcp-targets': {type: 'array', describe: 'tcp servers to connect to (ip: port pairs), does not susbtitute for --send',
|
||||
check: (s, argv)=>{
|
||||
if (!argv['tcp-port']) return '--tcp-port must be set'
|
||||
return s.some(item=>!item.match('^[^:\s\"\']*:[0-9]{4,5}[\s\"\']*$')) ?
|
||||
'Targets must be ip:port pairs & port must be >= 1024' : true
|
||||
return s.some(item=>!item.match('^[^: \s\"\']*: [0-9]{4, 5}[\s\"\']*$')) ?
|
||||
'Targets must be ip: port pairs & port must be >= 1024' : true
|
||||
}
|
||||
},
|
||||
'm':{alias:'midi',type:'array',describe:'midi router settings'},
|
||||
'd':{alias:'debug',type:'boolean',describe:'log received osc messages in the console'},
|
||||
'n':{alias:'no-gui',type:'boolean',describe:'disable default gui'},
|
||||
't':{alias:'theme',type:'array',describe:'theme name or path (mutliple values allowed)'},
|
||||
'client-options':{type:'array',describe:'client options (opt=value pairs)',
|
||||
'm': {alias: 'midi', type: 'array', describe: 'midi router settings'},
|
||||
'd': {alias: 'debug', type: 'boolean', describe: 'log received osc messages in the console'},
|
||||
'n': {alias: 'no-gui', type: 'boolean', describe: 'disable default gui'},
|
||||
't': {alias: 'theme', type: 'array', describe: 'theme name or path (mutliple values allowed)'},
|
||||
'client-options': {type: 'array', describe: 'client options (opt=value pairs)',
|
||||
check: (o)=>{
|
||||
return o.some(item=>!item.match(/^[^=]*=[^=]*$/)) ?
|
||||
'Options must be key=value pairs' : true
|
||||
},
|
||||
coerce: (arg)=>{
|
||||
var opts = {}
|
||||
for (var o of arg) {
|
||||
if (!o.includes('=')) continue
|
||||
var [k, v] = o.split('=')
|
||||
opts[k] = v
|
||||
}
|
||||
return opts
|
||||
}
|
||||
},
|
||||
'disable-vsync':{type:'boolean',describe:'disable gui\'s vertical synchronization', restart: true},
|
||||
'force-gpu':{type:'boolean',describe:'ignore chrome\'s gpu blacklist', restart: true},
|
||||
'read-only':{type:'boolean',describe:'disable session editing and session history changes'},
|
||||
'remote-saving':{type:'string',describe:'disable remote session saving for hosts that don\'t match the regular expresion',
|
||||
'disable-vsync': {type: 'boolean', describe: 'disable gui\'s vertical synchronization', restart: true},
|
||||
'force-gpu': {type: 'boolean', describe: 'ignore chrome\'s gpu blacklist', restart: true},
|
||||
'read-only': {type: 'boolean', describe: 'disable session editing and session history changes'},
|
||||
'remote-saving': {type: 'string', describe: 'disable remote session saving for hosts that don\'t match the regular expresion',
|
||||
check: (r, argv)=>{
|
||||
var msg = true
|
||||
try {
|
||||
|
|
@ -57,15 +86,16 @@ module.exports = {
|
|||
msg = e
|
||||
}
|
||||
return msg
|
||||
}
|
||||
},
|
||||
coerce: arg=>RegExp(arg)
|
||||
},
|
||||
'remote-root':{type:'string', describe:'set remote file browsing root folder', file:{folder: true}},
|
||||
'instance-name':{type:'string',describe:'used to differenciate multiple instances in a zeroconf network'},
|
||||
'fullscreen':{type:'boolean', describe:'launch in fullscreen mode (only affects the default client gui)'},
|
||||
'remote-root': {type: 'string', describe: 'set remote file browsing root folder', file: {folder: true}},
|
||||
'instance-name': {type: 'string', describe: 'used to differenciate multiple instances in a zeroconf network'},
|
||||
'fullscreen': {type: 'boolean', describe: 'launch in fullscreen mode (only affects the default client gui)'},
|
||||
|
||||
// cli only
|
||||
'disable-gpu':{type:'boolean',describe:'disable hardware acceleration', launcher: false},
|
||||
'inspect':{type:'boolean', describe:'enable node/electron inspector', launcher: false},
|
||||
'cache-dir':{type:'string', describe:'override default cache directory', launcher: false},
|
||||
'config-file':{type:'string', describe:'override default config file (defaults to cache-dir/config.json)', launcher: false}
|
||||
'disable-gpu': {type: 'boolean', describe: 'disable hardware acceleration', launcher: false},
|
||||
'inspect': {type: 'boolean', describe: 'enable node/electron inspector', launcher: false},
|
||||
'cache-dir': {type: 'string', describe: 'override default cache directory', launcher: false},
|
||||
'config-file': {type: 'string', describe: 'override default config file (defaults to cache-dir/config.json)', launcher: false}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
var path = require('path'),
|
||||
ipc = require('../server').ipc,
|
||||
settings = require('../settings'),
|
||||
tcpInPort = settings.read('tcpInPort'),
|
||||
tcpInPort = settings.read('tcp-port'),
|
||||
debug = settings.read('debug'),
|
||||
vm = require('vm'),
|
||||
fs = require('fs'),
|
||||
|
|
@ -20,7 +20,7 @@ class OscServer {
|
|||
this.customModuleEventEmitter = new EventEmitter()
|
||||
this.customModule = (()=>{
|
||||
|
||||
var customModule = settings.read('customModule')
|
||||
var customModule = settings.read('custom-module')
|
||||
if (!customModule) return false
|
||||
|
||||
// consolidate path containing whitespaces
|
||||
|
|
@ -257,7 +257,7 @@ class OscServer {
|
|||
oscUDPServer.on('message', this.oscInHandlerWrapper.bind(this))
|
||||
oscUDPServer.open()
|
||||
|
||||
if (settings.read('tcpInPort')) {
|
||||
if (settings.read('tcp-port')) {
|
||||
oscTCPServer.on('message', this.oscInHandlerWrapper.bind(this))
|
||||
oscTCPServer.open()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ var osc = require('./osc'),
|
|||
EventEmitter = require('events').EventEmitter,
|
||||
settings = require('../settings'),
|
||||
zeroconf = require('../zeroconf'),
|
||||
tcpInPort = settings.read('tcpInPort'),
|
||||
tcpTargets = settings.read('tcpTargets'),
|
||||
tcpInPort = settings.read('tcp-port'),
|
||||
tcpTargets = settings.read('tcp-targets'),
|
||||
net = require('net')
|
||||
|
||||
class OscTCPClient extends EventEmitter {
|
||||
|
|
@ -129,7 +129,7 @@ class OscTCPServer extends EventEmitter {
|
|||
}
|
||||
|
||||
zeroconf.publish({
|
||||
name: settings.read('appName') + (settings.read('instanceName') ? ' (' + settings.read('instanceName') + ')' : ''),
|
||||
name: settings.infos.appName + (settings.read('instance-name') ? ' (' + settings.read('instance-name') + ')' : ''),
|
||||
protocol: 'tcp',
|
||||
type: 'osc',
|
||||
port: tcpInPort
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
var osc = require('./osc'),
|
||||
settings = require('../settings'),
|
||||
zeroconf = require('../zeroconf'),
|
||||
oscInPort = settings.read('oscInPort') || settings.read('httpPort')
|
||||
oscInPort = settings.read('osc-port') || settings.read('port') || 8080
|
||||
|
||||
var oscUDPServer = new osc.UDPPort({
|
||||
localAddress: '0.0.0.0',
|
||||
|
|
@ -19,7 +19,7 @@ oscUDPServer.on('error', function(e) {
|
|||
})
|
||||
|
||||
zeroconf.publish({
|
||||
name: settings.read('appName') + (settings.read('instanceName') ? ' (' + settings.read('instanceName') + ')' : ''),
|
||||
name: settings.infos.appName + (settings.read('instance-name') ? ' (' + settings.read('instance-name') + ')' : ''),
|
||||
protocol: 'udp',
|
||||
type: 'osc',
|
||||
port: oscInPort
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ var urlparser = require('url'),
|
|||
settings = require('./settings'),
|
||||
theme = require('./theme').init(),
|
||||
zeroconf = require('./zeroconf'),
|
||||
appAddresses = settings.read('appAddresses'),
|
||||
appAddresses = settings.appAddresses(),
|
||||
osc = {},
|
||||
clients = {},
|
||||
httpCheckTimeout
|
||||
|
|
@ -28,7 +28,11 @@ function httpRoute(req, res) {
|
|||
if (url === '/' || url.indexOf('/?') === 0) {
|
||||
|
||||
fs.createReadStream(path.resolve(__dirname + '/../client/index.html'))
|
||||
.pipe(replaceStream('</body>', `<script>window.ENV=${JSON.stringify(settings.read('clientOptions'))}</script></body>`))
|
||||
.pipe(replaceStream('</body>', `
|
||||
<script>
|
||||
window.ENV=${JSON.stringify(settings.read('client-options'))}
|
||||
window.READ_ONLY=${JSON.stringify(settings.read('read-only'))}
|
||||
</script></body>`))
|
||||
.pipe(res);
|
||||
|
||||
// res.sendFile(path.resolve(__dirname + '/../client/index.html'))
|
||||
|
|
@ -89,9 +93,9 @@ server.on('error', (e)=>{
|
|||
}
|
||||
})
|
||||
|
||||
server.listen(settings.read('httpPort'))
|
||||
server.listen(settings.read('port') || 8080)
|
||||
|
||||
http.get(settings.read('appAddresses')[0] + '/osc-ping', ()=>{}).on('error', ()=>{httpCheck(false)})
|
||||
http.get(settings.appAddresses()[0] + '/osc-ping', ()=>{}).on('error', ()=>{httpCheck(false)})
|
||||
httpCheckTimeout = setTimeout(()=>{httpCheck(false)}, 5000)
|
||||
function httpCheck(ok){
|
||||
if (!httpCheckTimeout) return
|
||||
|
|
@ -105,9 +109,9 @@ function httpCheck(ok){
|
|||
}
|
||||
|
||||
zeroconf.publish({
|
||||
name: settings.read('appName') + (settings.read('instanceName') ? ' (' + settings.read('instanceName') + ')' : ''),
|
||||
name: settings.infos.appName + (settings.read('instanceName') ? ' (' + settings.read('instanceName') + ')' : ''),
|
||||
type: 'http',
|
||||
port: settings.read('httpPort')
|
||||
port: settings.read('port') || 8080
|
||||
}).on('error', (e)=>{
|
||||
console.error(`(ERROR, ZEROCONF) ${e.message}`)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,3 +1,15 @@
|
|||
var path = require('path'),
|
||||
fs = require('fs'),
|
||||
ifaces = require('os').networkInterfaces(),
|
||||
yargs = require('yargs'),
|
||||
infos = require('../package.json'),
|
||||
options = require('./options')
|
||||
|
||||
var appAddresses = Object.values(ifaces)
|
||||
.reduce((a,b)=>a.concat(b), [])
|
||||
.filter(i=>i.family === 'IPv4')
|
||||
.map(i=>'http://' + i.address + ':')
|
||||
|
||||
// This prevents argv parsing to be breaked when the app is packaged (executed without 'electron' prefix)
|
||||
if (process.argv[1] && process.argv[1].indexOf('-') == 0) process.argv.unshift('')
|
||||
|
||||
|
|
@ -7,11 +19,7 @@ if (process.argv[1] && process.argv[1].indexOf('-') == 0) process.argv.unshift('
|
|||
// it must be stripped to let yargs work normally
|
||||
if (process.argv[2] == '--') process.argv.splice(2, 1)
|
||||
|
||||
|
||||
var infos = require('../package.json')
|
||||
|
||||
var options = require('./options'),
|
||||
argv = require('yargs')
|
||||
var argv = yargs
|
||||
.parserConfiguration({'boolean-negation': false})
|
||||
.help('help').usage('\nUsage:\n $0 [options]').alias('h', 'help')
|
||||
.options(options)
|
||||
|
|
@ -40,78 +48,45 @@ argv = argv.argv
|
|||
delete argv._
|
||||
delete argv.$0
|
||||
|
||||
// are we in a terminal ?
|
||||
var cli = false,
|
||||
ignored = ['_', '$0', 'no-sandbox', 'noSandbox', 'cache-dir', 'cacheDir', 'config-file', 'configFile', 'disable-gpu', 'disableGpu', 'inspect']
|
||||
// clean argv
|
||||
var optNames = [],
|
||||
cliOnly = []
|
||||
|
||||
for (i in argv) {
|
||||
if (!ignored.includes(i) && (argv[i]!=undefined && argv[i]!==false)) cli = true
|
||||
}
|
||||
|
||||
var fs = require('fs'),
|
||||
ifaces = require('os').networkInterfaces()
|
||||
|
||||
|
||||
var defaultConfig,
|
||||
makeDefaultConfig = function(argv){
|
||||
defaultConfig = {
|
||||
argv:argv,
|
||||
recentSessions: [],
|
||||
appName: infos.productName,
|
||||
instanceName: argv['instance-name'] || false,
|
||||
targets: argv['send'] || false,
|
||||
oscInPort: argv['osc-port'] || 0,
|
||||
httpPort: argv['port'] || 8080,
|
||||
tcpInPort: argv['tcp-port'] || false,
|
||||
tcpTargets: argv['tcp-targets'] || [],
|
||||
debug: argv['debug'] || false,
|
||||
sessionFile: argv['load'] || false,
|
||||
newSession: argv['blank'] || false,
|
||||
customModule: argv['custom-module'] || false,
|
||||
fullScreen: argv['fullscreen'] || false,
|
||||
noGui: argv['no-gui'] || false,
|
||||
guiOnly: typeof argv['gui-only'] == 'string' ? argv['gui-only'].length ? argv['gui-only'] : true : false,
|
||||
clientOptions: argv['client-options'] ? (function(){
|
||||
var opts = {}
|
||||
for (var o of argv['client-options']) {
|
||||
if (!o.includes('=')) continue
|
||||
var [k, v] = o.split('=')
|
||||
opts[k] = v
|
||||
}
|
||||
return opts
|
||||
})() : false,
|
||||
noVsync: argv['disable-vsync'] || false,
|
||||
noGpu: argv['disable-gpu'] || false,
|
||||
forceGpu: argv['force-gpu'] || false,
|
||||
readOnly: argv['read-only'] || false,
|
||||
remoteSaving: argv['remote-saving'] ? RegExp(argv['remote-saving']) : false,
|
||||
remoteRoot: argv['remote-root'] || false,
|
||||
midi: argv['midi'],
|
||||
stateFile: (function(){
|
||||
if (!argv['state']) return false
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(argv['state'], 'utf8'))
|
||||
} catch(err) {
|
||||
console.error(err)
|
||||
return false
|
||||
}
|
||||
})(),
|
||||
appAddresses: Object.values(ifaces)
|
||||
.reduce((a,b)=>a.concat(b), [])
|
||||
.filter(i=>i.family === 'IPv4')
|
||||
.map(i=>'http://' + i.address + ':' + (argv['port'] || 8080)),
|
||||
examples: argv['examples'],
|
||||
theme: argv['theme'] || [],
|
||||
checkForUpdates: true
|
||||
for (var k in options) {
|
||||
var name = options[k].alias || k
|
||||
optNames.push(name)
|
||||
if (options[k].launcher === false) {
|
||||
cliOnly.push(name)
|
||||
}
|
||||
}
|
||||
|
||||
makeDefaultConfig(argv)
|
||||
for (var i in argv) {
|
||||
if (argv[i] === false || !optNames.includes(i)) {
|
||||
delete argv[i]
|
||||
}
|
||||
}
|
||||
delete argv._
|
||||
delete argv.$0
|
||||
|
||||
// are we in a terminal ?
|
||||
var cli = false
|
||||
for (i in argv) {
|
||||
if (!cliOnly.includes(i)) cli = true
|
||||
}
|
||||
|
||||
|
||||
var settings = {
|
||||
options: argv,
|
||||
recentSessions: [],
|
||||
checkForUpdates: true
|
||||
}
|
||||
|
||||
|
||||
|
||||
var path = require('path'),
|
||||
baseDir, configPath, configPathExists = true
|
||||
|
||||
///////////////// config paths
|
||||
|
||||
var baseDir, configPath, configPathExists = true
|
||||
|
||||
if (argv['cache-dir']) {
|
||||
baseDir = path.isAbsolute(argv['cache-dir']) ? argv['cache-dir'] : path.resolve(process.cwd(), argv['cache-dir'])
|
||||
|
|
@ -142,34 +117,52 @@ if (configPathExists) {
|
|||
} else {
|
||||
configPath = path.join(baseDir, 'config.json')
|
||||
}
|
||||
configFile = function(){try {return JSON.parse(fs.readFileSync(configPath,'utf-8'))} catch(err) {return {}}}()
|
||||
config = JSON.parse(JSON.stringify(configFile))
|
||||
try {
|
||||
config = JSON.parse(fs.readFileSync(configPath,'utf-8'))
|
||||
} catch(e) {}
|
||||
if (cli) {
|
||||
for (var k in config) {
|
||||
if (k === 'options') continue
|
||||
settings[k] = config[k]
|
||||
}
|
||||
} else {
|
||||
for (var k in config) {
|
||||
settings[k] = config[k]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!configPath) {
|
||||
console.warn('(WARNING) Config directory not found, settings and session history will not be saved.')
|
||||
}
|
||||
|
||||
/////////////////
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
argv: argv,
|
||||
options: options,
|
||||
makeDefaultConfig: makeDefaultConfig,
|
||||
read: function(key){
|
||||
var x = config[key] !== undefined ? config[key] : defaultConfig[key]
|
||||
return x
|
||||
return settings.options[key] !== undefined ? settings.options[key] : settings[key]
|
||||
},
|
||||
write:function(key,value,tmp) {
|
||||
write:function(key, value, tmp) {
|
||||
|
||||
config[key] = value
|
||||
if (tmp || !configPathExists) return
|
||||
settings[key] = value
|
||||
|
||||
configFile[key] = value
|
||||
if (!tmp && configPathExists) {
|
||||
|
||||
config[key] = value
|
||||
fs.writeFile(configPath, JSON.stringify(config, null, 4), function(err, data) {
|
||||
if (err) throw err
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
fs.writeFile(configPath, JSON.stringify(configFile, null, 4), function(err, data) {
|
||||
if (err) throw err
|
||||
})
|
||||
},
|
||||
cli: cli,
|
||||
configPath: baseDir,
|
||||
infos: infos,
|
||||
appAddresses: ()=>{
|
||||
return appAddresses.map(x=>x + (settings.options.port || 8080))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class Theme {
|
|||
|
||||
init() {
|
||||
|
||||
this.themes = settings.read('theme')
|
||||
this.themes = settings.read('theme') || []
|
||||
this.files = []
|
||||
|
||||
for (let theme of this.themes) {
|
||||
|
|
@ -53,8 +53,8 @@ class Theme {
|
|||
|
||||
var css = this.get()
|
||||
|
||||
if (css.includes('--color-bg:')) {
|
||||
this.backgroundColor = css.match(/--color-bg:([^;]*);/)[1].trim()
|
||||
if (css.includes('--color-background:')) {
|
||||
this.backgroundColor = css.match(/--color-background:([^;]*);/)[1].trim()
|
||||
} else {
|
||||
this.backgroundColor = this.defaultColor
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue