2021-06-28 05:17:38 -04:00
|
|
|
import { Download } from "@styled-icons/boxicons-regular";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-06-28 05:17:38 -04:00
|
|
|
import { useContext, useEffect, useState } from "preact/hooks";
|
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
import { internalSubscribe } from "../../lib/eventEmitter";
|
|
|
|
|
|
|
|
import { ThemeContext } from "../../context/Theme";
|
|
|
|
|
|
|
|
import IconButton from "../ui/IconButton";
|
|
|
|
|
|
|
|
import { updateSW } from "../../main";
|
|
|
|
|
2021-06-28 05:17:38 -04:00
|
|
|
var pendingUpdate = false;
|
2021-07-05 06:23:23 -04:00
|
|
|
internalSubscribe("PWA", "update", () => (pendingUpdate = true));
|
2021-06-28 05:17:38 -04:00
|
|
|
|
|
|
|
export default function UpdateIndicator() {
|
2021-07-05 06:23:23 -04:00
|
|
|
const [pending, setPending] = useState(pendingUpdate);
|
2021-06-28 05:17:38 -04:00
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
useEffect(() => {
|
|
|
|
return internalSubscribe("PWA", "update", () => setPending(true));
|
|
|
|
});
|
2021-06-28 05:17:38 -04:00
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
if (!pending) return null;
|
|
|
|
const theme = useContext(ThemeContext);
|
2021-06-28 05:17:38 -04:00
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
return (
|
|
|
|
<IconButton onClick={() => updateSW(true)}>
|
|
|
|
<Download size={22} color={theme.success} />
|
|
|
|
</IconButton>
|
|
|
|
);
|
2021-06-28 05:17:38 -04:00
|
|
|
}
|