From f891442e284d0304651d75022ee970821a108a6e Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Fri, 4 Oct 2024 15:41:38 +0200 Subject: [PATCH] mobile: apply root's (or themes) background color the the browser's topbar when possible --- CHANGELOG.md | 4 ++ src/client/ipc/callbacks.js | 4 +- src/client/ui/init.js | 1 + src/client/ui/scrollbar-color.js | 32 ---------------- src/client/ui/ui-workspace.js | 2 +- src/client/ui/utils.js | 52 ++++++++++++++++++++++++++ src/client/widgets/containers/panel.js | 2 +- src/client/widgets/containers/root.js | 10 +++++ src/html/client.html | 1 + 9 files changed, 73 insertions(+), 35 deletions(-) delete mode 100644 src/client/ui/scrollbar-color.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 3acf5ac1..e1ab9718 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ - patchbay: `ignoreDefaults` not working properly - editor: missing position indicator in color picker pad +- mobile + - apply root's (or themes) background color the the browser's topbar when possible + + ## 1.27.0 - bug fixes diff --git a/src/client/ipc/callbacks.js b/src/client/ipc/callbacks.js index 7f7c4ae5..08fac43c 100644 --- a/src/client/ipc/callbacks.js +++ b/src/client/ipc/callbacks.js @@ -9,7 +9,8 @@ var utils = require('../ui/utils'), uiLoading = require('../ui/ui-loading'), notifications = require('../ui/notifications'), raw = require('nanohtml/raw'), - backup = require('../backup') + backup = require('../backup'), + {updateMobileThemeColor} = require('../ui/utils') module.exports = { @@ -119,6 +120,7 @@ module.exports = { editor.toggleGrid() }) }) + updateMobileThemeColor() } } diff --git a/src/client/ui/init.js b/src/client/ui/init.js index 73a292e2..c2c4ce3b 100644 --- a/src/client/ui/init.js +++ b/src/client/ui/init.js @@ -5,6 +5,7 @@ require('./notifications') require('./ui-workspace') require('./main-menu') require('./ui-console') +require('./utils').updateMobileThemeColor() if (!navigator.userAgent.match(/Android|iPhone|iPad|iPod/i)) { require('./ui-keyboard') diff --git a/src/client/ui/scrollbar-color.js b/src/client/ui/scrollbar-color.js deleted file mode 100644 index 5150a170..00000000 --- a/src/client/ui/scrollbar-color.js +++ /dev/null @@ -1,32 +0,0 @@ -var chroma = require('chroma-js'), - fastdom = require('fastdom') - -module.exports = (container)=>{ - - fastdom.measure(()=>{ - - var computedStyle = window.getComputedStyle(container), - alpha = parseFloat(computedStyle.getPropertyValue('--alpha-scrollbar')), - alphaOn = parseFloat(computedStyle.getPropertyValue('--alpha-scrollbar-on')), - color = computedStyle.getPropertyValue('--color-fill').trim() - - if (color === 'transparent') { - // prevent chroma-js error - // irrelevant case, but still... - color = 'rgb(0, 0, 0)' - alpha = 0 - alphaOn = 0 - } - - if (color) { - fastdom.mutate(()=>{ - try { - container.style.setProperty('--color-scrollbar', chroma(color).alpha(alpha).css()) - container.style.setProperty('--color-scrollbar-on', chroma(color).alpha(alphaOn).css()) - } catch(e) {} - }) - } - - }) - -} diff --git a/src/client/ui/ui-workspace.js b/src/client/ui/ui-workspace.js index 95c3d189..06eea07f 100644 --- a/src/client/ui/ui-workspace.js +++ b/src/client/ui/ui-workspace.js @@ -1,5 +1,5 @@ var UiWidget = require('./ui-widget'), - setScrollbarColor = require('./scrollbar-color') + {setScrollbarColor} = require('./utils') class UiWorkspace extends UiWidget { diff --git a/src/client/ui/utils.js b/src/client/ui/utils.js index 86c41985..704ace3a 100644 --- a/src/client/ui/utils.js +++ b/src/client/ui/utils.js @@ -1,3 +1,6 @@ +var chroma = require('chroma-js'), + fastdom = require('fastdom'), + widgetManager = require('../managers/widgets') module.exports = { @@ -10,6 +13,55 @@ module.exports = { return String(string).replace(/\^[^\s]{2,}/g,(x)=>{return module.exports.icon(x.substring(1))}) }, + setScrollbarColor: function(container) { + fastdom.measure(()=>{ + + var computedStyle = window.getComputedStyle(container), + alpha = parseFloat(computedStyle.getPropertyValue('--alpha-scrollbar')), + alphaOn = parseFloat(computedStyle.getPropertyValue('--alpha-scrollbar-on')), + color = computedStyle.getPropertyValue('--color-fill').trim() + + if (color === 'transparent') { + // prevent chroma-js error + // irrelevant case, but still... + color = 'rgb(0, 0, 0)' + alpha = 0 + alphaOn = 0 + } + + if (color) { + fastdom.mutate(()=>{ + try { + container.style.setProperty('--color-scrollbar', chroma(color).alpha(alpha).css()) + container.style.setProperty('--color-scrollbar-on', chroma(color).alpha(alphaOn).css()) + } catch(e) {} + }) + } + + }) + + }, + + updateMobileThemeColor: function(){ + + fastdom.measure(()=>{ + var root = widgetManager.getWidgetById('root')[0] + var style = window.getComputedStyle(root ? root.widget : document.documentElement) + + fastdom.mutate(()=>{ + + var color = style.getPropertyValue('--color-background').trim() + try { + for (var el of DOM.get('meta[name="theme-color"], meta[name="apple-mobile-web-app-status-bar-style"]')) { + el.setAttribute('content', color) + } + } catch(e) {} + + }) + + }) + + } } diff --git a/src/client/widgets/containers/panel.js b/src/client/widgets/containers/panel.js index b741cdf1..73068517 100644 --- a/src/client/widgets/containers/panel.js +++ b/src/client/widgets/containers/panel.js @@ -3,7 +3,7 @@ var Container = require('../common/container'), parser = require('../../parser'), html = require('nanohtml'), {enableTraversingGestures, disableTraversingGestures} = require('../../events/drag'), - setScrollbarColor = require('../../ui/scrollbar-color'), + {setScrollbarColor} = require('../../ui/utils'), iOS13 = require('../../ui/ios') === 13, Fader = require('../sliders/fader'), faderDefaults, Script = require('../scripts/script'), diff --git a/src/client/widgets/containers/root.js b/src/client/widgets/containers/root.js index 1cfcebae..6c7df940 100644 --- a/src/client/widgets/containers/root.js +++ b/src/client/widgets/containers/root.js @@ -1,5 +1,6 @@ var Panel = require('./panel'), StaticProperties = require('../mixins/static_properties'), + {updateMobileThemeColor} = require('../../ui/utils'), mainMenu class Root extends StaticProperties(Panel, {visible: true, label: false, id: 'root'}) { @@ -84,6 +85,9 @@ class Root extends StaticProperties(Panel, {visible: true, label: false, id: 'ro case 'hideMenu': this.checkMenuVisibility() return + case 'colorBg': + updateMobileThemeColor() + } } @@ -97,6 +101,12 @@ class Root extends StaticProperties(Panel, {visible: true, label: false, id: 'ro } + setCssVariables() { + + super.setCssVariables() + updateMobileThemeColor() + + } } diff --git a/src/html/client.html b/src/html/client.html index fbeaffc0..aea357cf 100644 --- a/src/html/client.html +++ b/src/html/client.html @@ -6,6 +6,7 @@ +