2021-08-05 09:47:00 -04:00
|
|
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
|
|
import { Download, CloudDownload } from "@styled-icons/boxicons-regular";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-12-13 12:27:06 -05:00
|
|
|
import { useEffect, useState } from "preact/hooks";
|
2021-06-28 05:17:38 -04:00
|
|
|
|
2022-05-30 07:01:47 -04:00
|
|
|
import { IconButton } from "@revoltchat/ui";
|
|
|
|
|
2021-07-05 06:23:23 -04:00
|
|
|
import { internalSubscribe } from "../../lib/eventEmitter";
|
|
|
|
|
2021-12-13 12:27:06 -05:00
|
|
|
import { useApplicationState } from "../../mobx/State";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
import { updateSW } from "../../main";
|
2021-08-01 12:56:38 -04:00
|
|
|
import Tooltip from "./Tooltip";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-07-10 10:57:29 -04:00
|
|
|
let pendingUpdate = false;
|
2021-07-05 06:23:23 -04:00
|
|
|
internalSubscribe("PWA", "update", () => (pendingUpdate = true));
|
2021-06-28 05:17:38 -04:00
|
|
|
|
2021-08-01 12:52:44 -04:00
|
|
|
interface Props {
|
|
|
|
style: "titlebar" | "channel";
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function UpdateIndicator({ style }: Props) {
|
2021-07-05 06:25:20 -04:00
|
|
|
const [pending, setPending] = useState(pendingUpdate);
|
2021-06-28 05:17:38 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
useEffect(() => {
|
|
|
|
return internalSubscribe("PWA", "update", () => setPending(true));
|
|
|
|
});
|
2021-06-28 05:17:38 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
if (!pending) return null;
|
2021-12-13 12:27:06 -05:00
|
|
|
const theme = useApplicationState().settings.theme;
|
2021-06-28 05:17:38 -04:00
|
|
|
|
2021-08-01 12:52:44 -04:00
|
|
|
if (style === "titlebar") {
|
|
|
|
return (
|
2021-08-01 12:56:38 -04:00
|
|
|
<div class="actions">
|
|
|
|
<Tooltip
|
|
|
|
content="A new update is available!"
|
|
|
|
placement="bottom">
|
|
|
|
<div onClick={() => updateSW(true)}>
|
2021-12-13 12:27:06 -05:00
|
|
|
<CloudDownload
|
|
|
|
size={22}
|
|
|
|
color={theme.getVariable("success")}
|
|
|
|
/>
|
2021-08-01 12:56:38 -04:00
|
|
|
</div>
|
|
|
|
</Tooltip>
|
2021-08-01 12:52:44 -04:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window.isNative) return null;
|
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
return (
|
|
|
|
<IconButton onClick={() => updateSW(true)}>
|
2021-12-13 12:27:06 -05:00
|
|
|
<Download size={22} color={theme.getVariable("success")} />
|
2021-07-05 06:25:20 -04:00
|
|
|
</IconButton>
|
|
|
|
);
|
2021-06-28 05:17:38 -04:00
|
|
|
}
|