From 6574b8465a81d3dbcab13e6d5b5d6af542bd1f7a Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Mon, 21 Mar 2016 19:48:26 +0100 Subject: [PATCH] - theming support added - not caching fake input color as private var because it doesn't work with themes --- README.md | 3 ++- browser/js/app.js | 2 +- browser/js/app/callbacks.js | 13 ++++++++++++- browser/js/app/ui.js | 5 ++--- browser/js/jquery/jquery.fake-input.js | 4 ++-- main/callbacks.js | 1 + main/settings.js | 13 +++++++++++-- 7 files changed, 31 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0baaf326..24edb9d1 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Please note that : - bi-directionnal osc bindings - headless server mode with any number of clients using chromium - app state store / recall & import / export -- light & dark themes ! +- themes ! ### Getting started @@ -37,6 +37,7 @@ Options: -l, --load session file to load -p, --port osc input port (for synchronization) -n, --nogui disable default gui and makes the app availabe through http on specified port + -t, --theme theme name (light) or path to theme file Exemples : diff --git a/browser/js/app.js b/browser/js/app.js index c3d93b27..8232e2fc 100644 --- a/browser/js/app.js +++ b/browser/js/app.js @@ -23,7 +23,7 @@ MISC = { PXSCALE = getComputedStyle(document.documentElement).getPropertyValue("--pixel-scale") - +INITIALZOOM = PXSCALE /////////////////////// diff --git a/browser/js/app/callbacks.js b/browser/js/app/callbacks.js index 626c93ef..617cf098 100644 --- a/browser/js/app/callbacks.js +++ b/browser/js/app/callbacks.js @@ -11,7 +11,7 @@ module.exports = { // fetch ids corresponding to the osc path var path = data.path var ids = WIDGETS_ID_BY_PATH[path] - + for (i in ids) { var id = ids[i] // update @@ -77,6 +77,17 @@ module.exports = { var data = data || event utils.createPopup(icon('warning')+' '+data.title,data.text) + }, + + applyStyle: function(event,data){ + var data = data || event + var style = document.createElement('style'); + style.innerHTML = data; + document.body.appendChild(style); + if (data.indexOf('--pixel-scale')) { + PXSCALE = data.match(/--pixel-scale\s*:\s*([^;]*)/)[1] + INITIALZOOM = PXSCALE + } } } diff --git a/browser/js/app/ui.js b/browser/js/app/ui.js index aeaf4c9a..07f041a4 100644 --- a/browser/js/app/ui.js +++ b/browser/js/app/ui.js @@ -34,7 +34,6 @@ var tabs = function() { // if shift is pressed (native), or if there is no vertical scrollbar, // or if mouse is on h-scrollbar var scrollbarHeight = 20 -var initialZoom = PXSCALE var scrolls = function(){ $('html').on('mousewheel.zoom',function(e) { // console.log(e) @@ -51,9 +50,9 @@ var scrolls = function(){ }) $(document).on('keydown.resetzoom', function(e){ if (e.keyCode==96||e.keyCode==48) { - PXSCALE = 1 + PXSCALE = INITIALZOOM document.documentElement.style.setProperty("--pixel-scale",'') - document.documentElement.style.setProperty("--pixel-scale",initialZoom) + document.documentElement.style.setProperty("--pixel-scale",PXSCALE) } }) diff --git a/browser/js/jquery/jquery.fake-input.js b/browser/js/jquery/jquery.fake-input.js index 4d29f92b..0df358b2 100644 --- a/browser/js/jquery/jquery.fake-input.js +++ b/browser/js/jquery/jquery.fake-input.js @@ -1,5 +1,4 @@ (function ($) { - var color = String(getComputedStyle(document.documentElement).getPropertyValue("--color-text")).trim() $.fn.fakeInput = function(options) { var settings = $.extend({ @@ -13,7 +12,7 @@ self.value = undefined self.height = undefined self.width = undefined - self.color = color + self.color = undefined self.center = settings.align == 'center' self.visible = false @@ -33,6 +32,7 @@ canvas.addClass('visible') } + self.color = getComputedStyle(document.documentElement).getPropertyValue("--color-text") self.height=height self.width=width diff --git a/main/callbacks.js b/main/callbacks.js index 823c8574..f7264918 100644 --- a/main/callbacks.js +++ b/main/callbacks.js @@ -5,6 +5,7 @@ module.exports = function(settings,fs,ipc,osc,dialog) { return { ready: function(data,clientId) { + if (settings.read('theme')) ipc.send('applyStyle',settings.read('theme'),clientId) if (settings.read('sessionFile')) this.sessionOpen({path:settings.read('sessionFile')},clientId) var recentSessions = settings.read('recentSessions') ipc.send('sessionList',recentSessions,clientId) diff --git a/main/settings.js b/main/settings.js index 708a13ac..80cf3da2 100644 --- a/main/settings.js +++ b/main/settings.js @@ -11,6 +11,7 @@ var argv = require('yargs') 'l':{alias:'load',type:'string',describe:'session file to load'}, 'p':{alias:'port',describe:'osc input port (for synchronization)'}, 'n':{alias:'nogui',describe:'disable default gui and makes the app availabe through http on specified port'}, + 't':{alias:'theme',type:'string',describe:'theme name or file'} }) .check(function(a,x){if(a.port==undefined || !isNaN(a.p)&&a.p>1023&&parseInt(a.p)===a.p){return true}else{throw 'Error: Port must be an integer >= 1024'}}) .check(function(a,x){if(a.n==undefined || !isNaN(a.n)&&a.n>1023&&parseInt(a.n)===a.n){return true}else{throw 'Error: Port must be an integer >= 1024'}}) @@ -28,10 +29,18 @@ module.exports = function(fs) { appName: 'Open Stage Control', syncTargets: argv.s || false, oscInPort: argv.p || false, - compileScss: argv.c!==undefined || false, - lightTheme: argv.c && argv.c.match(/light/), sessionFile: argv.l || false, noGui: argv.n || false, + theme: function(){ + if (!argv.t) return + try {return fs.readFileSync(__dirname + '/themes/' + argv.t + '.css','utf-8')} + catch(err) { + try {return fs.readFileSync(argv.t,'utf-8')} + catch(err) { + return + } + } + }() } return {