Skip to content

Commit

Permalink
fix: sync state on color reset
Browse files Browse the repository at this point in the history
  • Loading branch information
darlanalves committed Oct 21, 2023
1 parent 8fe16b8 commit deaa2f9
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,23 @@
const reset = async () => {
const { clientId, clientSecret, deviceIds, state } = await getProperties();

await state.remove('color');

for (const deviceId of deviceIds) {
await fetch("/reset/" + deviceId, {
headers: { clientId, clientSecret },
});
}

await state.remove('color');
};

window.addEventListener("DOMContentLoaded", async () => {
const main = document.querySelector("main");
const theme = document.head.querySelector('meta[name="theme-color"]');

const applyColorToScreen = (color) => {
if (color) {
main.style.backgroundColor = color.rgb;
theme.content = color.rgb;
}
const rgb = color?.rgb || '#fff';
main.style.backgroundColor = rgb;
theme.content = rgb;
};

try {
Expand All @@ -128,7 +127,7 @@
}

const props = await getProperties();
const apply = debounce(applyColor, props.interval);
const applyColorToDevices = debounce(applyColor, props.interval);
let lastStamp = Date.now();
const { state } = props;

Expand All @@ -140,7 +139,7 @@
const color = colors[index];

applyColorToScreen(color);
apply(color);
applyColorToDevices(color);
};

function startChange() {
Expand Down

0 comments on commit deaa2f9

Please sign in to comment.