the ability to mark notification as low priority to bypass the toast

This commit is contained in:
arabcoders 2025-06-15 19:35:57 +03:00
parent 784671cb24
commit ffcae45d9b
3 changed files with 18 additions and 22 deletions

View file

@ -335,9 +335,8 @@ class DownloadQueue(metaclass=Singleton):
if "is_upcoming" == entry.get("live_status"): if "is_upcoming" == entry.get("live_status"):
NotifyEvent = Events.COMPLETED NotifyEvent = Events.COMPLETED
dlInfo.info.status = "not_live" dlInfo.info.status = "not_live"
dlInfo.info.msg = ( dlInfo.info.msg = f"{'Premiere video' if is_premiere else 'Stream' } is not available yet." + text_logs
f"{'Premiere video' if is_premiere else 'Stream' } is not available yet." + text_logs await self._notify.emit(Events.LOG_INFO, data=event_info(dlInfo.info.msg, {"lowPriority": True}))
)
itemDownload: Download = self.done.put(dlInfo) itemDownload: Download = self.done.put(dlInfo)
elif len(entry.get("formats", [])) < 1: elif len(entry.get("formats", [])) < 1:
availability: str = entry.get("availability", "public") availability: str = entry.get("availability", "public")
@ -379,9 +378,7 @@ class DownloadQueue(metaclass=Singleton):
NotifyEvent = Events.COMPLETED NotifyEvent = Events.COMPLETED
await self._notify.emit( await self._notify.emit(
Events.LOG_INFO, Events.LOG_INFO,
data=event_info( data=event_info(f"'{dl.title}' is {dlInfo.info.error}.", {"lowPriority": True}),
f"'{dl.title}' is premiering. Download delayed by '{300+dl.extras.get('duration')}'s."
),
) )
else: else:
NotifyEvent = Events.ADDED NotifyEvent = Events.ADDED

View file

@ -14,10 +14,11 @@ export interface Notification {
export interface notificationOptions { export interface notificationOptions {
timeout?: number, timeout?: number,
force?: boolean, force?: boolean,
store?: boolean,
closeOnClick?: boolean, closeOnClick?: boolean,
position?: POSITION position?: POSITION
onClick?: (closeToast: Function) => void onClick?: (closeToast: Function) => void
store?: boolean,
lowPriority?: boolean
} }
const allowToast = useStorage<boolean>('allow_toasts', true) const allowToast = useStorage<boolean>('allow_toasts', true)
@ -28,15 +29,20 @@ const toast = useToast()
function notify(type: notificationType, message: string, opts?: notificationOptions): void { function notify(type: notificationType, message: string, opts?: notificationOptions): void {
const notificationStore = useNotificationStore() const notificationStore = useNotificationStore()
if (!opts) {
opts = {}
}
let id: string = '' let id: string = ''
const force = opts?.force || false; const force = opts?.force || false;
const store = opts?.store || true; const store = opts?.store || true;
const lowPriority = opts?.lowPriority || false;
if (store && notificationStore) { if (notificationStore && (store || true === lowPriority)) {
id = notificationStore.add(type, message, false) id = notificationStore.add(type, message, false)
} }
if (false === allowToast.value && false === force) { if (true === lowPriority || (false === allowToast.value && false === force)) {
return; return;
} }
@ -44,14 +50,6 @@ function notify(type: notificationType, message: string, opts?: notificationOpti
return; return;
} }
if (!opts) {
opts = {}
}
if (opts?.force) {
delete opts.force
}
opts.closeOnClick = toastDismissOnClick.value opts.closeOnClick = toastDismissOnClick.value
opts.position = toastPosition.value ?? POSITION.TOP_RIGHT opts.position = toastPosition.value ?? POSITION.TOP_RIGHT
opts.onClick = (closeToast: Function) => { opts.onClick = (closeToast: Function) => {
@ -88,5 +86,6 @@ export default function useNotification() {
success: (message: string, opts?: notificationOptions) => notify('success', message, opts), success: (message: string, opts?: notificationOptions) => notify('success', message, opts),
warning: (message: string, opts?: notificationOptions) => notify('warning', message, opts), warning: (message: string, opts?: notificationOptions) => notify('warning', message, opts),
error: (message: string, opts?: notificationOptions) => notify('error', message, opts), error: (message: string, opts?: notificationOptions) => notify('error', message, opts),
notify
} }
} }

View file

@ -51,27 +51,27 @@ export const useSocketStore = defineStore('socket', () => {
socket.value.on('error', stream => { socket.value.on('error', stream => {
const json = JSON.parse(stream); const json = JSON.parse(stream);
toast.error(`${json.data?.id ?? json?.type}: ${json?.message}`); toast.error(`${json.data?.id ?? json?.type}: ${json?.message}`, json.data || {});
}); });
socket.value.on('log_info', stream => { socket.value.on('log_info', stream => {
const json = JSON.parse(stream); const json = JSON.parse(stream);
toast.info(json?.message); toast.info(json?.message, json.data || {});
}); });
socket.value.on('log_success', stream => { socket.value.on('log_success', stream => {
const json = JSON.parse(stream); const json = JSON.parse(stream);
toast.success(json?.message); toast.success(json?.message, json.data || {});
}); });
socket.value.on('log_warning', stream => { socket.value.on('log_warning', stream => {
const json = JSON.parse(stream); const json = JSON.parse(stream);
toast.warning(json?.message); toast.warning(json?.message, json.data || {});
}); });
socket.value.on('log_error', stream => { socket.value.on('log_error', stream => {
const json = JSON.parse(stream); const json = JSON.parse(stream);
toast.error(json?.message); toast.error(json?.message, json.data || {});
}); });
socket.value.on('completed', stream => { socket.value.on('completed', stream => {