Broadcast when theme changes

This commit is contained in:
Sam Atkins
2024-04-09 10:44:51 +01:00
parent 068e620249
commit 59cdb6e8c6
+14
View File
@@ -31,7 +31,11 @@ const default_values = {
};
export class ThemeService extends Service {
#broadcastService;
async _init () {
this.#broadcastService = globalThis.services.get('broadcast');
this.state = {
sat: 41.18,
hue: 210,
@@ -113,6 +117,16 @@ export class ThemeService extends Service {
this.root.style.setProperty('--primary-saturation', s.sat + '%');
this.root.style.setProperty('--primary-lightness', s.lig + '%');
this.root.style.setProperty('--primary-alpha', s.alpha);
// TODO: Should we debounce this to reduce traffic?
this.#broadcastService.sendBroadcast('themeChanged', {
palette: {
primaryHue: s.hue,
primarySaturation: s.sat + '%',
primaryLightness: s.lig + '%',
primaryAlpha: s.alpha,
},
}, { sendToNewAppInstances: true });
}
save_ () {