mobile: apply root's (or themes) background color the the browser's topbar when possible

This commit is contained in:
jean-emmanuel 2024-10-04 15:41:38 +02:00
parent 4451cffd36
commit f891442e28
9 changed files with 73 additions and 35 deletions

View file

@ -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

View file

@ -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()
}
}

View file

@ -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')

View file

@ -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) {}
})
}
})
}

View file

@ -1,5 +1,5 @@
var UiWidget = require('./ui-widget'),
setScrollbarColor = require('./scrollbar-color')
{setScrollbarColor} = require('./utils')
class UiWorkspace extends UiWidget {

View file

@ -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) {}
})
})
}
}

View file

@ -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'),

View file

@ -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()
}
}

View file

@ -6,6 +6,7 @@
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="theme-color" content="black">
<link rel="apple-touch-icon" href="/assets/logo.png?__OSC_ASSET__=1&version=${version}" />
<link rel="stylesheet" type="text/css" href="/assets/open-stage-control.css?__OSC_ASSET__=1&version=${version}" hot-reload/>
<link rel="stylesheet" type="text/css" href="/theme.css?__OSC_ASSET__=1&version=${version}" hot-reload/>