Skip to content
Snippets Groups Projects
Commit 84da056f authored by insert's avatar insert
Browse files

Add PWA update indicator.

parent e27f1bf9
No related merge requests found
import { updateSW } from "../../main";
import IconButton from "../ui/IconButton";
import { ThemeContext } from "../../context/Theme";
import { Download } from "@styled-icons/boxicons-regular";
import { internalSubscribe } from "../../lib/eventEmitter";
import { useContext, useEffect, useState } from "preact/hooks";
var pendingUpdate = false;
export default function UpdateIndicator() {
const [ pending, setPending ] = useState(pendingUpdate);
useEffect(() => {
return internalSubscribe('PWA', 'update', () => setPending(true));
});
if (!pending) return;
const theme = useContext(ThemeContext);
return (
<IconButton onClick={() => updateSW(true)}>
<Download size={22} color={theme.success} />
</IconButton>
)
}
...@@ -20,3 +20,4 @@ export function internalEmit(ns: string, event: string, ...args: any[]) { ...@@ -20,3 +20,4 @@ export function internalEmit(ns: string, event: string, ...args: any[]) {
// - MessageBox/append // - MessageBox/append
// - TextArea/focus // - TextArea/focus
// - ReplyBar/add // - ReplyBar/add
// - PWA/update
import { registerSW } from 'virtual:pwa-register' import { registerSW } from 'virtual:pwa-register';
const updateSW = registerSW({ import { internalEmit } from './lib/eventEmitter';
export const updateSW = registerSW({
onNeedRefresh() { onNeedRefresh() {
// ! FIXME: temp internalEmit('PWA', 'update');
updateSW(true);
// show a prompt to user
}, },
onOfflineReady() { onOfflineReady() {
console.info('Ready to work offline.'); console.info('Ready to work offline.');
......
...@@ -4,6 +4,7 @@ import { ChannelHeaderProps } from "../ChannelHeader"; ...@@ -4,6 +4,7 @@ import { ChannelHeaderProps } from "../ChannelHeader";
import IconButton from "../../../components/ui/IconButton"; import IconButton from "../../../components/ui/IconButton";
import { AppContext } from "../../../context/revoltjs/RevoltClient"; import { AppContext } from "../../../context/revoltjs/RevoltClient";
import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice"; import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice";
import UpdateIndicator from "../../../components/common/UpdateIndicator";
import { useIntermediate } from "../../../context/intermediate/Intermediate"; import { useIntermediate } from "../../../context/intermediate/Intermediate";
import { VoiceContext, VoiceOperationsContext, VoiceStatus } from "../../../context/Voice"; import { VoiceContext, VoiceOperationsContext, VoiceStatus } from "../../../context/Voice";
import { UserPlus, Cog, Sidebar as SidebarIcon, PhoneCall, PhoneOutgoing } from "@styled-icons/boxicons-regular"; import { UserPlus, Cog, Sidebar as SidebarIcon, PhoneCall, PhoneOutgoing } from "@styled-icons/boxicons-regular";
...@@ -15,6 +16,7 @@ export default function HeaderActions({ channel, toggleSidebar }: ChannelHeaderP ...@@ -15,6 +16,7 @@ export default function HeaderActions({ channel, toggleSidebar }: ChannelHeaderP
return ( return (
<> <>
<UpdateIndicator />
{ channel.channel_type === "Group" && ( { channel.channel_type === "Group" && (
<> <>
<IconButton onClick={() => <IconButton onClick={() =>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment