core&ui: add progress callback (beta)

This commit is contained in:
undefined committed 2023-04-09 23:55:29 +08:00
1 parent 275e82f0e5
commit 16db95ee87
7 files changed
+40 -5

No files matched your search

@@ -2,10 +2,11 @@ import { nanoid } from 'nanoid';
import ReconnectingWebsocket from 'reconnecting-websocket';
import { InfoDialog } from 'vj/components/dialog';
import VjNotification from 'vj/components/notification/index';
import { FLAG_ALERT } from 'vj/constant/message';
import { FLAG_ALERT, FLAG_INFO, FLAG_RICHTEXT } from 'vj/constant/message';
import { AutoloadPage } from 'vj/misc/Page';
import { i18n, tpl } from 'vj/utils';
let previous: VjNotification;
const onmessage = (msg) => {
console.log('Received message', msg);
if (msg.mdoc.flag & FLAG_ALERT) {
@@ -20,10 +21,19 @@ const onmessage = (msg) => {
}).open();
return true;
}
if (msg.mdoc.flag & FLAG_INFO) {
if (previous) previous.hide();
previous = new VjNotification({
message: i18n(msg.mdoc.content),
duration: 3000,
});
previous.show();
return true;
}
if (document.hidden) return false;
// Is message
new VjNotification({
...(msg.udoc._id === 1 && msg.mdoc.flag & 4)
...(msg.udoc._id === 1 && msg.mdoc.flag & FLAG_RICHTEXT)
? { message: i18n('You received a system message, click here to view.') }
: {
title: msg.udoc.uname,
@@ -3,6 +3,7 @@
/// <reference lib="ES2015" />
/// <reference types="@types/sharedworker" />
import ReconnectingWebsocket from 'reconnecting-websocket';
import { FLAG_INFO } from 'vj/constant/message';
console.log('SharedWorker init');
@@ -55,6 +56,7 @@ function initConn(path: string, port: MessagePort, cookie: any) {
setTimeout(() => {
delete ack[payload.mdoc.id];
if (acked) return;
if (payload.mdoc.flag & FLAG_INFO) return;
if (Notification?.permission !== 'granted') {
console.log('Notification permission denied');
return;