mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 09:38:19 +08:00
core&ui: add progress callback (beta)
This commit is contained in:
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;
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
export const FLAG_UNREAD = 1;
|
||||
export const FLAG_ALERT = 2;
|
||||
export const FLAG_RICHTEXT = 4;
|
||||
export const FLAG_INFO = 8;
|
||||
Reference in new issue
Block a user