Autoformating and cleanup

This commit is contained in:
2022-07-13 23:12:15 +00:00
parent e4a65f3077
commit a3cd0c9fd6
10 changed files with 65 additions and 129 deletions

View File

@@ -9,7 +9,9 @@ export const ConnectionMixin = (SuperClass) => {
private _data;
public connected = false;
private _connectionResolve;
public connectionPromise = new Promise(resolve => { this._connectionResolve = resolve; });
public connectionPromise = new Promise((resolve) => {
this._connectionResolve = resolve;
});
LOG(...args) {
const dt = new Date();
@@ -23,7 +25,7 @@ export const ConnectionMixin = (SuperClass) => {
private incoming_message(msg) {
if (msg.command) {
this.LOG("Command:", msg);
this.fireEvent(`command-${msg.command}`, msg)
this.fireEvent(`command-${msg.command}`, msg);
} else if (msg.result) {
this.update_config(msg.result);
}
@@ -103,7 +105,6 @@ export const ConnectionMixin = (SuperClass) => {
})();
}
private async _reregister(newData = {}) {
await this.connection.sendMessage({
type: "browser_mod/reregister",
@@ -165,7 +166,10 @@ export const ConnectionMixin = (SuperClass) => {
this.fireEvent("browser-mod-config-update");
if (this.devices?.[oldID] !== undefined && this.devices?.[this.deviceID] === undefined) {
if (
this.devices?.[oldID] !== undefined &&
this.devices?.[this.deviceID] === undefined
) {
(async () => {
await this.connection.sendMessage({
type: "browser_mod/reregister",
@@ -173,9 +177,9 @@ export const ConnectionMixin = (SuperClass) => {
data: {
...this.devices[oldID],
deviceID: this.deviceID,
}
})
})()
},
});
})();
}
// TODO: Send update to backend to update device
@@ -183,4 +187,4 @@ export const ConnectionMixin = (SuperClass) => {
}
return BrowserModConnection;
}
};

View File

@@ -1,6 +1,5 @@
export const MediaPlayerMixin = (SuperClass) => {
return class MediaPlayerMixinClass extends SuperClass {
public player;
private _player_enabled;
@@ -14,7 +13,9 @@ export const MediaPlayerMixin = (SuperClass) => {
this.player.addEventListener(ev, () => this._player_update());
}
window.addEventListener("pointerdown", () => {
window.addEventListener(
"pointerdown",
() => {
this._player_enabled = true;
if (!this.player.ended) this.player.play();
},
@@ -26,7 +27,9 @@ export const MediaPlayerMixin = (SuperClass) => {
this.player.src = ev.detail.media_content_id;
this.player.play();
});
this.addEventListener("command-player-pause", (ev) => this.player.pause());
this.addEventListener("command-player-pause", (ev) =>
this.player.pause()
);
this.addEventListener("command-player-stop", (ev) => {
this.player.src = null;
this.player.pause();
@@ -38,34 +41,30 @@ export const MediaPlayerMixin = (SuperClass) => {
this.addEventListener("command-player-mute", (ev) => {
if (ev.detail?.mute !== undefined)
this.player.muted = Boolean(ev.detail.mute);
else
this.player.muted = !this.player.muted;
else this.player.muted = !this.player.muted;
});
this.connectionPromise.then(() => this._player_update());
}
private _player_update() {
const state =
this._player_enabled
const state = this._player_enabled
? this.player.src
? this.player.ended
? "stopped"
: this.player.paused
? "paused"
: "playing"
? "paused"
: "playing"
: "stopped"
: "unavailable"
;
: "unavailable";
this.sendUpdate({
player: {
volume: this.player.volume,
muted: this.player.muted,
src: this.player.src,
state,
}
})
},
});
}
}
}
};
};

View File

@@ -1,6 +1,5 @@
export const ScreenSaverMixin = (SuperClass) => {
class ScreenSaverMixinClass extends SuperClass {
private _panel;
private _listeners = {};
private _brightness = 255;
@@ -8,7 +7,7 @@ export const ScreenSaverMixin = (SuperClass) => {
constructor() {
super();
const panel = this._panel = document.createElement("div")
const panel = (this._panel = document.createElement("div"));
panel.setAttribute("browser-mod", "");
panel.attachShadow({ mode: "open" });
const styleEl = document.createElement("style");
@@ -29,7 +28,7 @@ export const ScreenSaverMixin = (SuperClass) => {
:host([dark]) {
background: rgba(0,0,0,1);
}
`
`;
panel.shadowRoot.appendChild(styleEl);
document.body.appendChild(panel);
@@ -54,10 +53,13 @@ export const ScreenSaverMixin = (SuperClass) => {
}
}
private _screen_on(ev=undefined) {
private _screen_on(ev = undefined) {
if (ev?.detail?.brightness) {
this._brightness = ev.detail.brightness;
this._panel.style.setProperty("--darkness", 1-ev.detail.brightness/255)
this._panel.style.setProperty(
"--darkness",
1 - ev.detail.brightness / 255
);
}
this._panel.removeAttribute("dark");
this.sendUpdate({
@@ -67,15 +69,14 @@ export const ScreenSaverMixin = (SuperClass) => {
for (const ev of ["pointerdown", "pointermove", "keydown"]) {
if (this._listeners[ev]) {
window.removeEventListener(ev, this._listeners[ev])
window.removeEventListener(ev, this._listeners[ev]);
this._listeners[ev] = undefined;
}
}
}
}
return ScreenSaverMixinClass
}
return ScreenSaverMixinClass;
};
export const BrowserModScreensaverMixin = (C) =>
class extends C {