Merge pull request #242 from talvasconcelos/feature/readthemeenv

Fix theme choosing
This commit is contained in:
Arc
2021-07-01 23:51:09 +01:00
committed by GitHub
5 changed files with 31 additions and 10 deletions

View File

@@ -15,8 +15,8 @@ LNBITS_SERVICE_FEE="0.0"
# Change theme # Change theme
LNBITS_SITE_TITLE=LNbits LNBITS_SITE_TITLE=LNbits
# Choose from mint, flamingo, quasar, autumn, monochrome # Choose from mint, flamingo, salvador, autumn, monochrome, classic
LNBITS_THEME_OPTIONS="mint, flamingo, quasar, autumn, monochrome, salvador" LNBITS_THEME_OPTIONS="mint, flamingo, classic, autumn, monochrome, salvador"
# Choose from LNPayWallet, OpenNodeWallet, LntxbotWallet, LndWallet (gRPC), # Choose from LNPayWallet, OpenNodeWallet, LntxbotWallet, LndWallet (gRPC),
# LndRestWallet, CLightningWallet, LNbitsWallet, SparkWallet # LndRestWallet, CLightningWallet, LNbitsWallet, SparkWallet

View File

@@ -31,7 +31,7 @@ LNBITS_DISABLED_EXTENSIONS: List[str] = env.list(
) )
LNBITS_SITE_TITLE = env.str("LNBITS_SITE_TITLE", default="LNbits") LNBITS_SITE_TITLE = env.str("LNBITS_SITE_TITLE", default="LNbits")
LNBITS_THEME_OPTIONS = env.str("LNBITS_THEME_OPTIONS", default="classic,green,orange") LNBITS_THEME_OPTIONS: List[str] = env.list("LNBITS_THEME_OPTIONS", default="classic, flamingo, mint, salvador, monochrome, autumn", subcast=str)
WALLET = wallet_class() WALLET = wallet_class()
DEFAULT_WALLET_NAME = env.str("LNBITS_DEFAULT_WALLET_NAME", default="LNbits wallet") DEFAULT_WALLET_NAME = env.str("LNBITS_DEFAULT_WALLET_NAME", default="LNbits wallet")

View File

@@ -334,13 +334,26 @@ window.windowMixin = {
}, },
created: function () { created: function () {
this.$q.dark.set(this.$q.localStorage.getItem('lnbits.darkMode')) this.$q.dark.set(this.$q.localStorage.getItem('lnbits.darkMode'))
this.g.allowedThemes = window.allowedThemes this.g.allowedThemes = window.allowedThemes ?? ['classic']
// failsafe if admin changes themes halfway
if (
this.$q.localStorage.getItem('lnbits.theme') &&
!this.g.allowedThemes.includes(
this.$q.localStorage.getItem('lnbits.theme')
)
) {
console.log('allowedThemes changed by Admin', this.g.allowedThemes[0])
this.changeColor(this.g.allowedThemes[0])
}
if (this.$q.localStorage.getItem('lnbits.theme')) { if (this.$q.localStorage.getItem('lnbits.theme')) {
document.body.setAttribute( document.body.setAttribute(
'data-theme', 'data-theme',
this.$q.localStorage.getItem('lnbits.theme') this.$q.localStorage.getItem('lnbits.theme')
) )
} }
if (window.user) { if (window.user) {
this.g.user = Object.freeze(window.LNbits.map.user(window.user)) this.g.user = Object.freeze(window.LNbits.map.user(window.user))
} }

View File

@@ -49,6 +49,13 @@ $themes: (
[data-theme='#{$theme}'] .q-menu--dark { [data-theme='#{$theme}'] .q-menu--dark {
background: $color !important; background: $color !important;
} }
/* IF WANTING TO SET A DARKER BG COLOR IN THE FUTURE
// set a darker body bg for all themes, when in "dark mode"
body[data-theme='#{$theme}'].body--dark {
background: scale-color($color, $lightness: -60%);
}
*/
} }
@if $name == 'info' { @if $name == 'info' {
[data-theme='#{$theme}'] .q-card--dark, [data-theme='#{$theme}'] .q-card--dark,

View File

@@ -39,7 +39,7 @@
<strong>LN</strong>bits {% endif %} {% endblock %} <strong>LN</strong>bits {% endif %} {% endblock %}
</q-toolbar-title> </q-toolbar-title>
{% block beta %} {% block beta %}
<q-badge color="yellow" text-color="black"> <q-badge color="yellow" text-color="black" class="q-mr-md">
<span <span
><span v-show="$q.screen.gt.sm" ><span v-show="$q.screen.gt.sm"
>USE WITH CAUTION - LNbits wallet is still in </span >USE WITH CAUTION - LNbits wallet is still in </span
@@ -48,7 +48,7 @@
</q-badge> </q-badge>
{% endblock %} {% endblock %}
<q-btn-dropdown <q-btn-dropdown
v-if="g.allowedThemes" v-if="g.allowedThemes && g.allowedThemes.length > 1"
dense dense
flat flat
round round
@@ -58,6 +58,7 @@
> >
<div class="row no-wrap q-pa-md"> <div class="row no-wrap q-pa-md">
<q-btn <q-btn
v-if="g.allowedThemes.includes('classic')"
dense dense
flat flat
@click="changeColor('classic')" @click="changeColor('classic')"
@@ -85,7 +86,7 @@
><q-tooltip>autumn</q-tooltip> ><q-tooltip>autumn</q-tooltip>
</q-btn> </q-btn>
<q-btn <q-btn
v-if="g.allowedThemes.includes('flamingo')" v-if="g.allowedThemes.includes('monochrome')"
dense dense
flat flat
@click="changeColor('monochrome')" @click="changeColor('monochrome')"
@@ -95,7 +96,7 @@
><q-tooltip>monochrome</q-tooltip> ><q-tooltip>monochrome</q-tooltip>
</q-btn> </q-btn>
<q-btn <q-btn
v-if="g.allowedThemes.includes('monochrome')" v-if="g.allowedThemes.includes('salvador')"
dense dense
flat flat
@click="changeColor('salvador')" @click="changeColor('salvador')"
@@ -105,7 +106,7 @@
><q-tooltip>elSalvador</q-tooltip> ><q-tooltip>elSalvador</q-tooltip>
</q-btn> </q-btn>
<q-btn <q-btn
v-if="g.allowedThemes.includes('quasar')" v-if="g.allowedThemes.includes('flamingo')"
dense dense
flat flat
@click="changeColor('flamingo')" @click="changeColor('flamingo')"
@@ -188,7 +189,7 @@
<script type="text/javascript"> <script type="text/javascript">
const themes = {{ LNBITS_THEME_OPTIONS | tojson }} const themes = {{ LNBITS_THEME_OPTIONS | tojson }}
if(themes && themes.length) { if(themes && themes.length) {
window.allowedThemes = themes.trim() window.allowedThemes = themes.map(str => str.trim())
} }
</script> </script>
{% block scripts %}{% endblock %} {% block scripts %}{% endblock %}