Begun framework for frontend settings across devices

This commit is contained in:
2022-07-20 22:45:03 +00:00
parent 77554aa86c
commit c7ce90883b
11 changed files with 593 additions and 88 deletions

View File

@@ -0,0 +1,25 @@
export const AutoSettingsMixin = (SuperClass) => {
return class AutoSettingsMixinClass extends SuperClass {
constructor() {
super();
this._auto_settings_setup();
}
async _auto_settings_setup() {
await this.connectionPromise;
const settings = this.settings;
if (settings.sidebarPanelOrder) {
localStorage.setItem("sidebarPanelOrder", settings.sidebarPanelOrder);
}
if (settings.sidebarHiddenPanels) {
localStorage.setItem(
"sidebarHiddenPanels",
settings.sidebarHiddenPanels
);
}
}
};
};

View File

@@ -119,12 +119,66 @@ export const ConnectionMixin = (SuperClass) => {
});
}
get meta() {
if (!this.registered) return null;
return this.browsers[this.browserID].meta;
get global_settings() {
const settings = {};
const global = this._data.settings ?? {};
for (const [k, v] of Object.entries(global)) {
if (v !== null) settings[k] = v;
}
return settings;
}
set meta(value) {
this._reregister({ meta: value });
get user_settings() {
const settings = {};
const user = this._data.user_settings[this.hass.user.id] ?? {};
for (const [k, v] of Object.entries(user)) {
if (v !== null) settings[k] = v;
}
return settings;
}
get browser_settings() {
const settings = {};
const browser = this.browsers[this.browserID]?.settings ?? {};
for (const [k, v] of Object.entries(browser)) {
if (v !== null) settings[k] = v;
}
return settings;
}
get settings() {
return {
...this.global_settings,
...this.user_settings,
...this.browser_settings,
};
}
set_setting(key, value, level) {
switch (level) {
case "global": {
this.connection.sendMessage({
type: "browser_mod/settings",
key,
value,
});
break;
}
case "user": {
const user = this.hass.user.id;
this.connection.sendMessage({
type: "browser_mod/settings",
user,
key,
value,
});
break;
}
case "browser": {
const settings = this.browsers[this.browserID]?.settings;
settings[key] = value;
this._reregister({ settings });
break;
}
}
}
get cameraEnabled() {

View File

@@ -14,6 +14,7 @@ import "./popups";
import { PopupMixin } from "./popups";
import pjson from "../../package.json";
import "./popup-card";
import { AutoSettingsMixin } from "./auto-settings";
/*
TODO:
@@ -48,11 +49,13 @@ import "./popup-card";
x Redesign services to target devices
- frontend editor for popup cards
- also screensavers
- Tweaks
- Save sidebar
- Save sidebar per user
- Saved frontend settings
X Framework
x Save sidebar
- Kiosk mode
- Kiosk mode per user
- Default panel?
- Screensaver?
- Tweaks
- Favicon templates
- Title templates
- Quickbar tweaks (ctrl+enter)?
@@ -67,7 +70,9 @@ export class BrowserMod extends ServicesMixin(
CameraMixin(
MediaPlayerMixin(
ScreenSaverMixin(
FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget)))
AutoSettingsMixin(
FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget)))
)
)
)
)