Don't show notification if window is focused
This commit is contained in:
parent
a8a25d09ee
commit
dcc3473ecf
|
@ -50,7 +50,7 @@ from .models.model_store import ModelStore
|
|||
from .nio_callbacks import NioCallbacks
|
||||
from .presence import Presence
|
||||
from .pyotherside_events import (
|
||||
AlertRequested, InvalidAccessToken, LoopException,
|
||||
InvalidAccessToken, LoopException, NotificationRequested,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -2137,8 +2137,6 @@ class MatrixClient(nio.AsyncClient):
|
|||
room_item.local_unreads = True
|
||||
|
||||
if unread or highlight:
|
||||
AlertRequested(high_importance=highlight)
|
||||
|
||||
members = self.models[self.user_id, room.room_id, "members"]
|
||||
room_name = room.display_name
|
||||
sender = item.sender_name or item.sender_id
|
||||
|
@ -2150,10 +2148,11 @@ class MatrixClient(nio.AsyncClient):
|
|||
else:
|
||||
body_start = f"{sender}: "
|
||||
|
||||
await self.backend.desktop_notify(
|
||||
title = room_name,
|
||||
body = f"{body_start}{item.inline_content}",
|
||||
# await self.backend.media_cache.get_thumbnail(
|
||||
NotificationRequested(
|
||||
title = room_name,
|
||||
body = f"{body_start}{item.inline_content}",
|
||||
high_importance = highlight,
|
||||
# image = await self.backend.media_cache.get_thumbnail(
|
||||
# item.sender_avatar, 32, 32,
|
||||
# ),
|
||||
)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, Union
|
||||
|
||||
import pyotherside
|
||||
|
||||
|
@ -34,14 +35,17 @@ class ExitRequested(PyOtherSideEvent):
|
|||
|
||||
|
||||
@dataclass
|
||||
class AlertRequested(PyOtherSideEvent):
|
||||
"""Request a window manager alert to be shown.
|
||||
class NotificationRequested(PyOtherSideEvent):
|
||||
"""Request a notification and window manager alert to be shown.
|
||||
|
||||
Sets the urgency hint for compliant X11/Wayland window managers;
|
||||
flashes the taskbar icon on Windows.
|
||||
Alerts set the urgency hint for compliant X11/Wayland window managers or
|
||||
flash the program's taskbar icon on Windows.
|
||||
"""
|
||||
|
||||
high_importance: bool = False
|
||||
title: str = field()
|
||||
body: str = ""
|
||||
image: Union[Path, str] = ""
|
||||
high_importance: bool = False
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
|
@ -11,15 +11,17 @@ QtObject {
|
|||
Qt.exit(exitCode)
|
||||
}
|
||||
|
||||
function onAlertRequested(highImportance) {
|
||||
function onNotificationRequested(title, body, image, highImportance) {
|
||||
if (Qt.application.state === Qt.ApplicationActive) return
|
||||
|
||||
py.callCoro("desktop_notify", [title, body, image])
|
||||
|
||||
const msec =
|
||||
highImportance ?
|
||||
window.settings.alertOnMentionForMsec :
|
||||
window.settings.alertOnMessageForMsec
|
||||
|
||||
if (Qt.application.state !== Qt.ApplicationActive && msec !== 0) {
|
||||
window.alert(msec === -1 ? 0 : msec) // -1 → 0 = no time out
|
||||
}
|
||||
if (msec) window.alert(msec === -1 ? 0 : msec) // -1 → 0 = no time out
|
||||
}
|
||||
|
||||
function onCoroutineDone(uuid, result, error, traceback) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user