Make sure to focus window for desktop notifs.

Prevent empty pastes of files.
Log push errors.
This commit is contained in:
Paul 2021-06-22 15:43:06 +01:00
parent 548826527c
commit e98a962071
3 changed files with 30 additions and 23 deletions

View file

@ -263,6 +263,8 @@ function MessageBox({ channel, draft, dispatcher }: Props) {
onChange={files => setUploadState({ type: "attached", files })} onChange={files => setUploadState({ type: "attached", files })}
cancel={() => uploadState.type === 'uploading' && uploadState.cancel.cancel("cancel")} cancel={() => uploadState.type === 'uploading' && uploadState.cancel.cancel("cancel")}
append={files => { append={files => {
if (files.length === 0) return;
if (uploadState.type === 'none') { if (uploadState.type === 'none') {
setUploadState({ type: 'attached', files }); setUploadState({ type: 'attached', files });
} else if (uploadState.type === 'attached') { } else if (uploadState.type === 'attached') {

View file

@ -136,6 +136,7 @@ function Notifier(props: Props) {
if (notif) { if (notif) {
notif.addEventListener("click", () => { notif.addEventListener("click", () => {
window.focus();
const id = msg.channel; const id = msg.channel;
if (id !== channel_id) { if (id !== channel_id) {
let channel = client.channels.get(id); let channel = client.channels.get(id);

View file

@ -62,32 +62,36 @@ export function Component(props: Props & WithDispatcher) {
disabled={typeof pushEnabled === "undefined"} disabled={typeof pushEnabled === "undefined"}
checked={pushEnabled ?? false} checked={pushEnabled ?? false}
onChange={async pushEnabled => { onChange={async pushEnabled => {
const reg = await navigator.serviceWorker?.getRegistration(); try {
if (reg) { const reg = await navigator.serviceWorker?.getRegistration();
if (pushEnabled) { if (reg) {
const sub = await reg.pushManager.subscribe({ if (pushEnabled) {
userVisibleOnly: true, const sub = await reg.pushManager.subscribe({
applicationServerKey: urlBase64ToUint8Array( userVisibleOnly: true,
client.configuration!.vapid applicationServerKey: urlBase64ToUint8Array(
) client.configuration!.vapid
}); )
});
// tell the server we just subscribed // tell the server we just subscribed
const json = sub.toJSON(); const json = sub.toJSON();
if (json.keys) { if (json.keys) {
client.req("POST", "/push/subscribe", { client.req("POST", "/push/subscribe", {
endpoint: sub.endpoint, endpoint: sub.endpoint,
...json.keys ...json.keys
} as any); } as any);
setPushEnabled(true); setPushEnabled(true);
}
} else {
const sub = await reg.pushManager.getSubscription();
sub?.unsubscribe();
setPushEnabled(false);
client.req("POST", "/push/unsubscribe");
} }
} else {
const sub = await reg.pushManager.getSubscription();
sub?.unsubscribe();
setPushEnabled(false);
client.req("POST", "/push/unsubscribe");
} }
} catch (err) {
console.error('Failed to enable push!', err);
} }
}} }}
> >